LCD彩屏驱动模块

/**********************************************************
*                                                         *
*                   彩屏驱动程序                              *
*                                                          *
**********************************************************/

#include 
#include
#include "Lcd.h"
#include "char.h"
#include "16.h"
#include "24.h"
#include "12.h"
#include "delay.h"
#include "main.h"


uint colors[]={0xf800,0x07e0,0x001f,0xffe0,0x0000,0x07ff,0xf81f,0xffff };
//初始化

char idata wen[]={"36.8'C"};
char idata shi[]={"76.2%RH"};
char idata co2[]={"995ppm"};
char idata guang[]={"2632LX"};

char  idata wen_s[]={"36.9'C"};
char  idata shi_s[]={"77.2%RH"};
char  idata co2_s[]={"805ppm"};
char  idata guang_s[]={"2302LX"};


/**********************************************************
函数:showfigure()
功能:更新测量值

**********************************************************/
void showfigure(void)
{

   P2 = 0xff;
   P0 = 0xff;

   LCD_ShowString(90,70,colors[5],colors[2],wen);//temp
   LCD_ShowString(90,95,colors[5],colors[2],shi);//humi
   LCD_ShowString(130,120,colors[5],colors[2],guang);
   LCD_ShowString(170,145,colors[5],colors[2],co2);

   LCD_ShowString(90,260,colors[5],colors[2],wen_s);
   LCD_ShowString(90,285,colors[5],colors[2],shi_s);
   LCD_ShowString(130,310,colors[5],colors[2],guang_s);
   LCD_ShowString(170,335,colors[5],colors[2],co2_s);  
}




/**********************************************************
函数:showmenu()
功能:彩屏显示菜单

**********************************************************/
void showmenu(void)
{

   P2 = 0xff;
   P0 = 0xff;
 
   ChineseChar(60,20,2,colors[5],colors[2],1);    //大
   ChineseChar(90,20,2,colors[5],colors[2],2);    //棚
   ChineseChar(120,20,2,colors[5],colors[2],3);    //指
   ChineseChar(150,20,2,colors[5],colors[2],4);    //标

   ChineseChar(30,70,1,colors[5],colors[2],1);    //温
   ChineseChar(50,70,1,colors[5],colors[2],2);    //度
   ChineseChar(70,70,1,colors[5],colors[2],3);    //:
   LCD_ShowString(90,70,colors[5],colors[2],wen);//temp

   ChineseChar(30,95,1,colors[5],colors[2],4);    //湿
   ChineseChar(50,95,1,colors[5],colors[2],2);    //度
   ChineseChar(70,95,1,colors[5],colors[2],3);    //:
   LCD_ShowString(90,95,colors[5],colors[2],shi);//humi

   ChineseChar(30,120,1,colors[5],colors[2],6);    //光
   ChineseChar(50,120,1,colors[5],colors[2],7);    //照
   ChineseChar(70,120,1,colors[5],colors[2],8);    //强
   ChineseChar(90,120,1,colors[5],colors[2],2);    //度
   ChineseChar(110,120,1,colors[5],colors[2],3);    //:
   LCD_ShowString(130,120,colors[5],colors[2],guang);

   ChineseChar(30,145,1,colors[5],colors[2],9);    //二
   ChineseChar(50,145,1,colors[5],colors[2],13);    //氧
   ChineseChar(70,145,1,colors[5],colors[2],14);    //化
   ChineseChar(90,145,1,colors[5],colors[2],15);    //碳
   ChineseChar(110,145,1,colors[5],colors[2],5);    //浓
   ChineseChar(130,145,1,colors[5],colors[2],2);    //度
   ChineseChar(150,145,1,colors[5],colors[2],3);    //:
   LCD_ShowString(170,145,colors[5],colors[2],co2);


   ChineseChar(60,210,2,colors[5],colors[2],5);    //最
   ChineseChar(90,210,2,colors[5],colors[2],6);    //佳
   ChineseChar(120,210,2,colors[5],colors[2],7);//参
   ChineseChar(150,210,2,colors[5],colors[2],8);//数

   ChineseChar(30,260,1,colors[5],colors[2],1);//温
   ChineseChar(50,260,1,colors[5],colors[2],2);    //度
   ChineseChar(70,260,1,colors[5],colors[2],3);    //:
   LCD_ShowString(90,260,colors[5],colors[2],wen_s);
   

   ChineseChar(30,285,1,colors[5],colors[2],4);    //湿
   ChineseChar(50,285,1,colors[5],colors[2],2);    //度
   ChineseChar(70,285,1,colors[5],colors[2],3);    //:
   LCD_ShowString(90,285,colors[5],colors[2],shi_s);

   ChineseChar(30,310,1,colors[5],colors[2],6);    //光
   ChineseChar(50,310,1,colors[5],colors[2],7);    //照
   ChineseChar(70,310,1,colors[5],colors[2],8);    //强
   ChineseChar(90,310,1,colors[5],colors[2],2);    //度
   ChineseChar(110,310,1,colors[5],colors[2],3);    //:
   LCD_ShowString(130,310,colors[5],colors[2],guang_s);
 

   ChineseChar(30,335,1,colors[5],colors[2],9);    //二
   ChineseChar(50,335,1,colors[5],colors[2],13);    //氧
   ChineseChar(70,335,1,colors[5],colors[2],14);    //化
   ChineseChar(90,335,1,colors[5],colors[2],15);    //碳
   ChineseChar(110,335,1,colors[5],colors[2],5);    //浓
   ChineseChar(130,335,1,colors[5],colors[2],2);    //度
   ChineseChar(150,335,1,colors[5],colors[2],3);    //:
   LCD_ShowString(170,335,colors[5],colors[2],co2_s);  
}




/**********************************************************
函数:LCD_Write()
功能:写命令与数据子函数

**********************************************************/
void LCD_Write(uchar type, uint value)  
{
    LCD_CS = 0;
    LCD_RS     = type;            // 0: command    1: data
    
    LCD_WR  = 0;

    DATA     = (uchar)(value>>8)    ;
    LCD_WR  = 1;
    _nop_();
    LCD_WR  = 0;

    DATA     = (uchar)value;
    LCD_WR     = 1;
    _nop_();
    LCD_CS = 1;
}



/**********************************************************
函数: LCD_Wirte_Data16()
功能: 写16位数据子函数

**********************************************************/
void LCD_Wirte_Data16(uint value)    // color data
{
    LCD_CS = 0;
    LCD_RS     = 1;
    LCD_WR  = 0;
    //DATA     = (uchar)value;
    DATA     = (uchar)(value>>8)    ;
    LCD_WR  = 1;
    LCD_WR  = 0;
    //DATA     = (uchar)(value>>8)    ;
    DATA     = (uchar)value;
    LCD_WR     = 1;
    LCD_CS = 1;

}




/*********************************************************
函数:Reg_Write()
功能: 写数据和和命令到寄存器

**********************************************************/
void Reg_Write(uint reg,uint value)
{
   LCD_Write(TYPE_LCD_COMMAND,reg);      //写命令
   LCD_Wirte_Data16(value);              //写数据
}



/**********************************************************
函数:LCD_SetRamAddr()
功能:设置显示窗口子函数

**********************************************************/
void LCD_SetRamAddr(uint xStart, uint xEnd, uint yStart, uint yEnd)
{

    Reg_Write(0x200, xStart);
    Reg_Write(0x201, yStart);

    Reg_Write(0x0210, xStart);
    Reg_Write(0x0212, yStart);
    
    Reg_Write(0x211,  xEnd);
    Reg_Write(0x213,  yEnd);

    LCD_Write(TYPE_LCD_COMMAND,0x0202);
 
}




/***********************************************************
* 函数:InitLcd()                                               *
* 功能:LCD初始化                                              *                            
***********************************************************/

 void  LCD_init(void)
{
        LCD_RST=1;
        delay_ms(5);    
        LCD_RST=0;
         delay_ms(5);
        LCD_RST=1;
        delay_ms(5);
        LCD_CS =0;  //打开片选使能

    Reg_Write(0x000,0x0000); delay_ms(5);
    Reg_Write(0x000,0x0000); delay_ms(5);
    Reg_Write(0x000,0x0000); delay_ms(5);
    Reg_Write(0x000,0x0000); delay_ms(5);
    delay_ms(100);
    LCD_Wirte_Data16(0x0000);delay_ms(5);
    LCD_Wirte_Data16(0x0000);delay_ms(5);    
    LCD_Wirte_Data16(0x0000);delay_ms(5);    
    LCD_Wirte_Data16(0x0000);delay_ms(5);
      delay_ms(100);

    Reg_Write(0x400,0x6200); delay_ms(5);
     Reg_Write(0x008,0x0808); delay_ms(5);

    Reg_Write(0x300,0x0c0c); delay_ms(5);//GAMMA
    Reg_Write(0x301,0xff13); delay_ms(5);
    Reg_Write(0x302,0x0f0f); delay_ms(5);
    Reg_Write(0x303,0x150b); delay_ms(5);

    Reg_Write(0x304,0x1020); delay_ms(5);

    Reg_Write(0x305,0x0a0b); delay_ms(5);
    Reg_Write(0x306,0x0003); delay_ms(5);    
    Reg_Write(0x307,0x0d06); delay_ms(5);
    Reg_Write(0x308,0x0504); delay_ms(5);
    Reg_Write(0x309,0x1030); delay_ms(5);

    Reg_Write(0x010,0x001b); delay_ms(5);   //60Hz
     Reg_Write(0x011,0x0101); delay_ms(5);
    Reg_Write(0x012,0x0000); delay_ms(5);
    Reg_Write(0x013,0x0001); delay_ms(5);

    Reg_Write(0x100,0x0330); delay_ms(5);//BT,AP 0x0330
    Reg_Write(0x101,0x0247); delay_ms(5);//DC0,DC1,VC
    Reg_Write(0x103,0x1000); delay_ms(5);//VDV    //0x0f00
    Reg_Write(0x280,0xbf00); delay_ms(5);//VCM
    Reg_Write(0x102,0xd1b0); delay_ms(5);//VRH,VCMR,PSON,PON

    delay_ms(1220);

    Reg_Write(0x001,0x0100); delay_ms(5);
    Reg_Write(0x002,0x0100); delay_ms(5);
    Reg_Write(0x003,0x1030); delay_ms(5);
    Reg_Write(0x009,0x0001); delay_ms(5);
    Reg_Write(0x0C,0x0000);  delay_ms(5);    //MCU interface
    Reg_Write(0x090,0x8000); delay_ms(5);
    Reg_Write(0x00f,0x0000); delay_ms(5);


       Reg_Write(0x210,0x0000); delay_ms(5);
    Reg_Write(0x211,0x00ef); delay_ms(5);
    Reg_Write(0x212,0x0000); delay_ms(5);
    Reg_Write(0x213,0x018f); delay_ms(5);

    Reg_Write(0x500,0x0000); delay_ms(5);
    Reg_Write(0x501,0x0000); delay_ms(5);
    Reg_Write(0x502,0x005f); delay_ms(5);
    Reg_Write(0x401,0x0001); delay_ms(5);
    Reg_Write(0x404,0x0000); delay_ms(5);
    delay_ms(500);

       Reg_Write(0x0007,0x0100);delay_ms(5);
    delay_ms(1000);

       Reg_Write(0x200,0x0000); delay_ms(5);
    Reg_Write(0x201,0x0000); delay_ms(5);
    delay_ms(500);

      LCD_Write(TYPE_LCD_COMMAND,0x0202);
    delay_ms(500);

}




/***********************************************************
* 函数LCD_clear()                                               *
* 功能:清屏                                                  *                            
***********************************************************/\
void  LCD_clear(unsigned char x)
{
  unsigned int com,seg;    
  LCD_SetRamAddr(0,239, 0,399);
     
  for(com=0;com<400;com++)
  {
       for(seg=0;seg<240;seg++)
    {
      LCD_Wirte_Data16(colors[x]);
    }
    
  }
}



/**********************************************************
*  LCD_ShowChar()                                                    *
*  字符显示子函数                                         *
*                                                         *
**********************************************************/
void LCD_ShowChar(uint x,uint y,uint For_color,uint Bk_color, char ch)
{       
   uint temp;
   uint pos,t;
   uint  CHAR_W,CHAR_H;
   
   CHAR_W = 8;         //8*16
   CHAR_H = 16;

   if(x>(LCD_SIZE_X-CHAR_W)||y>(LCD_SIZE_Y-CHAR_H))
   return;
   
   LCD_SetRamAddr(x, x+CHAR_W-1, y,y+CHAR_H-1);
   ch = ch-32;                       //按照ASCII编码顺序的到相应字母的编码

   for(pos=0;pos>j)&0x01)
     {
       LCD_Wirte_Data16(For_color);  //textcolor
     }
     else
     {
       LCD_Wirte_Data16(Bk_color);  //backcolor
     }
  }
}




你可能感兴趣的:(嵌入式)