注:本数码管为共阴极,P2为位选口,P0为数据口
本实验是一个60s计数器,当满60s后,此时又从00开始计数
#includeunsigned char Tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};unsigned char int_time;unsigned char second;void delay(void){ unsigned char i; for(i=0;i<250;i++) ;}void Display(unsigned char k){ P2=0xfd; P0=Tab[k/10]; delay(); P2=0xfe; P0=Tab[k]; delay(); P2=0xff;}void main(){ TMOD=0x01; TH0=15536/256; //50ms发生一次中断 TL0=15536%6; EA=1; //开启总中断源 ET0=1; //定时器T0中断允许 TR0=1; //启动定时器0 int_time=0; //中断次数初始化 second=0; //秒初始化 while(1) { Display(second); }}void interserver(void) interrupt 1 using 1{ TR0=0; int_time++; if(int_time==20) { int_time=0; second++; if(second==60) second=0; } TH0=15536/256; TL0=15536%6; TR0=1;}