发表于:2010/8/14 16:56:39
#0楼
再记录一个由定时器构成的跑秒灯。思路很简单,自己摸索着编也摸索到了点技巧。数码管延时的余晖作用到5ms的时候就明显抖动了。延时选2ms。
程序
#include
#define uint unsigned int
unsigned char table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //共阳极0123456789
unsigned char count,second;
void delay1ms(uint z)
{
uint x,y;
{
for(x=z;x>0;x--)
{
for(y=110;y>0;y--);
}
}
}
void t0(void) interrupt 1
{
th0=(65536-50000)/256;
tl0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
second++;
}
}
void main()
{
tmod=0x01;
th0=(65536-50000)/256;
tl0=(65536-50000)%256;
et0=1;
tr0=1;
ea=1;
while(1)
{
p2=0xfe;
p0=table[second/10];
delay1ms(2);
p2=0xfd;
p0=table[second%10];
delay1ms(2);
if(second==100)
{
second=0;
}
}
}
实现了简单的由00到99的跑秒。自勉
----------------------------------------------
此篇文章从博客转发
原文地址: Http://blog.gkong.com/more.asp?id=121296&Name=h661005
程序
#include
#define uint unsigned int
unsigned char table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //共阳极0123456789
unsigned char count,second;
void delay1ms(uint z)
{
uint x,y;
{
for(x=z;x>0;x--)
{
for(y=110;y>0;y--);
}
}
}
void t0(void) interrupt 1
{
th0=(65536-50000)/256;
tl0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
second++;
}
}
void main()
{
tmod=0x01;
th0=(65536-50000)/256;
tl0=(65536-50000)%256;
et0=1;
tr0=1;
ea=1;
while(1)
{
p2=0xfe;
p0=table[second/10];
delay1ms(2);
p2=0xfd;
p0=table[second%10];
delay1ms(2);
if(second==100)
{
second=0;
}
}
}
实现了简单的由00到99的跑秒。自勉
----------------------------------------------
此篇文章从博客转发
原文地址: Http://blog.gkong.com/more.asp?id=121296&Name=h661005