实时时钟(RTC)的首要功能是在体系掉电的情况下,运用后备电源使时钟持续运转,然后不会丢掉时刻信息。
s3c2440内部集成了RTC模块,而且用起来也非常简略。其内部的寄存器BCDSEC,BCDMIN,BCDHOUR,BCDDAY,BCDDATE,BCDMON和BCDYEAR别离存储了当时的秒,分,小时,星期,日,月和年,表明时刻的数值都是BCD码。这些寄存器的内容可读可写,而且只要在寄存器RTCCON的第0位为1时才干进行读写操作。为了避免误操作,当不进行读写时,要把该位清零。当读取这些寄存器时,能够获悉当时的时刻;当写入这些寄存器时,能够改动当时的时刻。别的需求留意的是,由于有所谓的“一秒差错”,因而当读取到的秒为0时,需求从头再读取一遍这些寄存器的内容,才干确保时刻的正确。
下面是一个程序,能够在LCD上显现当时时刻,假如按下按键,中止发生,会更新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; //设置CLKVAL,VCLK=HCLK/[(CLKVAL+1)*2],决议VM的触发方法,挑选显现形式和BPP形式,暂时不要敞开LCD,由于还没有设置好
rLCDCON2=(VBPD<<24)|(LINEVAL<<14)|(VFPD<<6)|(VSPW); //rLCDCON2,rLCDCON3和rLCDCON4首要设置时序
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需求进行翻转,由于CPU宣布的是正脉冲,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; //使能数据输出和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;
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ceping/254701.html