/****************************************************************************/
/* */
/* SERIAL.C: Interrupt Controlled Serial Interface */
/* */
/****************************************************************************/
//采用中断接收串口数据
//发送数据到串口可使用<stdio.h>定义的函数
//测试:Robinson_911
//#include <reg52.h>
#include "STC_NEW_8051.H"
#include <stdio.h>
volatile unsigned char UartIsSending;
char putchar (char ucWriteData)
{
SBUF=ucWriteData;
UartIsSending=1;
while(UartIsSending);
return (ucWriteData);
}
volatile unsigned char UartIsSending;
void UartIsr(void) interrupt 4
{
if(TI) //发送中断
{
UartIsSending=0;
TI=0;
}
if(RI) //接收中断
{
RI=0;
}
}
/****************************************************************************/
/* serial_init: initialize serial interface */
/****************************************************************************/
serial_init ()
{
SCON = 0x50; /* mode 1: 8-bit UART, enable receiver */
TMOD |= 0x20; /* timer 1 mode 2: 8-Bit reload */
TH1 = 0xfa; /* reload value 2400 baud */
TR1 = 1; /* timer 1 run */
ES=1;
}
void Delay(void)
{
unsigned char ucDelayCount;
for(ucDelayCount=0; ucDelayCount<0xFF; ucDelayCount++)
{
;
}
}
unsigned long sum=0;
unsigned long __checksum=0xE728 ;
void main(void)
{
serial_init();
EA = 1;
while(1)
{
putchar('8');
putchar('\n');
Delay();
// printf("welcome to www.21ic.com\n");
printf("Checksum failed: 0x%04lX (calculated) "
"vs 0x%04lX (from linker)\n", sum, __checksum);
}
}