51单片机8*8点阵显示0到9并逐渐加秒延时 例如0到1停1秒 到2停2秒。。。。到9停9秒
源代码稍修改,然后把这个加进去就行了。。。
int sec_cnt = 0;
unsigned char timer0_cnt = 0;
unsigned char sec1 = 0;
void DelaySec(unsigned char sec)
{
sec_cnt = 0;
while(sec_cnt < sec);
}
void Timer0Init(void)
{
TMOD=0x01; //设置定时器0为工作方式1
TH0=(65536-45872)/256; //放入初值,11.0592M,50ms
TL0=(65536-45872)%256;
EA=1; //开总中断
ET0=1; //开定时器0中断
TR0=1; //启动定时器0
}
void timer0() interrupt 1 //50ms定时器中断
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
timer0_cnt++;
if(timer0_cnt == 20) //1s一次 20
{
timer0_cnt = 0;
sec1++;
if(sec1==1)
{
DelaySec(1);
}
if(sec1==2)
{
DelaySec(2);
}
if(sec1==3)
{
DelaySec(3);
}
if(sec1==4)
{
DelaySec(4);
}
if(sec1==5)
{
DelaySec(5);
}
if(sec1==6)
{
DelaySec(6);
}
if(sec1==7)
{
DelaySec(7);
}
if(sec1==8)
{
DelaySec(8);
}
if(sec1==9)
{
sec1=0;
DelaySec(9);
}
if(sec1==0)
{
DelaySec(10);
}
}
}