#include <SPCE061v004.h>
#include <unspmacro.h>
//中断函数定义
void IRQ1(void) __attribute__((ISR));
unsigned int hour,minute,second;
unsigned int show_hour=0xffff, show_minute=0xffff, show_second=0xffff;
// 7段LED数码管的字形码,采用高八位输出,决定显示的字形,如: '0'、'1'等
const unsigned int zhixingma[] = { 0x3f00, 0x0600, 0x5b00, 0x4f00,
0x6600, 0x6d00, 0x7d00, 0x0700,
0x7f00,0x6f00 };
//数码管选择的"位段码",决定哪一位数码管显示
const unsigned int weiduanma[] = {0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020};
//数码管的两个DD引脚,为时,中间的冒号亮
void display(unsigned int wei, unsigned int number)
{
*P_IOA_Data = zhixingma[number];
//设置位段码时,不能改变冒号的状态
*P_IOB_Data = weiduanma[wei] ;
}
//取反数码管中间的冒号
void delay(unsigned int howlong)
{
while(howlong--){
unsigned int temp = 0x00ff;
*P_Watchdog_Clear = 1;
while(temp--);
}
}
void init()
{
INT_OFF();
*P_IOA_Dir = 0xff00;
*P_IOA_Attrib = 0xff00;
*P_IOB_Dir = 0x00ff;
*P_IOB_Attrib = 0x00ff;
*P_TimerA_Data = 0xffff - 2048;
*P_TimerA_Ctrl = C_SourceA_1 | C_SourceB_2048Hz;
*P_INT_Ctrl = C_IRQ1_TMA ;
INT_IRQ();
}
int main()
{
init();
while(1){
// change_clock();
if(show_second){
display(5, second % 10);
delay(1);
display(4, second / 10);
delay(1);
}
if(show_minute){
display(3, minute % 10);
delay(1);
display(2, minute / 10);
delay(1);
}
if(show_hour){
display(1, hour % 10);
delay(1);
display(0, hour / 10);
delay(1);
}
}
}
void IRQ1()
{
//时钟计数中断
if( (C_IRQ1_TMA & *P_INT_Ctrl) != 0 )
{ if( 1 )
{ second++;
if(second >= 60 ) second=0, minute++;
if(minute >= 60 ) minute=0, hour++;
if(hour >= 24 ) hour=0;
}
*P_INT_Clear = C_IRQ1_TMA;
}
}