http://www./bbs/dpj-150083-1.html 電路原理圖如下: 單片機(jī)程序源碼: #include <reg52.h> //頭文件 #include <intrins.h> #define uint unsigned int //宏定義 #define uchar unsigned char sbit SW1 =P1^0; //按鍵1 sbit SW2 =P1^1; //按鍵2 sbit SW3 =P1^2; //按鍵3 sbit SW4 =P1^3; //按鍵4 uint num; uchar huayang1[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0xff}; uchar huayang2[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; uchar huayang3[]={0xaa,0x55,0xfb,0xf7,0xef,0x39,0xf1,0xe5,0x02,0xe3,0x2c,}; void delay(uint S) { while(S--); } void ms() { uint i; for(i=0;i<200;i++) { delay(200); } } void main() { while(1) { if(SW1==0) { delay(10); if(SW1==0) { while(!SW1); while(1) { for(num=0;num<9;num++) { P0=huayang1[num]; P2=~huayang1[num]; ms(); } } } } if(SW2==0) { delay(10); if(SW2==0) { while(!SW2); while(1) { for(num=0;num<8;num++) { P0=0xff; P2=0; ms(); P0=huayang2[num]; P2=~(0x55 & huayang2[num]); ms(); } } } } if(SW3==0) { delay(10); if(SW3==0) { while(!SW3); while(1) { for(num=0;num<11;num++) { P0=huayang3[num]; P2=~(0xaa & huayang3[num]); ms(); ms(); if(SW1==0||SW2==0||SW3==0||SW4==0) break; } } } } } } https://www./i34cm8j
|
|