#include<reg52.h> #define LED P0 sbit KEY1 = P1^0; sbit KEY2 = P1^1; unsigned int i = 0; unsigned char NUM[]={0X3f,0x06,0x56,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; unsigned char n = 0; void INT_T0(void) { TMOD = 0X01; //打开定时器0 ,使用模式1定时 TH0 = 0XFC; TL0 = 0X18; //初始值 EA = 1;//打开总开关 ET0 = 1;//打开中断T0开关 } void main(void) { INT_T0(); TR0 = 0; //定时功能打开 while(1) { if(KEY1==0) { TR0 = 1; } if(KEY2==1) { i = 0; n = 0; } } } void time0(void) interrupt 1 { TH0 = 0XFC; TL0 = 0X18; //初始值 if(i < 1000) { i++; } else { LED = NUM[n]; if(n<16) { n++; } else { n = 0; } i = 0; } }
原文:https://www.cnblogs.com/zxcd/p/11811455.html