昨天编了个小的时钟,但是按键调节不起作用,一直在想是什么原因。今天发现是按键判断条件的e都写成了f,改好后终于能调节了,不过灵敏度太高了,按一下跳好多,调整了一下延时,ok搞定,然后改成了多文件的了,虽然不是很正规,但是还是学会了多文件是怎么回事,呵呵,继续完善它的功能!
main.c
#include <at89x52.h>
#include "main.h"
#include "yanshi.h"
#define uchar unsigned char
#define uint unsigned int
#define TICK 20
#define OSC_PER_INST 12
#define OSC_FREQ 11059200UL
#define TIMEOUT 50
#define PRELOAD50ms 65536-(TIMEOUT*OSC_FREQ)/(OSC_PER_INST*1000)
uchar LEDMAP[]={ 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
uchar Hour,Minute,Second;
uchar one;
uchar twe;
uchar three;
uchar four;
sbit LED1=P1^0;
sbit LED2=P1^1;
sbit LED3=P1^2;
sbit LED4=P1^3;
sbit K1=P2^4;
uint C100us;
void Delay(uint CNT)
{
uchar i;
for(i=CNT;i>0;i--);
}
void Display()
{
one=Hour/10;
twe=Hour%10;
three="Minute/10";
four=Minute%10;
P0=LEDMAP[one];
LED1=0;
Delay(100);
LED1=1;
P0=LEDMAP[twe];
LED2=0;
Delay(100);
LED2=1;
P0=LEDMAP[three];
LED3=0;
Delay(100);
LED3=1;
P0=LEDMAP[four];
LED4=0;
Delay(100);
LED4=1;
}
void T0Int () interrupt 1
{
C100us--;
TH0=PRELOAD50ms/256;
TL0=PRELOAD50ms%256;
if(C100us==0)
{
Second++;
C100us=TICK;
if(Second==60)
{
Second=0;
Minute++;
if(Minute==60)
{
Minute=0;
Hour++;
if(Hour==24)
{
Hour=0;
}
}
}
}
}
void main ()
{
uchar i;
Timer0Init();
Hour=0;
Minute=0;
Second=0;
C100us=TICK;
TR0=1;
while(1)
{GetKey();
for(i=0;i<100;i++)
{ Display();
}
}
}
void GetKey()
{
uchar i,j;
K1=0;
i=P2;
Delay(100);
j=P2;
K1=1;
if (i==j)
{
if (j==0xee)
{
if(Hour<23)
Hour++;
else
Hour="0";
}
if (j==0xed)
{
if(Hour>0)
Hour--;
else
Hour=23;
}
if (j==0xeb)
{
if(Minute<59)
Minute++;
else
Minute=0;
}
if (j==0xe7)
{
if(Minute>0)
Minute--;
else
Minute=59;
}
}
}
用户1268540 2008-9-1 22:36