完成数码相框之前,要将图片转换为二进制数组,用的是Image2Lcd这个软件。将软件各选项与自己的开发板、寄存器中像素设置等设置成相同。如下图:
详细程序完成如下:
#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) /*用于设置显现缓存区时,取低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位数据信号线*/
#define rGPDDAT (*(volatile unsigned *)0x56000034)
#define rGPDUP (*(volatile unsigned *)0x56000038)
#define rGPGCON (*(volatile unsigned *)0x56000060) /*中止引脚,电源信号引脚*/
#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 /*屏幕的高*/
/*笔直同步信号的脉宽、后肩和前肩*/
#define VSPW (3-1)
#define VBPD (15-1)
#define VFPD (12-1)
/*水平同步信号的脉宽、后肩和前肩*/
#define HSPW (30-1)/*LCDCON4中设置*/
#define HBPD (38-1)
#define HFPD (20-1)
/*显现尺度*/
#define LINEVAL (LCD_HEIGHT-1)
#define HOZVAL (LCD_WIDTH-1)
/*for LCDCON1*/
#define CLKVAL_TFT 6 /*设置时钟信号频率为7.1M*/
#define MVAL_USED 0 /*设置VM信号的信号回转功率,用于STN LCD*/
#define PNRMODE_TFT 3 /*设置LCD类型 TFT型LCD*/
#define BPPMODE_TFT 13 /*24位TFT型LCD 24BPP*/
/*for LCDCON5*/
#define BPP24BL 0 /*32位数据表明24位色彩值时,低位数据有用,高8位无效*/
#define INVVCLK 0 /*像素值在VCLK下降沿有用*/
#define INVVLINE 1 /*翻转HSYNC信号*/
#define INVVFRAME 1 /*翻转VSYNC信号*/
#define INVVD 0 /*正常VD信号极性*/
#define INVVDEN 0 /*正常VDEN信号极性*/
#define PWREN 1 /*使能PWREN信号*/
#define BSWP 0 /*色彩数据字节不交流*/
#define HWSWP 0 /*色彩数据半字不交流*/
/*界说显现缓存区*/
volatile U32 LCD_BUFFER[LCD_HEIGHT][LCD_WIDTH];
/*延时程序*/
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为数据,所以每次需求3个八位数据。*/
t=t+3;
}
}
}
void Main(void)
{
//装备LCD相关引脚
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; /*设置LCD的类型、像素时钟、设置像素位数、使能LCD信号的输出。*/
rLCDCON2=(VBPD<<24)|(LINEVAL<<14)|(VFPD<<6)|(VSPW); /*这个非常重要。设置笔直方向各信号时刻参数。*/
rLCDCON3=(HBPD<<19)|(HOZVAL<<8)|(HFPD); /*设置水平方向各信号的时刻参数*/
rLCDCON4=(HSPW); /*设置HSYNC信号脉冲宽度*/
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用于设置显现缓存区,即把咱们界说的那个二维数组告知s3c2440。其间LCDBANK的9位数据指定LCD的BANK,
即显现缓存区的第30位到第22位地址;LCDBASEU的21位数据指定了LCD的基址,即显现缓存区开端地址的第21位到第1位;LCDBASEL的21位数据指定了LCD的尾址,
即显现缓存区完毕地址的第21位到第1位。例如,咱们想要在尺度为320×240的屏幕上显现24位色彩,界说的显现缓存区数组为LCD_BUFFER[240][320],
则LCDBANK等于LCD_BUFFER的第30位到第22位数据值(由于LCD_BUFFER表明的便是数组的首地址),LCDBASEU等于LCD_BUFFER的第21位到第1位数据值,
由所以用32位数据表明24为色彩,因而每个像素值是4个字节,所以LCDBASEL等于(LCD_BUFFER+(240×320×4))成果的第21位到第1位的数据值。
别的寄存器LCDSADDR3有两个内容:OFFSIZE和PAGEWIDTH。OFFSIZE用于虚拟屏幕的偏移长度,假如咱们不运用虚拟屏幕,就把它置为0;PAGEWIDTH界说了视口的宽,
单位是半字,如在上面的比如中,PAGEWIDTH应该为320×32÷16。
****************************************************************************************************************/
rLCDINTMSK|=(3); /*屏蔽LCD中止*/
rTCONSEL = 0; /*无效LPC3600*/
rGPGUP=rGPGUP&(~(1<<4))|(1<<4); /*GPG4上拉电阻无效*/
rGPGCON=rGPGCON&(~(3<<8))|(3<<8); /*设置GPG4为LCD_PWREN*/
rGPGDAT = rGPGDAT | (1<<4) ; /*GPG4置1 电源开关*/
rLCDCON5=rLCDCON5&(~(1<<3))|(1<<3); /*有用PWREN信号*/
rLCDCON5=rLCDCON5&(~(1<<5))|(0<<5); /*PWREN信号极性不翻*/
rLCDCON1|=1; /*LCD敞开*/
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);
}
}
完成效果图: