这是本人基于三星的S3C2451的miniARM开发板写的有关lcd的一下代码,包括了lcd初始化、lcd显示字符、描点、清屏等功能函数。提供给大家参考。
#define VIDCON0 (*(volatile unsigned *)0x4c800000)
#define VIDCON1 (*(volatile unsigned *)0x4c800004)
#define VIDTCON0 (*(volatile unsigned *)0x4c800008)
#define VIDTCON1 (*(volatile unsigned *)0x4c80000C)
#define VIDTCON2 (*(volatile unsigned *)0x4c800010)
#define WINCON0 (*(volatile unsigned *)0x4c800014)
#define WINCON1 (*(volatile unsigned *)0x4c800018)
#define VIDOSD0A (*(volatile unsigned *)0x4c800028)
#define VIDOSD0B (*(volatile unsigned *)0x4c80002C)
#define VIDOSD1A (*(volatile unsigned *)0x4c800034)
#define VIDOSD1B (*(volatile unsigned *)0x4c800038)
#define VIDOSD1C (*(volatile unsigned *)0x4c80003C)
#define VIDW00ADD0B0 (*(volatile unsigned *)0x4c800064)
#define VIDW00ADD0B1 (*(volatile unsigned *)0x4c800068)
#define VIDW01ADD0 (*(volatile unsigned *)0x4c80006C)
#define VIDW01ADD1 (*(volatile unsigned *)0x4c800084)
#define VIDW01ADD2 (*(volatile unsigned *)0x4c80009C)
#define VIDW00ADD1B0 (*(volatile unsigned *)0x4c80007C)
#define VIDW00ADD1B1 (*(volatile unsigned *)0x4c800080)
#define VIDW00ADD2B0 (*(volatile unsigned *)0x4c800094)
#define VIDW00ADD2B1 (*(volatile unsigned *)0x4c800098)
#define VIDINTCON (*(volatile unsigned *)0x4c8000AC)
#define W1KEYCON0 (*(volatile unsigned *)0x4c8000B0)
#define W1KEYCON1 (*(volatile unsigned *)0x4c8000B4)
#define W2KEYCON0 (*(volatile unsigned *)0x4c8000B8)
#define W2KEYCON1 (*(volatile unsigned *)0x4c8000BC)
#define W3KEYCON0 (*(volatile unsigned *)0x4c8000C0)
#define W3KEYCON1 (*(volatile unsigned *)0x4c8000C4)
#define W4KEYCON0 (*(volatile unsigned *)0x4c8000C8)
#define W4KEYCON1 (*(volatile unsigned *)0x4c8000CC)
#define WIN0MAP (*(volatile unsigned *)0x4c8000D0)
#define WIN1MAP (*(volatile unsigned *)0x4c8000D4)
#define WPALCON (*(volatile unsigned *)0x4c8000E4)
#define SYSIFCON0 (*(volatile unsigned *)0x4c800130)
#define SYSIFCON1 (*(volatile unsigned *)0x4c800134)
#define DITHMODE1 (*(volatile unsigned *)0x4c800138)
#define SIFCCON0 (*(volatile unsigned *)0x4c80013C)
#define SIFCCON1 (*(volatile unsigned *)0x4c800140)
#define SIFCCON2 (*(volatile unsigned *)0x4c800144)
#define CPUTRIGCON1 (*(volatile unsigned *)0x4c80015C)
#define CPUTRIGCON2 (*(volatile unsigned *)0x4c800160)
#define VIDW00ADD0B1 (*(volatile unsigned *)0x4c800068)
#define VIDW01ADD0 (*(volatile unsigned *)0x4c80006C)
#ifndef _TYPEDEF_H_
#define _TYPEDEF_H_
#define U32 unsigned int
#define U16 unsigned short
#define S32 int
#define S16 short int
#define U8 unsigned char
#define S8 char
#define TRUE 1
#define FALSE 0
#endif
#include "Main.h"
#include "typedef.h"
volatile unsigned int DisplayBuf[LCD_Y][LCD_X];
void LCD_GPIO_Init(void)
{
GPCCON = 0xAAAAAAAA;
GPDCON = 0xAAAAAAAA;
GPBCON &= ~(0x3 << 2);
GPBCON |= (1 << 2);
GPBDAT |= (1 << 1);
GPGCON &= ~(0x3 << 4);
GPGCON |= (1 << 4);
GPGDAT |= (1 << 2);
}
void LCD_Init(void)
{
VIDCON0 |= (0<<22)|(0<<13)|(9<<6)|(1<<5)|(1<<4)|(0<<2)|(3<<0);
VIDCON1 |= (1<<6)|(1<<5);
VIDTCON0 = VBPD<<16 | VFPD<<8 | VSPW<<0;
VIDTCON1 = HBPD<<16 | HFPD<<8 | HSPW<<0;
VIDTCON2 = (LINEVAL << 11) | (HOZVAL << 0);
WINCON0 |= (1<<0);
WINCON0 &= ~(0xf << 2);
WINCON0 |= 0xB <<2;
VIDOSD0A = (LeftTopX<<11) | (LeftTopY << 0);
VIDOSD0B = (RightBotX<<11) | (RightBotY << 0);
VIDW00ADD0B0 = (unsigned long)FRAME_BUFFER;
VIDW00ADD1B0 = (((HOZVAL + 1)*4 + 0) * (LINEVAL + 1)) & (0xffffff);
}
void LCD_draw_pixel(U32 x, U32 y, U16 color)
{
if (x >= LCD_X || y >= LCD_Y)
{
return;
}
DisplayBuf[y][x] = color;
}
void LCD_clear(U16 color)
{
U16 x, y;
for (y = 0; y < LCD_Y; y++)
{
for (x = 0; x < LCD_X; x++)
{
DisplayBuf[y][x] = color;
}
}
}
void LCD_Display_Bmp(U32 x0, U32 y0, U32 w, U32 h, const unsigned char *bmp)
{
U16 x;
U16 y;
U32 i = 0;
U16 color;
U16 img_w = x0+w-1;
U16 img_h = y0+h-1;
if (img_w >= LCD_X || img_h >= LCD_Y)
{
return;
}
for (x = x0; x < w; x++)
{
for (y = y0; y < h; y++)
{
color = bmp[i] << 8 | bmp[i + 1];
DisplayBuf[x + x0][y + y0] = color;
i += 2;
}
}
}
void LCD_Display_String(U32 x, U32 y, U16 col, char *s)
{
while(*s != '\0')
{
LCD_Display_Char(x, y, col, *s);
y = y+8;
s++;
}
}
void LCD_Display_Char(U32 x, U32 y, U16 col, char s)
{
int i;
for (i = 0; i < 11; i++)
{
if (zero2nine8x16[i][0] == s)
{
break;
}
}
LCD_Display_8x16(x, y, col, &zero2nine8x16[i][1]);
}
void LCD_Display_8x16(U32 x, U32 y, U16 col, const unsigned char ch[])
{
unsigned short i, j;
unsigned char mask, tem ;
for(i = 0; i < 16; i++)
{
mask = 0x80 ;
tem = ch[i] ;
for(j=0; j<8; j++)
{
if(tem & mask)
{
LCD_draw_pixel(y+j, x+i+8, col) ;
}
mask = mask >> 1 ;
}
}
}
#ifndef _LCD_H_
#define _LCD_H_
#define FRAME_BUFFER DisplayBuf
#define LCD_Y 320
#define LCD_X 240
#define HSPW (4)
#define HBPD (101- 1)
#define HFPD (1 - 1)
#define VSPW (9)
#define VBPD (1 - 1)
#define VFPD (1 - 1)
#define LINEVAL (LCD_Y - 1)
#define HOZVAL (LCD_X - 1)
#define LeftTopX 0
#define LeftTopY 0
#define RightBotX (LCD_X - 1)
#define RightBotY (LCD_Y - 1)
extern void LCD_GPIO_Init(void);
extern void LCD_Init(void);
extern void LCD_draw_pixel(U32 x, U32 y, U16 c);
extern void LCD_clear(U16 c);
extern void LCD_Display_Bmp(U32 x0, U32 y0, U32 w, U32 h, const unsigned char *bmp);
extern void LCD_Display_8x16(U32 x, U32 y, U16 col, const unsigned char ch[]);
extern void LCD_Display_Char(U32 x, U32 y, U16 col, char s);
extern void LCD_Display_String(U32 x, U32 y, U16 col, char *s);
#endif
#include "Main.h"
#include "typedef.h"
extern const unsigned char sirius[];
void Main()
{
LCD_GPIO_Init();
LCD_Init();
LCD_clear(0x00ffff);
LCD_Display_String(100, 100, 0, "15896");
while(1);
}