|
#include "BS87D20A-3.h"
//#define seg _pb
#define com1 _pc1
#define com2 _pc0
#define com3 _pc2
#define com4 _pc3
#define key1 _pd2
#define key2 _pd3
#define key3 _pa1
#define key4 _pa4
//#define ledc _pbc
const unsigned char tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char strtab[3];//緩沖區(qū)
//unsigned char cnt=0; //計(jì)數(shù)變量
unsigned char sec=0,min=0,hour=0;
unsigned char temp;
unsigned char key1_trg;
unsigned char key1_cont;
unsigned long s; //秒級
unsigned long mms; //毫秒級
unsigned long MS;//毫秒
//unsigned char station; //界面切換標(biāo)志位
unsigned char readdata;
unsigned char value_present;
unsigned char value_last=0;
void init()
{
_ctm0c0=0x20; // fh/16 2us
_ctm0c1=0xc1; // 定時/計(jì)數(shù)器模式 比較器a
_ctm0al=0xf4; // 1ms
_ctm0ah=0x01;
_pbc=0; //輸出
_pcc0=0;
_pcc1=0;
_pcc2=0;
_pcc3=0;
_pac1=1;
_pac4=1;
_pdc2=1;
_pdc3=1;
s=1000;
mms=20;
MS=5;
temp=0;
_pcpu0=1;
_pcpu1=1;
_pcpu2=1;
_pcpu3=1;
// station=0;
_mfe=1; //開多功能中斷
_ctm0ae=1; //CTM a中斷使能
_emi=1; //開總中斷
_ct0on=1; //開定時器
}
void displaypro()
{
strtab[0]=tab[sec%10];
strtab[1]=tab[sec/10];
strtab[2]=tab[min%10];
strtab[3]=tab[min/10];
}
void main()
{
init();
while(1)
{
GCC_CLRWDT();//清除開門狗
displaypro();
if(key1_trg)
{
sec++;if(sec==60);sec=0;
displaypro();
}
}
}
void __attribute__((interrupt(0x14))) ISR_CTMO(void)
{
_ctm0af=0;
s--;
MS--;
mms--;
if(! MS)
{ MS=5;//5MS 視覺暫留
displaypro();
com1=1;com2=1;com3=1;com4=1;
switch(temp)
{
case 0:com4=0;
_pb=strtab[temp]; break;
case 1:com3=0;
_pb=strtab[temp]; break;
case 2:com2=0;
_pb=strtab[temp]; break;
case 3:com1=0;
_pb=strtab[temp]; break;
default:break;
}
temp++;
if(temp==4)
temp=0;
}
if(! s)
{
s=1000;//1s電子鐘計(jì)數(shù)
sec++;
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
hour++;
if(hour==24)
{
hour=0;
}
}
}
}
if(!key1)
{if(!mms)
{
_ctm0ae=0;//關(guān)中斷
mms=20;//20ms按鍵消抖
{
value_present=key1;
if(value_present&value_last)
{
readdata=key1^0xff;
key1_trg = readdata & (readdata^cont);
key1_cont=readdata;
}
value_last=key1;
_ctm0ae=1;//開中斷
_ctm0af=0;
}
}
}
}
|
|