UART串口通信

来源:互联网 发布:arma预测 matlab源码 编辑:程序博客网 时间:2024/05/21 09:13

在STC-ISP里的串口助手的单字符串发送区

发送01   03可点亮小灯


#include<reg52.h>#define uchar unsigned char#define uint unsigned intuchar i;sbit D0=P0^0;sbit D1=P0^1;sbit D2=P0^2;sbit D3=P0^3;sbit D4=P0^4;sbit D5=P0^5;sbit D6=P0^6;sbit D7=P0^7;sbit ADDR0 = P1^0;sbit ADDR1 = P1^1;sbit ADDR2 = P1^2;sbit ADDR3 = P1^3;sbit ENLED = P1^4;void init_uart(void){TMOD=0X20;TH1=0XFD;TL1=0XFD;TR1=1;SCON=0X50;EA=1;ES=1;}void main (void){ENLED = 0;ADDR3 = 1;ADDR2 = 1;ADDR1 = 1;ADDR0 = 0;init_uart();while(1){while(!RI);RI=0;i=SBUF;switch(i){case 0x01 :D0=~D0;break;case 0x02 :D1=~D1;break;case 0x03 :D2=~D2;break;case 0x04 :D3=~D3;break;case 0x05 :D4=~D4;break;case 0x06 :D5=~D5;break;case 0x07 :D6=~D6;break;case 0x08 :D7=~D7;break;}}}


原创粉丝点击