#include <reg24e1.h>
/* LED1-LED4 */
sbit LED1 = P0^7;
sbit LED2 = P0^6;
sbit LED3 = P0^5;
sbit LED4 = P0^4;
volatile unsigned char BUF;
void Delay100us(volatile unsigned char n)
{
unsigned char i;
while(n--)
for(i=0;i<35;i++)
;
}
void Delayms(volatile unsigned char n)
{
unsigned char j;
while(n--)
for(j=0;j<10;j++)
Delay100us(10);
}
void InitUart(void)
{
P0_ALT=0x06;
P0_DIR=0x06;
T2CON = 0x34; /* Use Timer 2 as baudrate generator */
RCAP2H = 0xFF;
RCAP2L = 0xF7; /* 57600 baud @ 16MHz */
SCON = 0x50; /* enable serial uart & receiver */
ES=1;
EA=1;
}
void SendCh(unsigned char b)
{
TI = 0;
SBUF = b;
while(!TI);
TI = 0;
}
void UartISR (void) interrupt 4 using 2 //串口中断
{
EA=0;
if(RI)
{
BUF=SBUF;
LED1=0;
Delayms(20);
LED1=1;
RI=0;
}
if(TI)
TI=0;
EA=1;
}
void main(void)
{
InitUart();
while(1)
{
//SendCh(0xAA);
if(BUF=0xBB)
{
P0=0x0F;
Delayms(20);
P0=0xFF;
}
}
}