#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=
打赏帖 | |
---|---|
宏定义和const关键字定义被打赏5分 | |
【功率监测与控制系统DIY活动成果贴】DIY功率计与LabVIEW数据采集被打赏100分 | |
【Freertos】任务管理被打赏10分 | |
分享博世的两种不同的喷射系统模式被打赏5分 | |
汽车+开路实验与短路实验被打赏10分 | |
多点式电子控制汽油喷射系统知识分享被打赏10分 | |
分享机械控制式汽油喷射系统被打赏5分 | |
【分享开发笔记,赚取电动螺丝刀】解决基于CH341制作无线模块时芯片发热问题被打赏31分 | |
【分享开发笔记,赚取电动螺丝刀】使用STM32F103ZE主控调试RS485通讯的避坑经验被打赏36分 | |
【分享开发笔记,赚取电动螺丝刀】移植xprintf模块被打赏27分 |