S3C2440-RTC
s3c2440內(nèi)部集成了RTC模塊,而且用起來也十分簡單。其內(nèi)部的寄存器BCDSEC,BCDMIN,BCDHOUR,BCDDAY,BCDDATE,BCDMON和BCDYEAR分別存儲了當前的秒,分,小時,星期,日,月和年,表示時間的數(shù)值都是BCD碼。這些寄存器的內(nèi)容可讀可寫,并且只有在寄存器RTCCON的第0位為1時才能進行讀寫操作。為了防止誤操作,當不進行讀寫時,要把該位清零。當讀取這些寄存器時,能夠獲知當前的時間;當寫入這些寄存器時,能夠改變當前的時間。另外需要注意的是,因為有所謂的“一秒誤差”,因此當讀取到的秒為0時,需要重新再讀取一遍這些寄存器的內(nèi)容,才能保證時間的正確。
下面是一個程序,可以在LCD上顯示當前時間,如果按下按鍵,中斷產(chǎn)生,會更新LCD上的時間。如果不通過按鍵,直接刷屏,會造成閃爍。
#include "Font_Libs.h"
#include "2440addr.h"
#define _ISR_STARTADDRESS 0x33ffff00
#define pISR_EINT0 (*(unsigned *)(_ISR_STARTADDRESS+0x20))
//垂直同步信號的脈寬、后肩和前肩
#define VSPW 15
#define VBPD 3
#define VFPD 5
//水平同步信號的脈寬、后肩和前肩
#define HSPW 8
#define HBPD 58
#define HFPD 15
#define CLKVAL 10
#define HOZVAL 319
#define LINEVAL 239
#define PWREN 1
#define MMODE 0
#define PNRMODE 3
#define BPPMODE 13
#define INVVCLK 0
#define INVVD 0
#define INVVDEN 0
#define U32 unsigned int
#define M5D(n) ((n) & 0x1fffff)
#define PAGEWIDTH 320
#define OFFSIZE 0
#define LCD_XSIZE 320
#define LCD_YSIZE 240
#define SCR_XSIZE 320
#define SCR_YSIZE 240
#define INVVLINE 1
#define INVVFRAME 1
#define BPP24BL 0
#define BSWP 0
#define HWSWP 0
volatile U32 LCD_BUFFER[240][320];
unsigned char data_buffer[7] = {5*16+1,1*16+7,1*16+9,2*16+6,7,1*16+2,1*16+0};
unsigned char *temp;
unsigned char str0[] = "當前時間為";
unsigned char str1[] = "年";
unsigned char str2[] = "月";
unsigned char str3[] = "日";
unsigned char str[][7] = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
U32 flag;
void Init_LCD(){
rLCDCON1=(CLKVAL<<8)|(MMODE<<7)|(PNRMODE<<5)|(BPPMODE<<1)|0; //設(shè)置CLKVAL,VCLK=HCLK/[(CLKVAL+1)*2],決定VM的觸發(fā)方式,選擇顯示模式和BPP模式,暫時不要開啟LCD,因為還沒有設(shè)置好
rLCDCON2=(VBPD<<24)|(LINEVAL<<14)|(VFPD<<6)|(VSPW); //rLCDCON2,rLCDCON3和rLCDCON4主要設(shè)置時序
rLCDCON3=(HBPD<<19)|(HOZVAL<<8)|(HFPD);
rLCDCON4=(HSPW);
rLCDCON5 = (BPP24BL<<12) | (INVVCLK<<10) | (INVVLINE<<9) | (INVVFRAME<<8) | (0<<7) | (INVVDEN<<6) | (PWREN<<3) |(BSWP<<1) | (HWSWP); //INVVLINE和INVVFRAME需要進行翻轉(zhuǎn),因為CPU發(fā)出的是正脈沖,LCD使用的是負脈沖,所以要改變極性,PWREN使能電源信號
rLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)|M5D((U32)LCD_BUFFER>>1);
rLCDSADDR2=M5D(((U32)LCD_BUFFER+(SCR_XSIZE*SCR_YSIZE*4))>>1 );
rLCDSADDR3=PAGEWIDTH*32/16;
rLCDINTMSK|=(3);
rTCONSEL = 0;
rGPCUP = 0x0;
rGPDCON = 0xaaaaaaaa;
rGPCCON = 0xaaaa02a9;
rGPDUP = 0x0;
rGPGUP=rGPGUP&("(1<<4))|(1<<4);
rGPGCON=rGPGCON&("(3<<8))|(3<<8);
rLCDCON1 |= 1; //使能數(shù)據(jù)輸出和LCD控制信號
}
void Paint_background(U32 c, U32 startx, U32 starty, U32 endx, U32 endy){
U32 i,j;
for(j = starty; j < endy; j++)
for(i = startx; i < endx; i++)
LCD_BUFFER[j][ i] = c;
}
void SetTime(){
rRTCCON |= 0x1;
rBCDSEC = data_buffer[0];
rBCDMIN = data_buffer[1];
rBCDHOUR = data_buffer[2];
rBCDDATE = data_buffer[3];
rBCDDAY = data_buffer[4];
rBCDMON = data_buffer[5];
rBCDYEAR = data_buffer[6];
rRTCCON &= 0xfe;
}
關(guān)鍵詞:
S3C2440RTC實時時
評論