自制51單片機常用頭文件
#define __COM_H__
本文引用地址:http://2s4d.com/article/201611/320295.htm#define uchar unsigned char
#define uint unsigned int
#define XTAL 11059200
#define baudrate 9600
void sendmsg(uint ps)
{
SBUF = ps;
while(TI == 0);
TI = 0;
}
uint rcvmsg(void)
{
RI=0;
return SBUF;
}
void initcom(void)
{
TMOD = 0x20;
TH1=(unsigned char)(256 - (XTAL / (32L * 12L * baudrate)));
TL1=(unsigned char)(256 - (XTAL / (32L * 12L * baudrate)));
SM0 = 0; //串口工作方式控制
SM1 = 1; //串口工作方式控制 //這兩個共同控制了串口工作方式為 0;
REN = 1; //串口接收允許
PCON = 0x00;
TR1 = 1; //允許串口接收
ES = 0;
}
#endif
評論