第九篇
0-99循环显示,每隔一秒,增加1
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
| #include "reg51.h"
void delay1s() { unsigned char i; for(i=0;i<1;i++){ TH1=(65536-10000)/256; TL1=(65536-10000)%256; TR1=1; while(!TF1); TF1=0; } }
void disp(unsigned char i) { unsigned int k; unsigned char led[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90} ; for ( k = 0; k < 50; k++) { P2=0xe7; P0=~led[i/10]; delay1s(); P2=0xe3; P0=~led[i%10]; delay1s(); } } void main() { unsigned char miao=0; TMOD=0x10; TH1=(65536-50000)/256; TL1=(65536-50000)%256; TR1=1; while(1){ disp(miao); miao++; if(miao==100)miao=0; } }
|
代码下载链接(123云盘):https://www.123684.com/s/wFuijv-i8Zgh