想实现Arduino发送信息,c51接收信息,比如当c51收到A后LED1一直亮,当收到B后LED1灭LED2一直亮
自己写的程序不对,实现不了 求助大神
arduino程序
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.write('A');
delay(5000);
Serial.write('B');
delay(5000);
}
C51程序
#include <reg52.h>
sbit LED1 = P1^0;
sbit LED2 = P1^1;
unsigned char UART_buff;
bit New_rec = 0;
bit Send_ed = 1;
void delay(int x)
{
int i,j;
for(i=0;i<x;i++)
for(j=0;j<110;j++);
}
void main (void)
{
SCON = 0x50;//串口方式1, 8-n-1, 允许接收.
TMOD = 0x20;//T1方式2
TH1 = 0xFD; //9600bps@11.0592MHz
TL1 = 0xFD;
TR1 = 1;
ES= 1; //开中断.
EA= 1;
while(1)
{
if ((New_rec == 1) && (Send_ed == 1))//如果收到新数据及发送完毕
{
SBUF = UART_buff; //那就发送.
New_rec = 0;
Send_ed = 0;
}
}
}
/***************中断服务函数*********************/
void ser_int (void) interrupt 4
{
if(RI == 1) //如果收到.
{
RI = 0; //清除标志.
New_rec = 1;
UART_buff = SBUF; //接收.
if(UART_buff == '0')
|