#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=
打赏帖 | |
---|---|
C语言函数宏的三种封装方式被打赏50分 | |
【STM32F769】记一次由于开启D-Cache之后DMA数据传输出错的问题查找与解决被打赏35分 | |
嵌入式LinuxC语言程序调试和宏使用技巧被打赏50分 | |
让代码中包含最新的编译时间信息被打赏50分 | |
【分享开发笔记,赚取电动螺丝刀】STM32F769LVGL优化显示被打赏26分 | |
rtthread硬件加密--2crc加密分析被打赏10分 | |
【分享开发笔记,赚取电动螺丝刀】STM32F769驱动ST7789以及显示优化被打赏36分 | |
【分享开发笔记,赚取电动螺丝刀】S32K146 PAL模拟I2C驱动适配被打赏23分 | |
我想要一部加热台+电源硬件设计规范被打赏16分 | |
我想要一部加热台+LED背光驱动芯片RT9293知识被打赏18分 |