/*制作的一个999计数器,LED显示器从000开始显示,直至999后再返回000开始显示*/
#include sbit P20=P2^0; sbit P21=P2^1; sbit P22=P2^2; void delay(void) { unsigned char i,j,k; for (i=20;i>0;i--) for (j=20;j>0;j--) for (k=230;k>0;k--); } void main(void) { unsigneg char code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e} unsigned char a; unsigned int m,upbit,lowbit,hibit,cnt=1000; while(1) { for{m=0;m hibit=m/100; upbit=(m-hibit*100)/10; lowbit=m%10; for(a=0;a<30;a++) { P0=tab[upbit]; P20=0; delay(); P20=1; P0=tab[lowbit]; P21=0; delay(); P21=1; P0=tab[hibit]; P22=0; delay(); P22=1; } } } } 因篇幅问题不能全部显示,请点此查看更多更全内容