專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

串口波特率發(fā)送數(shù)據(jù)程序

作者:佚名   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2013年11月16日   【字體:
# include <reg52.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
uint8 num = 0;
void delay(uint16 n)      //延時(shí)函數(shù)
{
 while(n--);
}
void UART_init(void)
{
 SCON = 0x50;     //串口控制寄存器在方式1條件下,M1 = 1;M0 = 0   REN = 1,打開允許串口接收數(shù)
 TMOD = 0x20;     //將定時(shí)器1置為自動(dòng)重裝模式。即方式2
 TH1  = 0xFD;     //TH1 = TL1 =  256 - 11059200/(12 * 32 * 9600)   (12為12個(gè)時(shí)鐘周期)
 TL1  = 0xFD;
 TR1  = 1;      //允許串口接收數(shù)據(jù)
}
void UART_send_byte(uint8 dat)
{
 SBUF = dat;
 while(!TI);       //發(fā)送停止位時(shí)由硬件置1必須軟件清零
 TI = 0;
}
main()
{
 UART_init();     //串口初始化
 while(1)
 { 
  UART_send_byte(num++);
  delay(20000);
 }
}
關(guān)閉窗口

相關(guān)文章