1、左边1号机,右边2号机,功能实现1号机程序#include#define uint unsigned int#define uchar unsigned charsbit p10=P10;uchar a,b,kk;/uchar code d_c=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff;void delay_ms(uchar y)uchar i;while(y-)for(i=0;i120;i+);void put(uchar x) /发送函数SBUF=x; /SBUF:串行口数据缓冲器while(TI=0); /等待发送结束T
2、I=0;void main()uchar j;SCON=0x40; /串行口工作方式1,8位通用异步发送器TMOD=0x20; /定时器1工作方式2PCON=0x00;/波特率不倍增TH1=0xf4;TL1=0xf4;/波特率2400TR1=1;/定时器1开始计时P2=0xc0;while(1)if(p10=0&j=0)delay_ms(15);while(p10=0);kk=1;P2=0xf9;j=1;if(p10=0&j=1)delay_ms(15);while(p10=0);kk=2;P2=0xa4;j=2;if(p10=0&j=2)delay_ms(15);while(p10=0);k
3、k=3;P2=0xb0;j=0;if(kk=1)put(A);if(kk=2)put(B);if(kk=3)put(C);delay_ms(10); /*if(p10=0&j=0)delay_ms(15);while(p10=0);kk=0;P2=0xf9;j=1;if(p10=0&j=1)delay_ms(15);while(p10=0);kk=1;P2=0xa4;j=2;if(p10=0&j=2)delay_ms(15);while(p10=0);kk=2;P2=0xc0;j=0;if(kk=0)put(A);if(kk=1)put(B);if(kk=2)put(C);delay_ms(1
4、00);*if(p10=0) delay_ms(15); while(p10=0); number=(number+1)%4; switch(oper) case 0:break;case 1:put(A);P2=0xf9;break;case 2:put(B);P2=0xa4;break;case 3:put(C);P2=0xc0;break;delay_ms(10);*if(p10=0) delay_ms(15); while(p10=0); j=(j+1)%3; switch(j) case 0:put(A);P2=0xf9;break;case 1:put(B);P2=0xa4;bre
5、ak;case 2:put(C);P2=0xc0;break;delay_ms(10);*/2号机程序。#include#define uint unsigned int#define uchar unsigned charsbit L1=P20;sbit L2=P21;/uchar code d_c=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff;void delay_ms(int x)uchar i;while(x-)for(i=0;i120;i+);void main()SCON=0x50; /串行口工作方式1,8位通用异步发
6、送器TMOD=0x20; /定时器1工作方式2PCON=0x00; /波特率不倍增TH1=0xf4;TL1=0xf4;TR1=1;P1=0xc0;L1=L2=0;while(1)if(RI)RI=0;switch(SBUF)caseA:L1=L1;L2=0;P1=0xf9;break;caseB:L1=L1;L2=L2;P1=0xa4;break;caseC:L1=0;L2=0;P1=0xb0;break;delay_ms(100);/*if(RI)RI=0;if(SBUF=A)L1=L1;P1=0xf9;if(SBUF=B)L1=L1;L2=L2;P1=0xa4;if(SBUF=C)L1=0;L2=0;P1=0xc0;*/