基于s3c2440實(shí)現(xiàn)的裸機(jī)數(shù)碼相框
具體程序?qū)崿F(xiàn)如下:
#define U32 unsigned int
#include "gImage_xiaogou.h"
#include "ningbo.h"
#include "tushu.h"
#include "bailu.h"
#include "yejing.h"
#define M5D(n) ((n) & 0x1fffff) /*用于設(shè)置顯示緩存區(qū)時(shí),取低21位地址*/
#define rGPCCON (*(volatile unsigned *)0x56000020) /*定義LCD管腳VM、VLINE、VCLK、LEND等*/
#define rGPCDAT (*(volatile unsigned *)0x56000024)
#define rGPCUP (*(volatile unsigned *)0x56000028)
#define rGPDCON (*(volatile unsigned *)0x56000030) /*24位數(shù)據(jù)信號(hào)線*/
#define rGPDDAT (*(volatile unsigned *)0x56000034)
#define rGPDUP (*(volatile unsigned *)0x56000038)
#define rGPGCON (*(volatile unsigned *)0x56000060) /*中斷引腳,電源信號(hào)引腳*/
#define rGPGDAT (*(volatile unsigned *)0x56000064)
#define rGPGUP (*(volatile unsigned *)0x56000068)
#define rLCDCON1 (*(volatile unsigned *)0x4d000000) /*LCD control 1*/
#define rLCDCON2 (*(volatile unsigned *)0x4d000004) /*LCD control 2*/
#define rLCDCON3 (*(volatile unsigned *)0x4d000008) /*LCD control 3*/
#define rLCDCON4 (*(volatile unsigned *)0x4d00000c) /*LCD control 4*/
#define rLCDCON5 (*(volatile unsigned *)0x4d000010) /*LCD control 5*/
#define rLCDSADDR1 (*(volatile unsigned *)0x4d000014) /*STN/TFT Frame buffer start address 1*/
#define rLCDSADDR2 (*(volatile unsigned *)0x4d000018) /*STN/TFT Frame buffer start address 2*/
#define rLCDSADDR3 (*(volatile unsigned *)0x4d00001c) /*STN/TFT Virtual screen address set*/
#define rLCDINTMSK (*(volatile unsigned *)0x4d00005c) /*LCD Interrupt mask*/
#define rTCONSEL (*(volatile unsigned *)0x4d000060) /*LPC3600 Control --- edited by junon*/
#define LCD_WIDTH 320 /*屏幕的寬*/
#define LCD_HEIGHT 240 /*屏幕的高*/
/*垂直同步信號(hào)的脈寬、后肩和前肩*/
#define VSPW (3-1)
#define VBPD (15-1)
#define VFPD (12-1)
/*水平同步信號(hào)的脈寬、后肩和前肩*/
#define HSPW (30-1)/*LCDCON4中設(shè)置*/
#define HBPD (38-1)
#define HFPD (20-1)
/*顯示尺寸*/
#define LINEVAL (LCD_HEIGHT-1)
#define HOZVAL (LCD_WIDTH-1)
/*for LCDCON1*/
#define CLKVAL_TFT 6 /*設(shè)置時(shí)鐘信號(hào)頻率為7.1M*/
#define MVAL_USED 0 /*設(shè)置VM信號(hào)的信號(hào)反轉(zhuǎn)效率,用于STN LCD*/
#define PNRMODE_TFT 3 /*設(shè)置LCD類型 TFT型LCD*/
#define BPPMODE_TFT 13 /*24位TFT型LCD 24BPP*/
/*for LCDCON5*/
#define BPP24BL 0 /*32位數(shù)據(jù)表示24位顏色值時(shí),低位數(shù)據(jù)有效,高8位無(wú)效*/
#define INVVCLK 0 /*像素值在VCLK下降沿有效*/
#define INVVLINE 1 /*翻轉(zhuǎn)HSYNC信號(hào)*/
#define INVVFRAME 1 /*翻轉(zhuǎn)VSYNC信號(hào)*/
#define INVVD 0 /*正常VD信號(hào)極性*/
#define INVVDEN 0 /*正常VDEN信號(hào)極性*/
#define PWREN 1 /*使能PWREN信號(hào)*/
#define BSWP 0 /*顏色數(shù)據(jù)字節(jié)不交換*/
#define HWSWP 0 /*顏色數(shù)據(jù)半字不交換*/
/*定義顯示緩存區(qū)*/
volatile U32 LCD_BUFFER[LCD_HEIGHT][LCD_WIDTH];
/*延時(shí)程序*/
void delay(int a)
{
int k;
for(k=0;k
;
}
void paint(const unsigned char ch[])
{
int x,y ;
int t=0;
for( y = 0 ; y < LCD_HEIGHT ; y++ )
{
for( x = 0 ; x < LCD_WIDTH ; x++ )
{
LCD_BUFFER[y][x] = (ch[t]<<16)|(ch[t+1]<<8)|(ch[t+2]);/*圖像為24位像素,圖像.h文件中都是8為數(shù)據(jù),所以每次需要3個(gè)八位數(shù)據(jù)。*/
t=t+3;
}
}
}
void Main(void)
{
//配置LCD相關(guān)引腳
rGPCUP = 0x00000000;
rGPCCON = 0xaaaa02a9; //1010 1010 1010 1010 0000 0010 1010 1001
rGPDUP = 0x00000000;
rGPDCON = 0xaaaaaaaa;
rLCDCON1=(CLKVAL_TFT<<8)|(MVAL_USED<<7)|(PNRMODE_TFT<<5)|(BPPMODE_TFT<<1)|0; /*設(shè)置LCD的類型、像素時(shí)鐘、設(shè)置像素位數(shù)、使能LCD信號(hào)的輸出。*/
rLCDCON2=(VBPD<<24)|(LINEVAL<<14)|(VFPD<<6)|(VSPW); /*這個(gè)非常重要。設(shè)置垂直方向各信號(hào)時(shí)間參數(shù)。*/
rLCDCON3=(HBPD<<19)|(HOZVAL<<8)|(HFPD); /*設(shè)置水平方向各信號(hào)的時(shí)間參數(shù)*/
rLCDCON4=(HSPW); /*設(shè)置HSYNC信號(hào)脈沖寬度*/
rLCDCON5 = (BPP24BL<<12) | (INVVCLK<<10) | (INVVLINE<<9) | (INVVFRAME<<8) | (0<<7) | (INVVDEN<<6) | (PWREN<<3) |(BSWP<<1) | (HWSWP);
rLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)|M5D((U32)LCD_BUFFER>>1);
rLCDSADDR2=M5D( ((U32)LCD_BUFFER+(LCD_WIDTH*LCD_HEIGHT*4))>>1 );
rLCDSADDR3=LCD_WIDTH*32/16;
/***************************************************************************************************************
在s3c2440中,寄存器LCDSADDR1和LCDSADDR2用于設(shè)置顯示緩存區(qū),即把我們定義的那個(gè)二維數(shù)組告訴s3c2440。其中LCDBANK的9位數(shù)據(jù)指定LCD的BANK,
即顯示緩存區(qū)的第30位到第22位地址;LCDBASEU的21位數(shù)據(jù)指定了LCD的基址,即顯示緩存區(qū)開(kāi)始地址的第21位到第1位;LCDBASEL的21位數(shù)據(jù)指定了LCD的尾址,
即顯示緩存區(qū)結(jié)束地址的第21位到第1位。例如,我們想要在尺寸為320×240的屏幕上顯示24位顏色,定義的顯示緩存區(qū)數(shù)組為L(zhǎng)CD_BUFFER[240][320],
則LCDBANK等于LCD_BUFFER的第30位到第22位數(shù)據(jù)值(因?yàn)長(zhǎng)CD_BUFFER表示的就是數(shù)組的首地址),LCDBASEU等于LCD_BUFFER的第21位到第1位數(shù)據(jù)值,
由于是用32位數(shù)據(jù)表示24為顏色,因此每個(gè)像素值是4個(gè)字節(jié),所以LCDBASEL等于(LCD_BUFFER+(240×320×4))結(jié)果的第21位到第1位的數(shù)據(jù)值。
另外寄存器LCDSADDR3有兩個(gè)內(nèi)容:OFFSIZE和PAGEWIDTH。OFFSIZE用于虛擬屏幕的偏移長(zhǎng)度,如果我們不使用虛擬屏幕,就把它置為0;PAGEWIDTH定義了視口的寬,
單位是半字,如在上面的例子中,PAGEWIDTH應(yīng)該為320×32÷16。
****************************************************************************************************************/
rLCDINTMSK|=(3); /*屏蔽LCD中斷*/
rTCONSEL = 0; /*無(wú)效LPC3600*/
rGPGUP=rGPGUP&(~(1<<4))|(1<<4); /*GPG4上拉電阻無(wú)效*/
rGPGCON=rGPGCON&(~(3<<8))|(3<<8); /*設(shè)置GPG4為L(zhǎng)CD_PWREN*/
rGPGDAT = rGPGDAT | (1<<4) ; /*GPG4置1 電源開(kāi)關(guān)*/
rLCDCON5=rLCDCON5&(~(1<<3))|(1<<3); /*有效PWREN信號(hào)*/
rLCDCON5=rLCDCON5&(~(1<<5))|(0<<5); /*PWREN信號(hào)極性不翻*/
rLCDCON1|=1; /*LCD開(kāi)啟*/
while(1)
{
paint(gImage_xiaogou);
delay(5000000);
paint(gImage_ningbo);
delay(5000000);
paint(gImage_tushu);
delay(5000000);
paint(gImage_bailu);
delay(5000000);
paint(gImage_yejing);
delay(5000000);
}
}
評(píng)論