用ARM的LCD功能实现了一个简单的电子相册,找到了一个非常好用的图片取模软件,要做LCD实验的朋友一定会喜欢这个软件的.
顺便也请教一下在实验中碰到的问题,请高手赐教.谢谢!
以下是主程序,附件是头文件和用我的相片通过取模软件转成的C数组文件.可以直接运行。
//ac2440套件,LCD尺寸:320x240
/*问题:
#define VBPD 1
#define VFPD 5
#define VSPW 1
#define HBPD 39
#define HFPD 16
#define HSPW 5
这里的值是可以自己改的吗?怎么改?
*/
#define GLOBAL_CLK 1
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "mmu.h"
#include "profile.h"
#include "memtest.h"
#define XSIZE 360
#define YSIZE 256
#define CLKVAL 4
//vertical setting
#define VBPD 1
#define VFPD 5
#define LINEVAL YSIZE-1
#define VSPW 1
//horizonal setting
#define HBPD 44
#define HFPD 16
#define HOZVAL XSIZE-1
#define HSPW 5
void CLK_init(void);
void Delay100us(int time);
volatile static U16 LCDBUF[YSIZE][XSIZE];
static void LCD_IO_init(void);
static void LCD_init(void);
void LCD_on(void);
void LCD_off(void);
void LCD_clear(U16 n);
void BMP_display(int x0,int y0,int x1,int y1,const U8 *bmp);
extern unsigned char gImage_photo1[];
extern unsigned char gImage_photo2[];
extern unsigned char gImage_photo3[];
extern unsigned char gImage_photo4[];
extern unsigned char gImage_photo5[];
extern unsigned char gImage_photo6[];
extern unsigned char gImage_photo7[];
extern unsigned char gImage_photo8[];
void Main(void)
{
U16 n;
U16 num[8][2]={341,256,341,256,343,256,341,256,341,256,340,256,341,256,341,256};//保存各张图片的尺寸
U8 *photo[8]={
gImage_photo1,gImage_photo2,
gImage_photo3,gImage_photo4,
gImage_photo5,gImage_photo6,
gImage_photo7,gImage_photo8,
};
CLK_init();
LCD_IO_init();
LCD_init();
LCD_on();
LCD_clear( (0x1f<<11) | (0x3f<<5) | (0x1f) ) ; //clear screen white
while(1)
{
for(n=0;n<8;n++)
{
BMP_display(0, 0, num[n][0], num[n][1], photo[n]);
Delay100us(40000);
}
n=0;
}
}
void Delay100us(int time)
{
while(time)
{
int i;
for(i=0;i<5000;i++);
time--;
}
}
void CLK_init(void)
{
rMPLLCON &= ~0xFFFFF;
rMPLLCON |= (92<<12) | (1<<4) | 1; //初始化FCLK为400M
rCLKDIVN = (2<<1) | 1; //HCLK = FCLK/4 =100M,PCLK = HCLK/2 = 50M
}
static void LCD_IO_init(void)
{
rGPCUP=0xff;
rGPCCON=0xaaaa02aa;
rGPDUP=0xffffffff;
rGPDCON=0xaaaaaaaa;
}
static void LCD_init(void)
{
rLCDCON1=(CLKVAL<<8)|(3<<5)|(12<<1); //VCLK=10M,TFT LCD,16bpp
rLCDCON2=(VBPD<<24)|(LINEVAL<<14)|(VFPD<<6)|(VSPW);
rLCDCON3=(HBPD<<19)|(HOZVAL<<8)|(HFPD);
rLCDCON4=HSPW;
rLCDCON5=(1<<11)|(1<<9)|(1<<8)|(1<<3)|1;//5:6:5Format,Enable PWREN signal,Swap Enable
rLCDSADDR1=(((U32)LCDBUF>>22)<<21)|(((U32)LCDBUF&0x3fffff)>>1);
rLCDSADDR2=(((U32)LCDBUF+XSIZE*YSIZE*2)>>1)&0x1fffff;
rLCDSADDR3=XSIZE;
rLCDINTMSK |=3;//mask LCD interrupt
rTCONSEL &=~(0x17);//LCC3600 Disable, LPC3600 Disable
rTPAL=0;
}
void LCD_on(void)
{
rLCDCON1 |=1;
}
void LCD_off(void)
{
rLCDCON1 &=~1;
}
void LCD_clear(U16 n)
{
U32 x,y;
for(y=0;y<YSIZE;y++)
{
for(x=0;x<XSIZE;x++)
{
LCDBUF[y][x]=n;
}
}
}
void BMP_display(int x0,int y0,int x1,int y1,const U8 *bmp)
{
int x,y,p=0;
U32 data;
for(y=0;y<y1;y++)
{
for(x=0;x<x1;x++)
{
data=(bmp[p]<<8|bmp[p+1]);
if((x0+x)<XSIZE && (y0+y)<YSIZE)
LCDBUF[y0+y][x0+x]=data;
p=p+2;
}
}
}
一款彩色图形取模软件.rar (776 K) 下载次数:478 lcd test.rar (952 K) 下载次数:476 [ 此帖被liyaozu在2011-12-05 18:56重新编辑 ]