#include
#include
#define uchar unsigned char
#define uint unsigned int
#define LED1 P1_0
#define LED2 P1_5
#define LED3 P1_4
#define LED4 P1_3
uchar c;
uchar temp;
uchar Data[30]={0};
uint count=0;
void Init_LED()
{
P1SEL &=~0X39;
P1DIR |= 0X39;
P1 &=~ 0X39;
}
void Init_UART()
{
CLKCONCMD &= 0x80;
U0CSR |= 0X80;
P0SEL |= 0X0C;
U0GCR =10;
U0BAUD =216;
U0CSR |= 0X40;
URX0IF = 0;
UTX0IF = 0;
IEN0 |= 0X84;
}
void UART_Control_Led()
{
if(Data[0]‘d’||Data[0]‘A’)
{
if(Data[0]‘d’)
{
if(Data[1]‘1’)
LED1 =1;
else if(Data[1]‘2’)
LED2 =1;
else
LED1=LED2=LED3=LED4=0;
}
if(Data[0]‘A’)
{
if(Data[1]‘0’)
LED1 = LED2 = 1;
else if(Data[1]‘1’)
LED1 = LED2 = 0;
else
LED1=LED2=LED3=LED4=0;
}
}
}
void Send_Data(uchar *Data,uint len)
{
int j;
for(j=0;j
{
U0DBUF = *Data++;
while(UTX0IF == 0);
UTX0IF = 0;
}
UART_Control_Led();
}
#pragma vector=URX0_VECTOR
__interrupt void UART0_ISR(void)
{
URX0IF=0;
temp = U0DBUF;
if((temp != ‘#’)&& count < 30)
{
Data[count++]=temp;
temp=0;
}
else
Send_Data(Data,count);
}
main()
{
Init_LED();
Init_UART();
while(1)
{
}
}
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define LED1 P1_0
#define LED2 P1_5
#define LED3 P1_4
#define LED4 P1_3
uchar c;
uchar temp;
uchar Data[30]={0};
uint count=0;
void Init_LED()
{
P1SEL &=~0X39;
P1DIR |= 0X39;
P1 &=~ 0X39;
}
void Init_UART()
{
CLKCONCMD &= 0x80;
U0CSR |= 0X80;
P0SEL |= 0X0C;
U0GCR =10;
U0BAUD =216;
U0CSR |= 0X40;
URX0IF = 0;
UTX0IF = 0;
IEN0 |= 0X84;
}
void UART_Control_Led()
{
if(Data[0]‘d’||Data[0]‘A’)
{
if(Data[0]‘d’)
{
if(Data[1]‘1’)
LED1 =1;
else if(Data[1]‘2’)
LED2 =1;
else
LED1=LED2=LED3=LED4=0;
}
if(Data[0]‘A’)
{
if(Data[1]‘0’)
LED1 = LED2 = 1;
else if(Data[1]‘1’)
LED1 = LED2 = 0;
else
LED1=LED2=LED3=LED4=0;
}
}
}
void Send_Data(uchar *Data,uint len)
{
int j;
for(j=0;j
{
U0DBUF = *Data++;
while(UTX0IF == 0);
UTX0IF = 0;
}
UART_Control_Led();
}
#pragma vector=URX0_VECTOR
__interrupt void UART0_ISR(void)
{
URX0IF=0;
temp = U0DBUF;
if((temp != ‘#’)&& count < 30)
{
Data[count++]=temp;
temp=0;
}
else
Send_Data(Data,count);
}
main()
{
Init_LED();
Init_UART();
while(1)
{
}
}
举报