<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          S3C2440-RTC

          作者: 時(shí)間:2016-12-02 來(lái)源:網(wǎng)絡(luò) 收藏
          實(shí)時(shí)時(shí)鐘(RTC)的主要功能是在系統(tǒng)掉電的情況下,利用后備電源使時(shí)鐘繼續(xù)運(yùn)行,從而不會(huì)丟失時(shí)間信息。
          s3c2440內(nèi)部集成了RTC模塊,而且用起來(lái)也十分簡(jiǎn)單。其內(nèi)部的寄存器BCDSEC,BCDMIN,BCDHOUR,BCDDAY,BCDDATE,BCDMON和BCDYEAR分別存儲(chǔ)了當(dāng)前的秒,分,小時(shí),星期,日,月和年,表示時(shí)間的數(shù)值都是BCD碼。這些寄存器的內(nèi)容可讀可寫(xiě),并且只有在寄存器RTCCON的第0位為1時(shí)才能進(jìn)行讀寫(xiě)操作。為了防止誤操作,當(dāng)不進(jìn)行讀寫(xiě)時(shí),要把該位清零。當(dāng)讀取這些寄存器時(shí),能夠獲知當(dāng)前的時(shí)間;當(dāng)寫(xiě)入這些寄存器時(shí),能夠改變當(dāng)前的時(shí)間。另外需要注意的是,因?yàn)橛兴^的“一秒誤差”,因此當(dāng)讀取到的秒為0時(shí),需要重新再讀取一遍這些寄存器的內(nèi)容,才能保證時(shí)間的正確。
          下面是一個(gè)程序,可以在LCD上顯示當(dāng)前時(shí)間,如果按下按鍵,中斷產(chǎn)生,會(huì)更新LCD上的時(shí)間。如果不通過(guò)按鍵,直接刷屏,會(huì)造成閃爍。
          #include "Font_Libs.h"
          #include "2440addr.h"
          #define _ISR_STARTADDRESS 0x33ffff00
          #define pISR_EINT0 (*(unsigned *)(_ISR_STARTADDRESS+0x20))
          //垂直同步信號(hào)的脈寬、后肩和前肩
          #define VSPW 15
          #define VBPD 3
          #define VFPD 5
          //水平同步信號(hào)的脈寬、后肩和前肩
          #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[] = "當(dāng)前時(shí)間為";
          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模式,暫時(shí)不要開(kāi)啟LCD,因?yàn)檫€沒(méi)有設(shè)置好
          rLCDCON2=(VBPD<<24)|(LINEVAL<<14)|(VFPD<<6)|(VSPW); //rLCDCON2,rLCDCON3和rLCDCON4主要設(shè)置時(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需要進(jìn)行翻轉(zhuǎn),因?yàn)镃PU發(fā)出的是正脈沖,LCD使用的是負(fù)脈沖,所以要改變極性,PWREN使能電源信號(hào)
          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控制信號(hào)
          }
          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;
          }

          上一頁(yè) 1 2 3 下一頁(yè)

          評(píng)論


          技術(shù)專(zhuān)區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();