AT89S52、4Mhz 晶振以 9600 波特率发送数据

发布于 2024-12-23 03:34:40 字数 303 浏览 3 评论 0原文

朋友们,

我想用AT89S52传输数据,我的晶体是4 Mhz, 我在下面编写了正确的波特率代码吗? 或者你们谁知道如何计算波特率?

多谢

void transmit_data()
 {
    TMOD = 0x20;
    TH1 = 0xfd;
    PCON &= 0x7f;
SCON = 0x50;
TCON =0x40;
while(1)
  {
    printf("a"); // transmit a along with CR & LF.
  }

}

Mates,

I want to transmit data using AT89S52 and my crystal is 4 Mhz,
Am I writing a correct baud rate code below ?
Or anyone of you know how to calculate a baud rate ?

Thanks a lot

void transmit_data()
 {
    TMOD = 0x20;
    TH1 = 0xfd;
    PCON &= 0x7f;
SCON = 0x50;
TCON =0x40;
while(1)
  {
    printf("a"); // transmit a along with CR & LF.
  }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苍白女子 2024-12-30 03:34:40

这是一个可以提供帮助的计算器:
http://www.keil.com/c51/baudrate.asp
不幸的是,它表明 4 MHz 晶体选择对于标准波特率来说是多么糟糕。

Here is a calculator to help:
http://www.keil.com/c51/baudrate.asp
Unfortunately, it shows how poor a 4 MHz crystal selection is for standard baud rates.

爱你不解释 2024-12-30 03:34:40

用一些猜测值对其进行编码并循环发送 0xAA。用示波器查看 tx o/p,测量位宽,然后出错...“优化”除数值。与查找/阅读/消化庞大的用户手册和计算相比,这有一些优势:

1)它更快,除非你很幸运。

2) 如果根本没有输出,您可以先修复不可靠的硬件和/或不正确的 UART 初始化和/或寄存器地址和/或引脚分配,然后再花很长时间思考波特率出了什么问题。

3) 即使用户手册波特率公式“低于 100% 正确”,它也始终有效。

4) 当您可以看到输出正确但仍然没有通信时,您可以将其归咎于电缆和/或 DCE/DTE 和/或超级终端和/或所有其他阻止 RS232 工作的东西。

Code it up with some guesstimate values and send 0xAA in a loop. Look at the tx o/p with a scope, measure the bit width and then err... 'optimize' the divisor values. This has some advantages over finding/reading/digesting the huge user manual and calculating:

1) It's quicker, unless you're lucky.

2) If there is no output at all, you get to fix the dodgy hardware and/or incorrect UART initializion and/or register addresses and/or pin assignments before spending ages wondering what you did wrong with the baud rate.

3) It always works, even if the user manual baud rate formula is 'less than 100% correct'.

4) When you can see the output coming out correctly but there is still no communication, you can blame it on the cables and/or DCE/DTE and/or Hyperterminal and/or all the other stuff that stops RS232 working.

半步萧音过轻尘 2024-12-30 03:34:40

我获得 9600 波特的最佳方法是使用 11.0592Mhz 晶体...0% 误差范围

The best way I can get for 9600 baut is using 11.0592Mhz Crystal...0% error margin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文