⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd2478.c

📁 广州致远电子的SmartArm2400出厂时的演示代码。
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************Copyright (c)****************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info---------------------------------------------------------------------------------
** File name:           LCD2478.C
** Last modified Date:  2008-04-07
** Last Version:        1.2
** Descriptions:        the lcd controller's driver
**
**--------------------------------------------------------------------------------------------------------
** Created by:          Houxiaolong
** Created date:        2008-04-07
** Version:             1.0
** Descriptions:        the lcd controller's driver
**
**--------------------------------------------------------------------------------------------------------
** Modified by:         Houxiaolong
** Modified date:       2008-04-23
** Version:             1.1
** Descriptions:        add the lcd_OnOff function 
**-------------------------------------------------------------------------------------------------------
** Modified by:         Houxiaolong
** Modified date:       2008-05-5
** Version:             1.2
** Descriptions:        add the hardware cursor initialize
**                      
*********************************************************************************************************/

#include "LCD2478.h"
#include "cursor.h"
#include "config.h"

#define TEST     0

void delay_Ns(int idly);

__align(8) volatile unsigned short LCD_BUFFER[U_LCD_YSIZE][U_LCD_XSIZE];/*  display data buffer         */
/*********************************************************************************************************
** Function name :        lcd_Init
** Function Description : Initialize the LCD controler
** Input:                 none
** Output:                none
*********************************************************************************************************/
void lcd_Init (void)
{
    PCONP     |= (1 << 20);                                             /*  enable LCD controller power 
                                                                            control bit                 */    
    PINSEL0    = PINSEL0 & ~(0xfff << 8)   | (0x555 << 8);              /*  select lcd pin              */
    PINSEL3    = PINSEL3 & ~(0xfffff << 8) | (0x55555 << 8);            /*  select lcd pin              */
    PINSEL4    = PINSEL4 & ~(0x3f << 22)   | 0x054fffff;
    PINSEL9    = PINSEL9 & ~(0xf << 24)    | (0xa << 24);
    PINSEL10  &= 0xFFFFFFF7;
    PINSEL11   = (int)(0xfffffffll << 4)                                /*  Reserved,should write 1     */
               | (5 << 1)                                               /*  TFT 16-bit (5:6:5 mode)     */ 
               | (1 << 0);                                              /*  lcd port is enable          */   

    delay_Ns(15);

    
    LCD_UPBASE = (unsigned int)LCD_BUFFER;                              /*  set buffer's base address   */
    
    LCD_CTRL   = 0;                                                     /*  power disable               */
    delay_Ns(20);
               
    LCD_CFG    = 0x07;                                                  /*  pixel clock 9MHZ            */ 
    LCD_TIMH   = (HBP << 24) |                                          /*  set horizontal timing       */
                 (HFP << 16) |                                            
                 (HSW << 8)  |
                 (PPL << 2);
    
    LCD_TIMV   = (VBP << 24) |                                          /*  set vertical timing         */
                 (VFP << 16) |
                 (VSW << 10) |
                 (LPP << 0);
               
    LCD_POL    = (1 << 26)   |                                          /*  bypass pixel color driver   */
                 (CPL << 16) |                                          /*  240 clock per line          */
                 (0 << 14)   |                                          /*  LCDENAB output pin is active
                                                                            HIGH in TFT mode            */
                 (1 << 13)   |                                          /*  Data is driven on the LCD on 
                                                                            the rising edge of LCDDCLK  */
                 (1 << 12)   |                                          /*  HSYNC is active low         */                                           
                 (1 << 11)   |                                          /*  VSYNC is active low         */
                 (0 << 5);                                              /*  select HCLK                 */
    
    LCD_CTRL   = (LcdTFT << 5) |                                        /*  select TFT LCD type         */
                 (LcdBpp << 1) |                                        /*  select 16bpp                */
                 (LcdEn);                                               /*  LCD enable                  */
    
    LCD_INTMSK = 0;                                                     /*  disable LCD interrupt       */
    
    delay_Ns(20);
      
    LCD_CTRL  |= (1 << 11);                                             /*  Power enable                */
    delay_Ns(20);
    
    cursor_Init();                                                      /*  Initialize hardware cursor  */
                            
}    

           
/*********************************************************************************************************
** Function name :        lcd_ReadPixel
** Function Description : Get the pixel's color
** Input:                 ix       x side coordinate of the pixel
**                        iy       y side coordinate of the pixel 
** Output:                succeed  return the pixel's color
**                        fail     0
*********************************************************************************************************/
int lcd_ReadPixel (int ix, int iy)
{
    if ((ix < U_LCD_XSIZE) && (iy < U_LCD_YSIZE)) {
        return LCD_BUFFER[SECTION_Y(ix, iy)][SECTION_X(ix, iy)];
    } 
    
    return 0;
}  


/*********************************************************************************************************
** Function name :        lcd_Clear
** Function Description : Fill the LCD panel with a color
** Input:                 uicolor   LCD display color
** Output:                none
*********************************************************************************************************/
void lcd_Clear (unsigned int uicolor)
{
    int ix, iy;
    
    for (iy = 0; iy <U_LCD_YSIZE; iy++) {
        for (ix = 0; ix < U_LCD_XSIZE; ix++) {
            LCD_BUFFER[SECTION_Y(ix, iy)][SECTION_X(ix, iy)] = (unsigned short)uicolor;
        }
    }
}


/*********************************************************************************************************
** Function name :        lcd_OnOff
** Function Description : enable or disable the lcd data output
** Input:                 iOnOff  1:enable lcd data output 0: disable lcd data output
** Output:                none
**                        fail     0
*********************************************************************************************************/
void lcd_OnOff(int iOnOff)
{
    if (iOnOff==1) {
        LCD_CTRL |= (1 << 11);                                          /*  Lcd controller enable       */
    } else {
        LCD_CTRL &= ~(1 << 11);                                         /*  Lcd controller disable      */
    }
}


/*********************************************************************************************************
** Function name :        lcd_DrawHLine
** Function Description : Draw a horizontal line
** Input:                 ix0      x side coordinate of the first pixel
**                        ix1      x side coordinate of the last pixel
**                        iy       y side coordinate of the line
**                        uicolor  the color of the pixel 
** Output:                none
*********************************************************************************************************/
void lcd_DrawHLine (int ix0, int ix1, int iy, unsigned int uicolor)
{
    int i;
    for (i = ix0; i < ix1; i ++) {
        lcd_SetPixel(i, iy, uicolor);
    }
}


/*********************************************************************************************************
** Function name :        lcd_DrawVLine
** Function Description : Draw a vertical line
** Input:                 ix       x side coordinate of the line
**                        iy0      y side coordinate of the first pixel
**                        iy1      y side coordinate of the last pixel
**                        uicolor  the color of the pixel 
** Output:                none
*********************************************************************************************************/
void lcd_DrawVLine (int ix, int iy0, int iy1, unsigned int uicolor)
{
    int i;
    for (i = iy0; i < iy1; i ++) {
        lcd_SetPixel(ix, i, uicolor);
    }
}


/*********************************************************************************************************
** Function name :        lcd_DrawLine
** Function Description : Draw a line 
** Input:                 ix0      x side coordinate of the first pixel
**                        iy0      y side coordinate of the first pixel
**                        ix1      x side coordinate of the last pixel
**                        iy1      y side coordinate of the last pixel
**                        uicolor  the color of the pixel 
** Output:                none
*********************************************************************************************************/
void lcd_DrawLine (int ix0, int iy0, int ix1, int iy1, unsigned int uicolor)
{
    signed char dx_sym;                                                 /*  increase size of x          */
    signed char dy_sym;                                                 /*  increase size of y          */
    int  dx;                                                            /*  line of x's offset          */
    int  dy;                                                            /*  line of y's offset          */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -