1. 动态显示
2. 七段译码的编码表
3. 定时器的设置
单片机的时钟信号为11.0592MHz,选取46080对应0.05s。
程序:
#include#include sbit P2_2=P2^2 ;sbit P2_3=P2^3 ;void delay(unsigned char dly){ unsigned char i,j; for(i=255;i>0;i--) for(j=dly;j>0;j--);}unsigned char num,time;void timer0()interrupt 1{ TH0=(65535-46080)/256; TL0=(65535-46080)% 256; num++; if(num==20) { num=0; time++;}}void intial(){ TMOD=0x01; ET0=1; EA=1; TR0=1; num=0;}void main(){ unsigned char table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; unsigned char shi,fen; intial(); while(1) { if(time==60) time=0; shi=time/10; fen=time% 10; P2_2=1; P2_3=0; P0=table[shi]; delay(2); P2_2=0; P2_3=1; P0=table[fen]; delay(2);}}