初學者上手的簡單程序,把下面代碼復制進keil代碼窗口,燒進51hei開發板,看看結果吧 #include<reg52.h> #define uchar unsigned char #define uint unsigned int #define dp P0 char code DuanMa[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40}; //單個數碼管顯示數 char code fenjie[]={0,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f}; char code WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //數碼管的位選擇:從0到7. sbit LATCH1=P2^6; // 控制數碼管段的位 sbit LATCH2=P2^7; // 控制數碼管位的位 void delay(unsigned int t) { while(--t); } void main() { int i,j,k; while(1) { delay(5000); for(i=0;i<7;i++) //段碼 { for(j=0;j<8;j++) //位碼 { for(k=0;k<10;k++) //調節k的值可調節掃描時間 { dp=WeiMa[j]; //取位碼 LATCH2=1; LATCH2=0; dp=DuanMa[i]; //取段碼 LATCH1=1; LATCH1=0; delay(2500); dp=fenjie[i]; //取段碼 LATCH1=1; LATCH1=0; dp=WeiMa[7]; //取位碼 LATCH2=1; LATCH2=0; delay(50); dp=0; //取段碼 清零 減小余暉影響 LATCH1=1; LATCH1=0; dp=WeiMa[j]; //取位碼 LATCH2=1; LATCH2=0; delay(1000); } } } //閃爍8 for(k=0;k<10;k++) { dp=fenjie[7]; //取段碼 LATCH1=1; LATCH1=0; dp=WeiMa[7]; //取位碼 LATCH2=1; LATCH2=0; delay(6000); delay(6000); dp=0; //取段碼 LATCH1=1; LATCH1=0; dp=WeiMa[7]; //取位碼 LATCH2=1; LATCH2=0; delay(6000); } } }