#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1=P1^4;
sbit key2=P1^5;
sbit key3=P1^6;
sbit key4=P1^7;
sbit tdis=P2^6;
sbit sdis=P2^7;
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90};
void delayms(uint);
uchar numt0,num;
/**************************************************
ÏÔʾ¹¦Äܺ¯Êý
***************************************************/
void display(uchar numdis)
{
uchar tendis,sigledis;
tendis=numdis/10;
sigledis=numdis%10;
//
tdis=0;
P0=table[tendis];
delayms(5);
tdis=1;
P0=0xff;
//
sdis=0;
P0=table[sigledis];
delayms(5);
sdis=1;
P0=0xff;
}
/**************************************************
º¯Êý¹¦ÄÜ£ºÑÓʱº¯Êý£¬ÑÓʱһ¶Îʱ¼ä
***************************************************/
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
/**************************************************
³õʼ»¯º¯Êý
***************************************************/
void init()
{
TMOD=0x01;
TH0=(65536-45827)/256;
TL0=(65536-45827)%256;
IE=0x82;
}
/**************************************************
¼üÅÌɨÃ躯Êý
***************************************************/
void keyscan()
{
if(key1==0)
{
delayms(10);
if(key1==0)
{
num++;
if(num==60)
num=0;
while(!key1);
}
}
//
if(key2==0)
{
delayms(10);
if(key2==0)
{
if(num==0)
num=60;
num--;
while(!key2);
}
}
//
if(key3==0)
{
delayms(10);
if(key3==0)
{
num=0;
while(!key3);
}
}
//
if(key4==0)
{
delayms(10);
if(key4==0)
{
while(!key4);
TR0=~TR0;
}
}
}
/**************************************************
Ö÷º¯Êý
***************************************************/
void main()
{
init();
while(1)
{
keyscan();
display(num);
}
}
/**************************************************
ÖжϺ¯Êý
***************************************************/
void T0_time()interrupt 1
{
TH0=(65536-45827)/256;
TL0=(65536-45827)%256;
numt0++;
if(numt0>=20)
{
numt0=0;
num++;
if(num>=60)
num=0;
}
}
这个是根据郭老师教程的程序改的,现在这个程序也是正常的:K1显示数字加,K2显示数字减,K3显示数字清0,K4开中断和关中断,开中断时显示00-59循环。现在我有一点不明白,响应中断函数应该是60秒,在这60秒按按键应该是没有反应的,但烧进学习板按按键随时按随时有,是不是我分析中断程序有错误,请各位老师解答。
|