S3C2451_lcd屏显示操作详解代码_ARM

这是本人基于三星的S3C2451的miniARM开发板写的有关lcd的一下代码,包括了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];
/*lcdGPIO初始化*/
void LCD_GPIO_Init(void)
{
    /*配置GPIO用于LCD的相关功能*/
    GPCCON = 0xAAAAAAAA;
    GPDCON = 0xAAAAAAAA;
    /*打开背光*/
    GPBCON &= ~(0x3 << 2);
    GPBCON |= (1 << 2);
    GPBDAT |= (1 << 1);
    /*打开LCD电源*/
    GPGCON &= ~(0x3 << 4);
    GPGCON |= (1 << 4);
    GPGDAT |= (1 << 2);
}
/*lcd初始化*/
void LCD_Init(void)
{
    /*配置VIDCONx,设置接口类型,时钟,极性和使能LCD控制器*/
    VIDCON0 |= (0<<22)|(0<<13)|(9<<6)|(1<<5)|(1<<4)|(0<<2)|(3<<0);
    VIDCON1 |= (1<<6)|(1<<5);

    /*配置VIDTCONx,设置时序和长度等*/
    /*设置时序*/
    VIDTCON0 = VBPD<<16 | VFPD<<8 | VSPW<<0;
    VIDTCON1 = HBPD<<16 | HFPD<<8 | HSPW<<0;
    /*设置长度*/
    VIDTCON2 = (LINEVAL << 11) | (HOZVAL << 0);

    /*配置WINCON0,设置wincon0的数据格式 RGB565*/
    WINCON0 |= (1<<0);
    WINCON0 &= ~(0xf << 2);
    /*设置16bpp (non-palletized)R: 5-G:6-B:5*/
    WINCON0 |= 0xB <<2;                 

    /*配置VIDOSD0A/B/C,设置wincon*/

    VIDOSD0A = (LeftTopX<<11) | (LeftTopY << 0);
    VIDOSD0B = (RightBotX<<11) | (RightBotY << 0);

    /*设置VIDW00ADD和VID00ADD1B0*/
    VIDW00ADD0B0 = (unsigned long)FRAME_BUFFER;

    VIDW00ADD1B0 = (((HOZVAL + 1)*4 + 0) * (LINEVAL + 1)) & (0xffffff);
}
/*lcd描点*/
void LCD_draw_pixel(U32 x, U32 y, U16 color)
{
    if (x >= LCD_X || y >= LCD_Y)
    {
        return;
    }
    DisplayBuf[y][x] = color;
}

/*lcd清屏*/
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;
            //delay();
        }
    }
}
/*lcd显示图片,必须是240*320的图片。bmp格式。以及图片需要使用转码工具转成数组,通过函数调用显示,想要转码工具的留一下邮箱,我会发给的哦*/
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");
    //LCD_Display_Char(100, 100, 0, '1');
    /*显示图片*/
    //LCD_Display_Bmp(0, 0, 240, 320, hah2);
    while(1);
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zxnsirius

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值