第二篇
分别通过四个按键实现一下功能:
①第四位亮
②高四位亮
③交叉亮
④流水灯
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| #include <reg51.h> #include <intrins.h> sbit S1=P3^1; sbit S2=P3^0; sbit S3=P3^2; sbit S4=P3^3; void delay(unsigned int i) { unsigned int k; for(k=0;k<i;k++); } void main() { unsigned char a; P2=0xFF; while(1) { if(S1==0 && S2!=0) { delay(1200); if(S1==0 && S2!=0) { P2=0xF0; } } else if(S1!=0 && S2==0) { delay(1200); if(S1!=0 && S2==0) { P2=0x0F; } } else if(S1==0 && S2==0) { delay(1200); if(S1==0 && S2==0) { P2=0x00; } } else if(S3==0) { delay(1200); a=0x55; if(S3==0) { P2=a; delay(5000); P2=~a; delay(5000); } } else if(S4==0) { delay(1200); P2=0x7F; while(S4==0) { P2=_cror_(P2,1); delay(5000); } } else if(S1!=0&&S2!=0&&S3!=0&&S4!=0) { P2=0xFF; } } }
|
代码下载链接(123云盘):https://www.123684.com/s/wFuijv-i8Zgh