S3C2451_lcd 函数封装

S3C2451_lcd.h
#ifndef _S3C2451_LCD_H__
#define _S3C2451_LCD_H__
#include "typedef.h"


typedef struct{
        U32 VIDCON0;            
        U32 VIDCON1;                
        U32 VIDTCON0;           
        U32 VIDTCON1;   
        U32 VIDTCON2;   
        U32 WINCON0;        
        U32 WINCON1;        
        U32 UNUSED1;
        U32 UNUSED2;
        U32 UNUSED3;
        U32 VIDOSD0A;       
        U32 VIDOSD0B;
        U32 UNUSED4;
        U32 VIDOSD1A;   
        U32 VIDOSD1B;   
        U32 VIDOSD1C;   
        U32 UNUSED5[9];
        U32 VIDW00ADD0B0;
        U32 VIDW00ADD0B1;   
        U32 VIDW01ADD0;     
        U32 UNUSED6;
        U32 UNUSED7;
        U32 UNUSED8;
        U32 VIDW00ADD1B0;   
        U32 VIDW00ADD1B1;   
        U32 VIDW01ADD1; 
        U32 UNUSED9;
        U32 UNUSED10;
        U32 UNUSED11;
        U32 VIDW00ADD2B0;   
        U32 VIDW00ADD2B1;
        U32 VIDW01ADD2; 
        U32 UNUSED12;
        U32 UNUSED13;
        U32 UNUSED14;
        U32 VIDINTCON;      
        U32 W1KEYCON0;  
        U32 W1KEYCON1;
        U32 W2KEYCON0;
        U32 W2KEYCON1;  
        U32 W3KEYCON0;
        U32 W3KEYCON1;
        U32 W4KEYCON0;
        U32 W4KEYCON1;      
        U32 WIN0MAP;    
        U32 WIN1MAP;    
}volatile *LCD_MemMapPtr;

#define LCDCTRL_BASE_PTR            ((LCD_MemMapPtr)0x4C800000)

#define FRAME_BUFFER        LCD_BUFFER

/*TD35*/
#if 0

#define LCD_X                   240
#define LCD_Y                   320
#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)

#else

/*P43*/
#define LCD_X                   480
#define LCD_Y                   272
#define HSPW                (30)
#define HBPD                (10)
#define HFPD                (19)
#define VSPW                (8)
#define VBPD                (2)
#define VFPD                (4)
#define LINEVAL             (LCD_Y-1)
#define HOZVAL              (LCD_X-1)

#endif


#define LeftTopX     0
#define LeftTopY     0
#define RightBotX   (LCD_X-1)
#define RightBotY   (LCD_Y-1)

//extern const unsigned char zero2nine8x16[11][17];
//extern const char char_mode8x15[][15];

//const unsigned char feiji_320x240[]£»
//extern const unsigned char gImage_picture[];

extern void LCD_GPIO_Init(void);  //³õʼ»¯ LCDÏà¹ØGPIO
extern void LCD_Init(void);     //³õʼ»¯LCDÅäÖòÎÊý
extern void LCD_PutPixel(U32 x,U32 y,U32 c);
extern void LCD_Clear( U32 c);
extern void LCD_Display_Bmp(int x0,int y0,int h,int l,const unsigned char *bmp);
extern void LCD_Display_8x16(U32 x, U32 y, U32 col, const unsigned char ch[]);
extern void LCDDisplay_Char(U32 x, U32 y, U32 col, char s);
extern void LCDDisplay_String(U32 x, U32 y, U32 col, char *s);

#endif


S3C2451_lcd.c
#include "S3C2451_lcd.h"
#include "S3C2451_gpio.h"
LCD_MemMapPtr const LCD_BASE_PTR = LCDCTRL_BASE_PTR;

volatile unsigned int LCD_BUFFER[LCD_Y][LCD_X];

//0x000000
//0xff0000

void LCD_GPIO_Init(void)
{
    //端口复用设置
    GPIO_Init_Typedef gpio_init_struct;

    gpio_init_struct.pinx =  0x0000ffff;
    gpio_init_struct.mode = GPIO_MODE_ALT;
    gpio_init_struct.udp = GPIO_UDP_PULLUP;

    GPIO_Init(GPIOC,gpio_init_struct);

    gpio_init_struct.pinx =  0x0000ffff;
    gpio_init_struct.mode = GPIO_MODE_ALT;
    gpio_init_struct.udp = GPIO_UDP_PULLUP;

    GPIO_Init(GPIOD,gpio_init_struct);  


    //背光控制
    gpio_init_struct.pinx =  GPIO_PIN_1;
    gpio_init_struct.mode = GPIO_MODE_OUT;
    gpio_init_struct.udp = GPIO_UDP_PULLUP;

    GPIO_Init(GPIOB,gpio_init_struct);
    GPIO_WriteBit(GPIOB,GPIO_PIN_1,BIT_SET);

    //电源控制
    gpio_init_struct.pinx =  GPIO_PIN_2;
    gpio_init_struct.mode = GPIO_MODE_OUT;
    gpio_init_struct.udp = GPIO_UDP_PULLUP;

    GPIO_Init(GPIOG,gpio_init_struct);
    GPIO_WriteBit(GPIOG,GPIO_PIN_2,BIT_SET);

}

void LCD_Init(void)
{
    // 配置VIDCONx,设置接口类型、时钟、极性和使能LCD控制器等/
    LCD_BASE_PTR->VIDCON0 = (0<<22)|(0<<13)|(9<<6)|(1<<5)|(1<<4)|(0<<2)|(3<<0);
    LCD_BASE_PTR->VIDCON1 |= (1<<6)|(1<<5); 

    // 配置VIDTCONx,设置时序和长宽等
    // 设置时序
    LCD_BASE_PTR->VIDTCON0 = VBPD<<16 | VFPD<<8 | VSPW<<0;
    LCD_BASE_PTR->VIDTCON1 = HBPD<<16 | HFPD<<8 | HSPW<<0;

    // 设置长宽
    LCD_BASE_PTR->VIDTCON2 = (LINEVAL << 11) | (HOZVAL << 0);

    // 配置WINCON0,设置window0的数据格式
    LCD_BASE_PTR->WINCON0 = 0xB<<2; //RGB888
    LCD_BASE_PTR->WINCON0 |= (1<<0);
//  LCD_BASE_PTR->WINCON0 &= ~(0xf << 2);


    // 配置VIDOSD0A/B/C,设置window0的坐标系
    LCD_BASE_PTR->VIDOSD0A = (LeftTopX<<11) | (LeftTopY << 0);
    LCD_BASE_PTR->VIDOSD0B = (RightBotX<<11) | (RightBotY << 0);
    // 置VIDW00ADD0B0和VIDW00ADD1B0,设置framebuffer的地址
    LCD_BASE_PTR->VIDW00ADD0B0 = (unsigned long)FRAME_BUFFER;    //显示的BUFFER
  LCD_BASE_PTR->VIDW00ADD1B0 =(unsigned long)FRAME_BUFFER + sizeof(FRAME_BUFFER);
}
/*LCD描点函数*/
void LCD_PutPixel(U32 x,U32 y,U32 c)
{
    if(x>=LCD_X||y>=LCD_Y) return;
    LCD_BUFFER[y][x] = c;
}

/*LCD清屏函数*/
void LCD_Clear( U32 c)
{
    U16 x,y;
    for(y=0;y<LCD_Y;y++)
        for(x=0;x<LCD_X;x++)
        {
                LCD_BUFFER[y][x] = c;
                //delay(100000);
        }

}
/*LCD 显示图片*/
void LCD_Display_Bmp(int x0,int y0,int w,int h,const unsigned char *bmp)
{
    U16 x,y;

    U32 c;
    U32 i=0;
    for(y=0;y<h;y++)
        for(x=0;x<w;x++)
        {
            c = bmp[i]<<24 | bmp[i+1]<<16 | bmp[i+2]<<8 | bmp[i+3];
            LCD_PutPixel(x0+x,y0+y,c);
            i+=4;
        }

}

void LCDDisplay_Char(U32 x, U32 y, U32 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 LCDDisplay_String(U32 x, U32 y, U32 col, char *s)
{
    U16 ypos =y;
    do{
            LCDDisplay_Char(x, ypos, col, *s);
            ypos+=8;
        s++;
    }while(*s != '\0');
}

void LCD_Display_8x16(U32 x, U32 y, U32 col, const unsigned char ch[])
{
    unsigned short i, j;
    unsigned char mask, tem ;
    for(i=0; i<16; i++)    {                
        mask= 0x80 ;
        tem    = ch[i] ;    //俩个字节一组16位,取第一个字节
        for(j=0; j<8; j++)
        {
            if(tem & mask)
            {
                LCD_PutPixel(y+j, x+i+8, col) ;
            }
            mask = mask >> 1 ;
        }
    }
}

void LCD_Display_8x15(U32 x, U32 y, U32 col, const unsigned char ch[])
{
    unsigned short i, j;
    unsigned char mask, tem ;
    for(i=0; i<15; i++)    {

        mask= 0x80 ;
        tem    = ch[i] ;    //俩个字节一组16位,取第一个字节
        for(j=0; j<8; j++)
        {
            if(tem & mask)
            {
                LCD_PutPixel(x+j, y+i, col) ;
            }else
                            LCD_PutPixel(x+j, y+i, 0) ;

            mask = mask >> 1 ;
        }
    }
}
#if 0
void LCD_Display_mxn(U32 x, U32 y, U32 col, U16 width, U16 height, const unsigned char ch[])
{
    unsigned short i, j;
    unsigned char mask, tem ;
    int byteperline = (width +7)/8 ;
      char *ptr;

       ptr = ch;
    for(i=0; i<height; i++){            
            ptr += i * byteperline;     

            for(m= 0; m < byteperline; m ++){
                 mask= 0x80 ;
         tem    = *(ptr + m);    //俩个字节一组16位,取第一个字节
                for(j=0; j<8; j++)
                {
            if(tem & mask)
            {
                LCD_PutPixel(x+ m*8+j, y+i, col) ;
            }else
                            LCD_PutPixel(x+ m*8+j, y+i, 0) ;

            mask = mask >> 1 ;
        }
            }
    }
}


void LCD_Display_Char((U32 x, U32 y, U32 col, U16 width, U16 height, char *charBase[], char chard)
{
    LCD_Display_mxn(x, y, col,width,  height,charBase[chard - ' ']);
}
#endif




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值