#include<reg52.h> #define uc unsigned char sbit key=P3^2; uc i,i1; void delay(uc c) { uc a,b; for(;c>0;c--) for(a=38;a>0;a--) for(b=130;b>0;b--); } void ss() interrupt 4 { if(RI) { i=SBUF; RI=0; } } void main() { TMOD=0x20; TH1=0xFD; TL1=0xFD; TR1=1; SCON=0X50; ES=1; EA=1; while(1) { if(key==0) { i1++; SBUF=i1+'0'; while(TI==0);TI=0; delay(1); while(key==0); delay(1); if(i1==4) i1=1; } if(i=='1') P2=0; if(i=='2') P2=0xff; if(i=='3') { P2=0xff; delay(20); P2=0; delay(20); } } }
- 接线:
- T接R,R接T,GND接GND
- key3接P3^2