} } }
void serial() interrupt 4 {
thedata=SBUF; RI=0; flag=1; } 5、
#include
#define uchar unsigned char #define uint unsigned int
uchar thedata; bit flag;
void main() {
TMOD=0x20; TH1=0xfd; TL1=0xfd; TR1=1; // SM0=0; // SM1=1; // REN=1; SCON=0x50; EA=1; ES=1; while(1) { if(flag==1) { ES=0; flag=0; if(thedata>=48 && thedata<=57) thedata-=48; if(thedata>=97 &&thedata<=122) //根据ascii值判断是否接收到了'a'-'z' thedata-=32; //将小写字母转换成大写 ascii值差32
SBUF=thedata; while(!TI); TI=0; ES=1; } } }
void serial() interrupt 4 {
thedata=SBUF; RI=0; flag=1; } 6、
#include
#define uchar unsigned char #define uint unsigned int
uchar count=0; uchar temp; uchar* thedata; bit flag;
void main() { uchar i;
TMOD=0x21; TH0=0x3C; TL0=0xB0; TH1=0xfd; TL1=0xfd; TR1=1; // TR0=1; SCON=0x50; EA=1; ET0=1; ES=1; while(1) { if(flag==1)
{ ES=0; flag=0; if(temp=='1') { TR0=1; thedata=\ } if(temp=='2') { TR0=0; thedata=\ } // for(i=0;i<5;i++) while(*thedata) { // SBUF=thedata[i]; SBUF=*thedata; while(!TI); TI=0; thedata++; } ES=1; } if(count==20) { count=0; P1=~P1; } } }
void t0() interrupt 1 {
TH0=0x3C; TL0=0xB0; count++; }
void serial() interrupt 4 {
temp=SBUF; RI=0;
flag=1; } 7、
#include
#define uchar unsigned char #define uint unsigned int uchar i;
uchar count=0;
uchar data_count=0; uchar receive[8]=%uchar send_Ok1[]=%uchar send_Ok2[]=%uchar Start[]=%uchar Stop[]=%uchar flag;
void main() {
TMOD=0x21; TH0=0x3C; TL0=0xB0; TH1=0xfd; TL1=0xfd; TR1=1; SCON=0x50; EA=1; ET0=1; ES=1; while(1) { if(flag==1) { ES=0; flag=0; TR0=1; data_count=0; for(i=0;i<4;i++) { SBUF=send_Ok1[i]; while(!TI);
TI=0; } ES=1; } if(flag==2) { ES=0; flag=0; TR0=0; data_count=0; for(i=0;i<4;i++) { SBUF=send_Ok2[i]; while(!TI); TI=0; } ES=1; } if(count==20) { count=0; P1=~P1; } } }
void t0() interrupt 1 {
TH0=0x3C; TL0=0xB0; count++; }
void serial() interrupt 4 { if(RI) { RI=0; receive[data_count]=SBUF; if(strcmp(receive,Start)==0) { flag=1; for(i=0;i<8;i++)