#include <stdlib.h>
#include <string.h>
#include "option.h"
#include "44b.h"
//#include "44blib.h"
#include "def.h"
#include "rtc.h"
void AutoTest(void);
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
void Quit(void);
void ClearScreen(void);
volatile int flag=1;
volatile char which_int=0;
void __irq Rtc_Tick(void);
char *date[8] = {"","SUN","MON","TUE","WED","THU","FRI","SAT"};
volatile unsigned int sec_tick;
#define EXT_OSC_CLK 10000000
#define D12Cmd *(volatile U8 *)(0x04080000)
#define D12Cmd2 *(volatile U8 *)(0x04040000)
#define D12Cmd1 *(volatile U8 *)(0x0a0000ef)
#define D12Cmd3 *(volatile U8 *)(0x040c0000)
#define D12Cmd4 *(volatile U8 *)(0x04100000)
#define D12Cmd5 *(volatile U8 *)(0x04140000)
#define D12Cmd6 *(volatile U8 *)(0x04180000)
U32 PINLV;
U32 kkk;
U8 value1;
volatile U32 temp1;U8 temp;
U8 bin=0x0f;
void ChangePllValue(int mdiv, int pdiv, int sdiv)
{
int i = 1;
rPLLCON = (mdiv<<12)|(pdiv<<4)|sdiv;
while(sdiv--)
i *= 2;
PINLV = (EXT_OSC_CLK*(mdiv+8))/((pdiv+2)*i);
}
/****************************************
【功能说明】RTC test*
****************************************/
void Display_Rtc1(void)
{
int i;
int year,month,day,weekday,hour,min,sec;
Uart_Printf("\n 系统时间为:\n");
Rtc_Init();
rRTCCON = 0x01; // R/W enable, 1/32768, Normal(merge), No reset
while(1)
{
if(rBCDYEAR == 0x99)
year = 0x1999;
else
year = 0x2006 + rBCDYEAR;
month = 0x00 + rBCDMON;
day = 0x00 + rBCDDAY;
weekday= rBCDDATE;
hour = 0x00 + rBCDHOUR;
min = 0x00 + rBCDMIN;
sec = 0x00 + rBCDSEC;
/* year = rBCDYEAR;
month = rBCDMON;
day = rBCDDAY;
weekday= rBCDDATE;
hour = rBCDHOUR;
min = rBCDMIN;
sec = rBCDSEC;*/
if(min==0 && sec==0) //整点报时设定
{
rPDATF=0X14;
rPCONF=0X24911a;
Delay(2000); //报警音时长控制
rPDATF=0X10;
Delay(800); //报警音节奏控制
rPDATF=0X14;
Delay(5000);
rPDATF=0X10;
}
else if(D12Cmd2=0x07)
{ temp1=(rPDATC>>10)&bin;
if (temp1!=bin)
if (temp1==0x07)
break; //有键0按下,则跳出循环
}
Uart_Printf("%4x年,%2x月,%2x日,星期%s,时间%2x:%2x:%2x\r",year,month,day,date[weekday],hour,min,sec);
Delay(500);
rRTCCON=0x0;
}
}
void Display_Rtc2(void)
{
int year;
int month,day,weekday,hour,min,sec;
Rtc_Init();
rRTCCON = 0x01; // R/W enable, 1/32768, Normal(merge), No reset
Uart_Printf("\n 秒表计时:\n");
while(1)
{
hour=rBCDHOUR;
min=rBCDMIN;
sec=rBCDSEC;
D12Cmd2=0x07;
temp1=(rPDATC>>10)&bin;
if (temp1!=bin)
if (temp1==0x07)
break; //有键0按下,则跳出循环
Uart_Printf("%2x:%2x:%2x\r",hour,min,sec);
Delay(500);
}
rRTCCON = 0x0; // R/W disable(for power consumption), 1/32768, Normal(merge), No reset
}
void Display_Rtc3(void)
{
int i;
int year,month,day,weekday,hour,min,sec;
Rtc_Init();
Uart_Printf("\n 定时报警:\n");
rRTCCON = 0x01; // R/W enable, 1/32768, Normal(merge), No reset
while(1)
{
hour=rBCDHOUR;
min=rBCDMIN;
sec=rBCDSEC;
if(min==1) //设定报警定时时间为1分钟
break; //有键0按下,则跳出循环
Uart_Printf("%2x:%2x:%2x\r",hour,min,sec);
Delay(500);
rRTCCON=0x0;
}
for(i=0;i<20;i++) //报警音时长控制
{
rPDATF=0X14;
rPCONF=0X24911a;
Delay(1000);
rPDATF=0X10;
Delay(400);
rPDATF=0X14;
Delay(4000);
rPDATF=0X10;
Delay(4200); //报警音节奏控制
}
}
void Rtc_Init(void)
{
rRTCCON = 0x01; // R/W enable, 1/32768, Normal(merge), No reset
rBCDYEAR = TESTYEAR;
rBCDMON = TESTMONTH;
rBCDDAY = TESTDAY; // SUN:1 MON:2 TUE:3 WED:4 THU:5 FRI:6 SAT:7
rBCDDATE = TESTDATE;
rBCDHOUR = TESTHOUR;
rBCDMIN = TESTMIN;
rBCDSEC = TESTSEC;
}
/****************************************************************************
【功能说明】键盘设定函数
****************************************************************************/
void __irq Key_Int(void)
{
which_int=0;
rINTPND=0x1<<21;//清除中断源
rINTMSK=0x7ffffff;//
which_int=rEXTINTPND;
rEXTINTPND=0xf; //clear EXTINTPND reg.
rI_ISPC=BIT_EINT4567; //clear pending_bit
switch(which_int)
{
case 1:
Delay(20000);
Delay(10000);
rINTMSK=~(BIT_GLOBAL|BIT_EINT4567); //start INT
which_int=0;
break;
case 2:
rPDATE = 0x157;
Delay(20000);
Delay(10000);
rINTMSK=~(BIT_GLOBAL|BIT_EINT4567); //start INT
which_int=0;
break;
case 4:
which_int=0;
break;
case 8:
which_int=0;
break;
default :
break;
}
}
void Key_Init(void)
{
rINTCON=0x5;
rINTMOD=0x0; //All=IRQ mode
rEXTINT=0x0; //"0" level mode
rPCONG=0xffff; //EINT7~0
rPUPG=0x0; //pull up enable
pISR_EINT4567=(unsigned)Key_Int;
rINTMSK=~(BIT_GLOBAL|BIT_EINT4567); //start INT
}
U8 keyread()
{
U8 value;
D12Cmd2=0x0e;
temp1=(rPDATC>>10)&bin;
if (temp1!=bin)
{
if(temp1==0x0e) // f
{
value=0x01;
D12Cmd=0xe3;
D12Cmd3=0xe6;
D12Cmd4=0x43;
D12Cmd5=0xf5;
D12Cmd6=0xe1;
}
else if (temp1==0x0d) //b
{
value=0x05;
D12Cmd=0xe3;
D12Cmd3=0xe6;
D12Cmd4=0x43;
D12Cmd5=0xf5;
D12Cmd6=0xe1;
}
else if (temp1==0x0b) //7
{
value=0x09;
D12Cmd=0xe3;
D12Cmd3=0xe6;
D12Cmd4=0x43;
D12Cmd5=0xf5;
D12Cmd6=0xe1;
}
else if (temp1==0x07)
{
value=0x0d;
D12Cmd=0xb6;
D12Cmd3=0x82;
D12Cmd4=0x14;
D12Cmd5=0xd5;
D12Cmd6=0xe6;
Display_Rtc3(); //按键3,定时报警开始计时
}
return value;
}
D12Cmd2=0x0d;
temp1=(rPDATC>>10)&bin;
if (temp1!=bin)
{
if(temp1==0x0e) //e
{
value=0x02;
D12Cmd=0xe3;
D12Cmd3=0xe6;
D12Cmd4=0x43;
D12Cmd5=0xf5;
D12Cmd6=0xe1;
}
else if (temp1==0x0d) //a
{
value=0x06;
D12Cmd=0xe3;
D12Cmd3=0xe6;
D12Cmd4=0x43;
D12Cmd5=0xf5;
D12Cmd6=0xe1;
}
else if (temp1==0x0b) //6
{
value=0x0a;
D12Cmd=0xe3;
D12Cmd3=0xe6;
D12Cmd4=0x43;
D12Cmd5=0xf5;
D12Cmd6=0xe1;
}
else if (temp1==0x07)
{
value=0x0e;
D12Cmd=0xb3;
D12Cmd3=0x82;
D12Cmd4=0x14;
D12Cmd5=0xd5;
D12Cmd6=0xe6;
Display_Rtc2(); //按键2,秒表计时显示 rPDATF=0X14;
}
return value;
}
D12Cmd2=0x0b;
temp1=(rPDATC>>10)&bin;
if (temp1!=bin)
{
if(temp1==0x0e) //d