#include "reg52.h"
#define uchar unsigned char
#define uint unsigned int
void delay1ms (uint t)
{
uint i;
while (t--)
{for (i=0;i<125;i++){}}
}
void uart_init( void )
{
SCON = 0xe0 ; //SCON: serail mode 3, 11-bit UART, enable ucvr
TMOD |= 0x20 ; //TMOD: timer 1, mode 2, 8-bit reload
PCON |= 0x00 ; //SMOD=0;
TH1 = 0xFD ; //Baud:9600 fosc=11.0592MHz
IE |= 0x90 ; //Enable Serial Interrupt
TR1 = 1 ; // timer 1 run
delay1ms (1);
}
bit ecc_test (uchar dat)
{
uchar i,count;
bit ecc;
for (i=0;i<8;i++)
{
if ((dat>>i)&0x01)
{
count=count+1;
}
}
if (count&0x01)
{ecc=0;}
else
{ecc=1;}
return ecc;
}
void uart_send( uchar ch)
{
TB8=ecc_test (ch);
SBUF=ch;
while (TI== 0 );
TI= 0 ;
}
void uart_com (uchar add,dat)
{
uchar com;
delay1ms (4);
uart_send (add);
delay1ms (4);
uart_send (dat);
}
void main ()
复制来自:http://89c51.5d6d.com/viewthread.php?tid=1367&extra=
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |