#include "reg52.h"
#include "absacc.h"
// 0 1 2 3 4 5 6 7 8 9 熄灭 -
code unsigned char tab[] = { 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xFF,0xBF};
unsigned char dspbuf[8] = {10,10,10,10,10,10,10,10}; //显示缓冲区
unsigned char dspcom = 0;
unsigned char biaozhi = 0;
unsigned char shi = 10,fen = 10,miao = 0;
unsigned int counter = 0;
unsigned int ms = 0;
void display(void);
//
void cls_buzz(void)
{
XBYTE[0xA000] = 0x00;
}
//
void cls_led(void)
{
XBYTE[0x8000] = 0xFF;
}
void Showxuehao (void) //41203129
{
dspbuf[0] = 4;
dspbuf[1] = 1;
dspbuf[2] = 2;
dspbuf[3] = 0;
dspbuf[4] = 3;
dspbuf[5] = 1;
dspbuf[6] = 2;
dspbuf[7] = 9;
}
void Showriqi(void)
{
dspbuf[0] = 1;
dspbuf[1] = 5;
dspbuf[2] = 11;
dspbuf[3] = 1;
dspbuf[4] = 2;
dspbuf[5] = 11;
dspbuf[6] = 1;
dspbuf[7] = 0;
}
void Showshijian(void)
{
dspbuf[0] = shi/10;
dspbuf[1] = shi%10;
dspbuf[2] = 11;
dspbuf[3] = fen/10;
dspbuf[4] = fen%10;
dspbuf[5] = 11;
dspbuf[6] = miao/10;
dspbuf[7] = miao%10;
}
//显示函数
void display(void)
{
XBYTE[0xE000] = 0xff; //消隐
XBYTE[0xC000] = (1<<dspcom);
XBYTE[0xE000] = tab[dspbuf[dspcom]]; //段码
if(++dspcom == 8){
dspcom = 0;
}
}
// 中断服务函数
void isr_
timer_0(void) interrupt 1 //默认中断优先级 1
{
unsigned char temp = 0;
if(++ms == 1000){
ms = 0;
counter++;
}
display(); //1ms执行一次
//
temp = read_key();
if(temp != 0xff)
{
delay(); //按键消抖
temp = read_key();
if(temp != 0xff)
{
//返回按键处理
key_proc(temp);
while(P3 != 0xff); //等待按键释放
}
}
}
//延时函数
void delay(void)
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 9;
j = 104;
k = 139;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
//按键扫描函数
unsigned char read_key(void)
{
unsigned char temp;
unsigned char key_value = 0xff;
temp = P3&0x0f;
switch(temp)
{
case 0x0e:
key_value = 1; //S7
break;
case 0x0d:
key_value = 2; //S6
break;
case 0x0b:
key_value = 3; //S5
break;
case 0x07:
key_value = 4; //S4
break;
}
return key_value;
}
//按键处理函数
void key_proc(unsigned char key)
{
switch(key)
{
case 1:
biaozhi = 1;
break;
case 2:
biaozhi = 2;
break;
case 3:
biaozhi = 3;
break;
case 4:
biaozhi = 4;
break;
}
}
//主函数
void main(void)
{
TMOD &= 0xF0; //11.0592Hz,1ms
TL0 = 0xCD;
TH0 = 0xD4;
TF0 = 0;
TR0 = 1;
ET0 = 1;
EA = 1;
cls_buzz();
cls_led();
//显示标志
if(biaozhi==0) Showxuehao();
if(biaozhi==1) Showriqi();
if(biaozhi==2) Showshijian();
if(biaozhi==3);
// 时间
if (counter==1)
{
miao ++;
if (miao >=60)
{
miao = 0;
fen++;
if (fen==60)
{
fen =0;
shi++;
if (shi==24)
{
shi=0;
}
}
}
}
}
compiling aa.c...AA.C(82): warning C206: 'read_key': missing function-prototypeAA.C(85): warning C206: 'delay': missing function-prototypeAA.C(90): warning C206: 'key_proc': missing function-prototypeAA.C(90): error C267: 'key_proc': requires ANSI-style prototypeAA.C(99): error C231: 'delay': redefinitionaa.c - 2 Error(s), 3 Warning(s).
一周热门 更多>