新聞中心

S3C2440-AD應(yīng)用

作者: 時(shí)間:2016-12-02 來(lái)源:網(wǎng)絡(luò) 收藏
void Init_LCD(){
rLCDCON1=(CLKVAL<<8)|(MMODE<<7)|(PNRMODE<<5)|(BPPMODE<<1)|0; //設(shè)置CLKVAL,VCLK=HCLK/[(CLKVAL+1)*2],決定VM的觸發(fā)方式,選擇顯示模式和BPP模式,暫時(shí)不要開啟LCD,因?yàn)檫€沒有設(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_text(U32 x, U32 y, U32 color, unsigned char ch[], U32 lengx, U32 lengy){ //我的這個(gè)函數(shù)是通用的,只要正確傳遞參數(shù)
int i, j, test, t = -1;
for(i = 0; i < lengy; i++){
for(j = 0; j < lengx; j++){
if(j%8 == 0){
test = 0x80;
t++;
}
if(ch[t] & test)
LCD_BUFFER[x+i][y+j] = color;
test >>= 1;
}
}
}
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;
}
U32 readAD(U32 ch){
rADCCON = (1<<14)|(49<<6)|(ch<<3);
rADCCON |= 0x1;
while(rADCCON & 0x1);
while(!(rADCCON & 0x8000));
return ((U32)rADCDAT0 & 0x3ff)*99/0x3ff ;
}
int LcdMain(){
U32 temperature, pre[2];
pre[0] = pre[1] = 0;
Init_LCD();
Paint_background(0xFFFFFF,0,0,LCD_XSIZE,LCD_YSIZE);
Paint_text(100, 20, 0x0, wen, 48, 48);
Paint_text(100, 68, 0x0, du, 48, 48);
Paint_text(100, 116, 0x0, s1, 48, 48);
Paint_text(100, 212, 0x0, s2, 48, 48);
while(1){
temperature = readAD(0); //讀取溫度
if(temperature / 10 != pre[1]){ //如果溫度改變了,調(diào)節(jié)LCD上顯示的溫度,如果沒有改變跳過
pre[1] = temperature/10;
Paint_background(0xFFFFFF,164,100,164+24,100+48);
Paint_text(100, 164, 0x0, num+pre[1]*144,24,48); //因?yàn)槊總€(gè)數(shù)字占24*48/8=144個(gè)字節(jié),所以num+offset就可以定位
}
if(temperature %10 != pre[0]){
pre[0] = temperature%10;
Paint_background(0xFFFFFF,188,100,188+24,100+48);
Paint_text(100, 188, 0x0, num+pre[0]*144,24,48);
}
Delay(100);
}
}
上一頁(yè) 1 2 下一頁(yè)

評(píng)論


技術(shù)專區(qū)

關(guān)閉