#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^7;
sbit wela=P2^6;
uchar shuzi[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98};
uchar num1,num;
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void delayx(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=10;j>0;j--);
}
void display()
{ uchar shi,ge;
shi=num/10;
ge=num%10;
dula=1;
P0=shuzi[shi];
dula=0;
P0=0x00;
wela=1;
P0=0x40;
wela=0;
delayx(50);
dula=1;
P0=shuzi[ge];
dula=0;
P0=0x00;
wela=1;
P0=0x20;
wela=0;
delayx(50);
}
void in
tin()
{
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
}
void keyx()
{
P1=0xfe;
delay(50);
if(P3==0xfe)
{
num++;
if(num==60)
{
num=0;
}
while(!P1);
}
P1=0xfd;
delay(50);
if(P3==0xfe)
{
if(num==0)
{
num=60;
}
num--;
while(!P1);
}
P1=0xfb;
delay(50);
if(P3==0xfe)
{
num=0;
while(!P1);
}
P1=0xf7;
delay(50);
if(P3==0xfe)
{
TR0=~TR0;
while(!P1);
}
}
void main()
{
intin();
while(1)
{
keyx();
display();
}
}
void time_0() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
num1++;
if(num1==20)
{
num1=0;
num++;
if(num==60)
{
num=0;
}
}
}
这个程序下到板子上时第一个数码管的显示很暗还有些跳动,第二个正常,请问是什么原因?
一周热门 更多>