?? rtc.c
字號:
/*-------------------------------------------------------------------------
RTC.C For Real Time Clock
Copyright 2006 Microntek Technologies Co. Ltd.
-------------------------------------------------------------------------*/
#include "global612.h"
#include "rtc.h"
#include "display.h"
#include "math.h"
BYTE bCalendarOnFlag = 0;
BYTE bDays[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
BYTE * MonthStr[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
BYTE * Data_TimeStr[31] = {" 1"," 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9","10",
"11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30","31"};
#if defined(CCIR_640x480)
BYTE CCIR_640x480p = 1;
#else
BYTE CCIR_640x480p = 0;
#endif
#if (RTC_ENABLE==1)
float sinx[60];
float cosx[60];
#define PI 3.14159265358
extern ST_OSDWIN *g_psUserWinOSD;
#define SDA_IN Ui_ChangeGpioInput(SDA_RTC)
#define SDA_OUT Ui_ChangeGpioOutput(SDA_RTC)
#define SCL_OUT Ui_ChangeGpioOutput(SCL_RTC)
#define SET_SDA Ui_SetGpioData(SDA_RTC);RTC_Delay(1)
#define CLR_SDA Ui_ClrGpioData(SDA_RTC);RTC_Delay(1)
#define SET_SCL Ui_SetGpioData(SCL_RTC);RTC_Delay(1)
#define CLR_SCL Ui_ClrGpioData(SCL_RTC);RTC_Delay(1)
#define SET_RST Ui_SetGpioData(RST_RTC);RTC_Delay(1)
#define CLR_RST Ui_ClrGpioData(RST_RTC);RTC_Delay(1)
#define CHK_SDA Ui_CheckGpioData(SDA_RTC)
ST_CLOCK g_stClock;
ST_CLOCK *g_pstClock = &g_stClock;
void RTC_Delay(WORD value)
{
value *= 5;
while(value>0)
value--;
}
static void RTC_WP()
{
RTC_WriteByte(0x7,0x80);
}
static void RTC_UNWP()
{
RTC_WriteByte(0x7,0x00);
}
void RTC_Init()
{
RTC_WriteByte(0x7,0x80); // Set WP
if (RTC_ReadByte(0x0)&0x80)
{
RTC_WriteByte(0x7,0x0); // Clr WP
RTC_WriteByte(0x0,0x0); // Clr CH
RTC_WriteByte(0x7,0x80); // Set WP
}
BYTE angle;
for (angle = 0; angle < 60; angle++ )
{
sinx[angle] = sin(PI*angle/30);
cosx[angle] = cos(PI*angle/30);
}
}
static void RTC_SendByte(BYTE bData)
{
BYTE i;
SDA_OUT;
for (i=0;i<8;i++)
{
if (bData&0x1)
{
SET_SDA;
}
else
{
CLR_SDA;
}
SET_SCL;
CLR_SCL;
bData>>=1;
}
SDA_IN;
}
static BYTE RTC_GetByte()
{
BYTE i,bData = 0;
SDA_IN;
for (i=0;i<8;i++)
{
SET_SCL;
bData >>= 1;
if (CHK_SDA)
bData |= 0x80;
CLR_SCL;
}
return bData;
}
static void RTC_WriteByte(BYTE bAddr, BYTE bData)
{
BYTE i;
CLR_RST;
SET_RST;
bAddr = (bAddr<<1)|0x80; // Write
RTC_SendByte(bAddr);
RTC_SendByte(bData);
CLR_RST;
}
static void RTC_Write(BYTE *bData)
{
CLR_RST;
SET_RST;
RTC_SendByte(0xBE);
RTC_SendByte(bData[0]);
RTC_SendByte(bData[1]);
RTC_SendByte(bData[2]);
RTC_SendByte(bData[3]);
RTC_SendByte(bData[4]);
RTC_SendByte(bData[5]);
RTC_SendByte(bData[6]);
RTC_SendByte(0x80);
CLR_RST;
}
static BYTE RTC_ReadByte(BYTE bAddr)
{
BYTE i;
BYTE bData = 0;
CLR_RST;
SET_RST;
bAddr = (bAddr<<1)|0x81; // Read
RTC_SendByte(bAddr);
bData = RTC_GetByte();
CLR_RST;
return bData;
}
static void RTC_Read(BYTE *bData)
{
CLR_RST;
SET_RST;
RTC_SendByte(0xBF);
bData[0] = RTC_GetByte();
bData[1] = RTC_GetByte();
bData[2] = RTC_GetByte();
bData[3] = RTC_GetByte();
bData[4] = RTC_GetByte();
bData[5] = RTC_GetByte();
bData[6] = RTC_GetByte();
RTC_GetByte();
CLR_RST;
}
void RTC_ReadTime()
{
BYTE bData[7];
RTC_Read(bData);
g_pstClock->bSecond = ((bData[0]&0x70)>>4)*10+(bData[0]&0xF);
g_pstClock->bMinute = ((bData[1]&0x70)>>4)*10+(bData[1]&0xF);
g_pstClock->bHour = ((bData[2]&0x30)>>4)*10+(bData[2]&0xF);
g_pstClock->bDate = ((bData[3]&0x30)>>4)*10+(bData[3]&0xF);
g_pstClock->bMonth = ((bData[4]&0x10)>>4)*10+(bData[4]&0xF);
g_pstClock->bDay = (bData[5]&0xF);
g_pstClock->wYear = ((bData[6]&0xF0)>>4)*10+(bData[6]&0xF)+2000;
if (g_pstClock->wYear >2099 || g_pstClock->wYear <2000 )
g_pstClock->wYear = 2000;
if (g_pstClock->bMonth >12 || g_pstClock->bMonth < 1 )
g_pstClock->bMonth = 1;
if (g_pstClock->bDate > Get_MonthDays(g_pstClock->wYear,g_pstClock->bMonth) || g_pstClock->bDate < 1)
g_pstClock->bDate = 1;
if (g_pstClock->bHour >23 )
g_pstClock->bHour = 0;
if (g_pstClock->bMinute >59 )
g_pstClock->bMinute = 0;
if (g_pstClock->bSecond >59 )
g_pstClock->bSecond = 0;
}
void RTC_WriteTime()
{
BYTE bData[7];
RTC_UNWP();
bData[0] = g_pstClock->bSecond%10 + ((g_pstClock->bSecond/10)<<4);
bData[1] = g_pstClock->bMinute%10 + ((g_pstClock->bMinute/10)<<4);
bData[2] = g_pstClock->bHour%10 + ((g_pstClock->bHour/10)<<4);
bData[3] = g_pstClock->bDate%10 + ((g_pstClock->bDate/10)<<4);
bData[4] = g_pstClock->bMonth%10 + ((g_pstClock->bMonth/10)<<4);
bData[5] = g_pstClock->bDay;
bData[6] = (g_pstClock->wYear-2000)%10 + (((g_pstClock->wYear-2000)/10)<<4);
RTC_Write(bData);
// RTC_WriteByte(0x1,bData[1]);
RTC_WP();
}
DWORD CLOCK_X;
DWORD CLOCK_Y;
void Clear_TimeBar()
{
if (TEST_480X240p == 1 )
{
CLOCK_X = (g_wScreenDefaultWidth-120);
CLOCK_Y = 6;
}
else
{
CLOCK_X = (g_wScreenDefaultWidth-220);
CLOCK_Y = 14;
}
ST_OSDWIN *psWin = Idu_GetOsdWin();
Idu_OsdPaintArea(psWin, CLOCK_X, CLOCK_Y, g_wScreenDefaultWidth-CLOCK_X-10, 20, 0);
}
extern BOOL In_Setup;
BYTE * bHourStr[12] = { "12","1", "2","3","4","5","6","7", "8","9","10","11" };
#if defined(SJD_7A)||defined(SJD_7A_16M)
extern BYTE bColor = 0;
#endif
void Show_Clock()
{
/*
if ( g_sSetupMenu.bClockMode == 0 || In_Setup)
{
return;
}
*/
WORD CLOCK_R,CLOCK_R1,CLOCK_R2,CLOCK_R3,CLOCK_M_X,CLOCK_M_Y,CLOCK_HOUR_R,CLOCK_MIN_R,CLOCK_SEC_R;
if (TEST_480X240p == 1)
{
#if defined(SJD_7A)
CLOCK_M_X = 114;
CLOCK_M_Y = (g_wScreenDefaultHeight/2-12);
CLOCK_R = 90;
CLOCK_R1 = 84;
CLOCK_R2 = 78;
CLOCK_R3 = 62;
CLOCK_HOUR_R = 32;
CLOCK_MIN_R = 52;
CLOCK_SEC_R = 68;
#else
CLOCK_M_X = 130;
CLOCK_M_Y = (g_wScreenDefaultHeight/2);
CLOCK_R = 110;
CLOCK_R1 = 104;
CLOCK_R2 = 98;
CLOCK_R3 = 82;
CLOCK_HOUR_R = 54;
CLOCK_MIN_R = 70;
CLOCK_SEC_R = 82;
#endif
}
else if (CCIR_640x480p == 1)
{
CLOCK_M_X = 162;
CLOCK_M_Y = (g_wScreenDefaultHeight/2-20);
CLOCK_R = 156;
CLOCK_R1 = 144;
CLOCK_R2 = 134;
CLOCK_R3 = 116;
CLOCK_HOUR_R = 66;
CLOCK_MIN_R = 96;
CLOCK_SEC_R = 116;
}
else
{
#if defined(SJD_7A_16M)
CLOCK_M_X = 176;
CLOCK_M_Y = (g_wScreenDefaultHeight/2);
CLOCK_R = 160;
CLOCK_R1 = 124;
CLOCK_R2 = 116;
CLOCK_R3 = 100;
CLOCK_HOUR_R = 56;
CLOCK_MIN_R = 72;
CLOCK_SEC_R = 88;
#else
CLOCK_M_X = 196;
CLOCK_M_Y = (g_wScreenDefaultHeight/2);
CLOCK_R = 176;
CLOCK_R1 = 168;
CLOCK_R2 = 158;
CLOCK_R3 = 140;
CLOCK_HOUR_R = 80;
CLOCK_MIN_R = 130;
CLOCK_SEC_R = 140;
#endif
}
DWORD dwStartTime = GetCurMs2();
WORD angle, swHourX,swHourY,swMinuteX,swMinuteY,swSecondX,swSecondY;
Idu_OsdPaintArea(g_psUserWinOSD, CLOCK_M_X-CLOCK_R, CLOCK_M_Y-CLOCK_R, CLOCK_R*2, CLOCK_R*2, 0);
for (angle = 0; angle < 360; angle+=6 )
{
swHourX = CLOCK_M_X + sinx[angle/6]* CLOCK_R2;
if (TEST_480X240p == 1)
swHourY = CLOCK_M_Y - cosx[angle/6]* CLOCK_R2*7/8;
else
{
#if defined(SJD_7A_16M)
swHourY = CLOCK_M_Y - cosx[angle/6]* CLOCK_R2*5/4;
#else
swHourY = CLOCK_M_Y - cosx[angle/6]* CLOCK_R2;
#endif
}
swMinuteX = CLOCK_M_X + sinx[angle/6]* CLOCK_R1;
if (TEST_480X240p == 1)
swMinuteY = CLOCK_M_Y - cosx[angle/6]* CLOCK_R1*7/8;
else
{
#if defined(SJD_7A_16M)
swMinuteY = CLOCK_M_Y - cosx[angle/6]* CLOCK_R1*5/4;
#else
swMinuteY = CLOCK_M_Y - cosx[angle/6]* CLOCK_R1;
#endif
}
if (angle%30 == 0)
{
#if defined(SJD_7A)||defined(SJD_7A_16M)
if (angle%90 == 0)
{
bColor = 1;
}
else
{
bColor = 0;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -