#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar i=0; ge, shi, bai, qian, num=0,a,b,cnt;
sbit led =P1^0;
sbit key1=P3^4;//按键加
sbit key2=P3^5;//按键减
sbit wela = P2^7;
sbit dula = P2^6;
void display();
/******延时函数*******/
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
/******定时器T0初始化*******/
void Time_Int()
{
TMOD=0x01;
TH0 =0xfe;//0.5ms
TL0 =0x33;
EA =1;
ET0 =1;
TR0 =1;
}
/**********键盘扫描**********/
void keyscan()
{
if(key1==0)
{
delay(10);
if(key1==0)
num++;
while(!key1);
}
if(key2==0)
{
delay(10);
if(key2==0)
num--;
while(!key2);
}
a=5000/num;
b=a*2;
if(num>2000)
num=2000;
if(num<1)
num=1;
}
main()
{
Time_Int();
led =0;
while(1)
{
display();
keyscan();
qian=num/1000;
bai =num%1000/100;
shi =num%1000%100/10;
ge =num%1000%100%10;
}
}
void time0() interrupt 1
{
TH0 =0xff;//0.1ms
TL0 =0xa3;
P0=0X00;
cnt++;
if(cnt<=a)
{
led=1;
}
else if((cnt>a)&&(cnt<=b))
{
led=0;
}
else if(cnt>b)
{
cnt=0;
}
i++;
if(i>4)
i=1;
/* switch(i)
{
case 1:P2=0X00;P0=table[qian];break;
case 2:P2=0X01;P0=table[ bai];break;
case 3:P2=0X02;P0=table[ shi];break;
case 4:P2=0X03;P0=table[ ge ];break;
default:break;
} */
}
|