#include <STC89C5xRC.H>
#include "intrins.h"
#include "string.h"
char uart_dat[10];
int uart_temp=0;
sbit ledOne=P3^7;
sbit ledTwo=P3^6;
void UartInit(void)
{
PCON &= 0x7F;
SCON = 0x50;
AUXR &= 0xBF;
AUXR &= 0xFE;
TMOD &= 0x0F;
TMOD |= 0x20;
TL1 = 0xFD;
TH1 = 0xFD;
ET1 = 0;
TR1 = 1;
ES=1;
EA=1;
}
void uartService() interrupt 4
{
if(RI==1)
{
uart_dat[uart_temp]=SBUF;
uart_temp++;
RI=0;
}
}
void sendDate(unsigned char dat)
{
SBUF=dat;
while(TI==0);
TI=0;
}
void sendString(unsigned char *str)
{
while(*str!='\0')
{
sendDate(*str++);
}
}
void judgeInformation()
{
if(uart_temp==1)
{
uart_temp=0;
if(strcmp(uart_dat,"A")==0)
{
ledOne=0;
sendString("L1 is open");
}
if(strcmp(uart_dat,"B")==0)
{
ledOne=1;
sendString("L1 is close");
}
if(strcmp(uart_dat,"C")==0)
{
ledTwo=0;
sendString("L2 is open");
}
if(strcmp(uart_dat,"D")==0)
{
ledTwo=1;
sendString("L2 is close");
}
}
}
void main()
{
UartInit();
sendString("welcome:\r\n");
while(1)
{
judgeInformation();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)