#include \"lcd.h\"
#include \"asc_zimo.h\" #include \"Hz_zimo.h\"
#define LT1763
#define DATA_12864
U16 PenColor; U16 BackColor;
//==================== 微秒延时子程序 ========================== void DelayUs(U16 us) { while(us--); }
//=================== 毫秒延时子程序 =========================== void DelayMs( U16 ms) { while(ms--) DelayUs(149); }
//================================= #ifdef DATA_12864
void LCD_WrCmd(U16 cmd) //时序见手册 {
LCD_nCS=0; LCD_RS=0;
LCD_DAT=(cmd>>8); //write high byte LCD_nWR=0; LCD_nWR=1;
LCD_DAT=(cmd&0xff); //write low byte LCD_nWR=0; LCD_nWR=1; LCD_nCS=1; }
1
//================================= void LCD_WrDat(U16 dat) {
LCD_nCS=0; LCD_RS=1;
LCD_DAT=(dat>>8); //write high byte LCD_nWR=0; LCD_nWR=1;
LCD_DAT=(dat&0xff); //write low byte LCD_nWR=0; LCD_nWR=1; LCD_nCS=1; }
U16 LCD_RdDat(void) {
U16 buf;
buf = XBYTE[0x1C00]; /*
LCD_nCS_0; LCD_RS_1; LCD_nRD_0;
buf=LCD_Dat_Rd;
buf=buf & 0xff00; //read high byte LCD_nRD_1; LCD_nRD_0;
buf=(LCD_Dat_Rd>>8)|buf;//read low byte LCD_nRD_1; LCD_nCS_1; return buf; */ }
#endif
2
//================================= void LCD_WrCmdDat(U16 addr,U16 dat) {
LCD_WrCmd(addr); LCD_WrDat(dat); }
#ifdef ILI9325
void LCD_Init(void) {
LCD_BLEN_0;
LCD_nRST_0; //低电平复位 DelayMs(10); LCD_nRST_1;
//************* Start Initial Sequence **********//
LCD_WrCmdDat(0x00E3, 0x3008);// Set internal timing LCD_WrCmdDat(0x00E7, 0x0012); // Set internal timing LCD_WrCmdDat(0x00EF, 0x1231); // Set internal timing LCD_WrCmdDat(0x0001, 0x0100); // set SS and SM bit LCD_WrCmdDat(0x0002, 0x0700); // set 1 line inversion
LCD_WrCmdDat(0x0003, 0x1030); // set GRAM write direction and BGR=1. LCD_WrCmdDat(0x0004, 0x0000); // Resize register
LCD_WrCmdDat(0x0008, 0x0207); // set the back porch and front porch LCD_WrCmdDat(0x0009, 0x0700); //00,00//set non-display area refresh
cycle ISC[3:0]
LCD_WrCmdDat(0x000A, 0x0000); // FMARK function LCD_WrCmdDat(0x000C, 0x0000); // RGB interface setting LCD_WrCmdDat(0x000D, 0x0000); // Frame marker Position LCD_WrCmdDat(0x000F, 0x0000); // RGB interface polarity //*************Power On sequence ****************//
LCD_WrCmdDat(0x0010, 0x00f0); //00,00//SAP,BT[3:0],AP,DSTB,SLP, STB LCD_WrCmdDat(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0] LCD_WrCmdDat(0x0012, 0x0096); //00,00 // VREG1OUT voltage
LCD_WrCmdDat(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude DelayMs(200); // Dis-charge capacitor power voltage LCD_WrCmdDat(0x0010, 0x1490); // SAP, BT[3:0], AP, DSTB, SLP, STB LCD_WrCmdDat(0x0011, 0x0227); // Set DC1[2:0], DC0[2:0], VC[2:0] DelayMs(50); // Delay 50ms
LCD_WrCmdDat(0x0012, 0x001D); // External reference voltage= Vci; DelayMs(50); // Delay 50ms
LCD_WrCmdDat(0x0013, 0x1A00); // Set VDV[4:0] for VCOM amplitude
3
LCD_WrCmdDat(0x0029, 0x0033); //00,0b // SetVCM[5:0] for VCOMH LCD_WrCmdDat(0x002B, 0x000e); //00,00 // Set Frame Rate DelayMs(50); // Delay 50ms LCD_WrCmdDat(0x0020, 0x0000); // GRAM horizontal Address LCD_WrCmdDat(0x0021, 0x0000); // GRAM Vertical Address // ----------- Adjust the Gamma Curve ----------// LCD_WrCmdDat(0x0030, 0x0007); LCD_WrCmdDat(0x0031, 0x0206); LCD_WrCmdDat(0x0032, 0x0506);
LCD_WrCmdDat(0x0035, 0x0704);
LCD_WrCmdDat(0x0036, 0x1203); LCD_WrCmdDat(0x0037, 0x0007); LCD_WrCmdDat(0x0038, 0x0000); LCD_WrCmdDat(0x0039, 0x0706); LCD_WrCmdDat(0x003C, 0x0701); LCD_WrCmdDat(0x003D, 0x000F);
//------------------ Set GRAM area ---------------//
LCD_WrCmdDat(0x0050, 0x0000); // Horizontal GRAM Start Address LCD_WrCmdDat(0x0051, 0x00EF); // Horizontal GRAM End Address LCD_WrCmdDat(0x0052, 0x0000); // Vertical GRAM Start Address LCD_WrCmdDat(0x0053, 0x013F); // Vertical GRAM Start Address LCD_WrCmdDat(0x0060, 0xA700); // Gate Scan Line LCD_WrCmdDat(0x0061, 0x0001); // NDL,VLE, REV LCD_WrCmdDat(0x006A, 0x0000); // set scrolling line
//-------------- Panel Control -------------------// */ LCD_WrCmdDat(0x0090, 0x0010); LCD_WrCmdDat(0x0092, 0x0600); LCD_WrCmdDat(0x0093, 0x0003); LCD_WrCmdDat(0x0095, 0x0110); LCD_WrCmdDat(0x0097, 0x0000); LCD_WrCmdDat(0x0098, 0x0000);
LCD_WrCmdDat(0x0007, 0x0133); // 262K color and display ON DelayMs(100);
LCD_BLEN_1;
PenColor=YELLOW; BackColor=RED; }
#endif
4
#ifdef LT1763
void LCD_Init(void) {
LCD_BLEN_1; LCD_nWR_1; //ALE=1;
LCD_nRST_0; //低电平复位 DelayMs(10);
LCD_nRST_1;
//================ Start Initial Sequence ==============// LCD_WrCmdDat(0x0011, 0x0001); // LCD_WrCmdDat(0x0013, 0x1334); // LCD_WrCmdDat(0x0010, 0x0530); // LCD_WrCmdDat(0x0012, 0x101D); // DelayMs(100);
LCD_WrCmdDat(0x0013, 0x3334); // LCD_WrCmdDat(0x0011, 0x0111); // LCD_WrCmdDat(0x0010, 0x1530); // DelayMs(100); //initial setting
LCD_WrCmdDat(0x0001,0x0100); LCD_WrCmdDat(0x0002,0x0700); LCD_WrCmdDat(0x0003,0x1030); LCD_WrCmdDat(0x0004,0x0141); LCD_WrCmdDat(0x0007,0x0005); LCD_WrCmdDat(0x0008,0x0202); LCD_WrCmdDat(0x000B,0x0000); LCD_WrCmdDat(0x000C,0x0000); LCD_WrCmdDat(0x000E,0x0015); LCD_WrCmdDat(0x00A1,0x1000); LCD_WrCmdDat(0x00A4,0x7300); LCD_WrCmdDat(0x0030,0x0202); LCD_WrCmdDat(0x0031,0x0000); LCD_WrCmdDat(0x0032,0x0404); LCD_WrCmdDat(0x0033,0x0203); LCD_WrCmdDat(0x0034,0x0207); LCD_WrCmdDat(0x0035,0x0202); LCD_WrCmdDat(0x0036,0x0707); LCD_WrCmdDat(0x0037,0x0002); LCD_WrCmdDat(0x0038,0x0F00); LCD_WrCmdDat(0x0039,0x0002);
5
LCD_WrCmdDat(0x0040,0x0000); LCD_WrCmdDat(0x0041,0x0000); LCD_WrCmdDat(0x0042,0x0140); LCD_WrCmdDat(0x0043,0x0000); LCD_WrCmdDat(0x0044,0x0000); LCD_WrCmdDat(0x0045,0x0000); LCD_WrCmdDat(0x0046,0xEF00); LCD_WrCmdDat(0x0047,0x013F); LCD_WrCmdDat(0x0048,0x0000); DelayMs(100);
//display on setting
LCD_WrCmdDat(0x0007,0x0025); LCD_WrCmdDat(0x0007,0x0027); DelayMs(100);
LCD_WrCmdDat(0x0007,0x0037); LCD_WrCmdDat(0x0020,0x0000); LCD_WrCmdDat(0x0021,0x0000);
DelayMs(100);
LCD_BLEN_0;
PenColor=YELLOW; BackColor=RED; }
#endif
/*========================================================== * Function : LCD_SetPoit
* Description : 设置lcd memory point * Input Para : U8 StartX, U8 StartY * Output Para : void * Return Value: void
===========================================================*/ void LCD_SetGramPoit(U16 x,U16 y) {
LCD_WrCmdDat(0x0020,x);
LCD_WrCmdDat(0x0021,y);
LCD_WrCmd(0x0022); //设置地址后重新启动写RAM命令 }
6
/*========================================================== * Function : lcd_set_write_area
* Description : 设置lcd memory write的区域
* Input Para : U8 StartX, U8 StartY,U8 EndX, U8 EndY * Output Para : void * Return Value: void
======================================================*/ #ifdef ILI9325
void LCD_SetWindows(U16 HSA, U16 VSA,U16 HEA, U16 VEA) {
LCD_WrCmdDat(0x0050,HSA); LCD_WrCmdDat(0x0051,HEA);
LCD_WrCmdDat(0x0052,VSA); LCD_WrCmdDat(0x0053,VEA);
//LCD_SetGramPoit(HSA,VSA); //根据扫描方式不同而不同 }
#endif
#ifdef LT1763
void LCD_SetWindows(U16 HSA, U16 VSA,U16 HEA, U16 VEA) {
LCD_WrCmdDat(0x0046,(HEA<<8)|HSA); //R46窗口水平起始结束地址,高八位为结束地址
LCD_WrCmdDat(0x0048,VSA); //R48 窗口垂直起始地址 LCD_WrCmdDat(0x0047,VEA); // R47 窗口垂直结束地址
//LCD_SetGramPoit(HSA,VSA); //根据扫描方式不同而不同 }
#endif
7
/******************************************************************** * 名 称: DispOneColor
* 功 能: 使任意矩形显示某种颜色 * 参 数: 颜色值:Color * 返 回 值: 无
********************************************************************/ void DispOneColor(U16 X,U16 Y,U16 W,U16 H,U16 Color) {
U16 i,j;
LCD_SetWindows(X,Y,X+W-1,Y+H-1);
LCD_SetGramPoit(X,Y); //根据扫描方式不同而不同 for(i=0;i void LCD_Clear(void) { DispOneColor(LCD_Sx, LCD_Sy, LCD_W, LCD_H,BackColor); } /*========================================================== * Function : lcd_display_full_screen_color * Description : 将全屏刷为某一颜色 * Input Para : U16 val * Output Para : void * Return Value: void ===========================================================*/ void Display_full_screen_color(U16 color) { U16 X, Y; LCD_SetWindows(LCD_Sx, LCD_Sy, LCD_Ex, LCD_Ey); LCD_SetGramPoit(LCD_Sx,LCD_Sy); //根据扫描方式不同而不同 for(X = 0; X < LCD_W; X++) { for(Y = 0; Y < LCD_H; Y++) { LCD_WrDat(color); } } return; } 8 /****************************************************************** * 名 称: DrawSingleAscii * 功 能: 在指定的位置显示单个字符 * 参 数: 坐标:x * 坐标:y * 字符的颜色:LineColor * 字符背景颜色:FillColor : * 返 回 值: 无 *******************************************************************/ void DrawSingleAscii(U16 x, U16 y, U8 *pHz, U16 LineColor,U16 FillColor, U8 Mod) { U16 j=0,i=0,k=0; U8 str; U16 len; //---------------------------查找该字是否已在字库中 len=sizeof(AsciiLib)/sizeof(AsciiLib[0]); for(j=0;j if ( str & (0x80>>k) ) //通过移位逐位发送数据 { LCD_WrDat((U16)(LineColor&0xffff)); } else { if (Mod == NORMAL) { LCD_WrDat((U16)(FillColor&0xffff)); } else { LCD_SetGramPoit(x+k+1,y+i); //跳过这一点,即保留该点原有的信息 } } } } } } 9 /******************************************************************** * 名 称: DrawSingleHz * 功 能: 在指定的位置显示汉字 * 参 数: 坐标:x * 坐标:y * 字符的颜色:LineColor * 字符背景颜色:FillColor ******************************************************************/ void DrawSingleHz(U16 x, U16 y, U8 *pHz, U16 LineColor,U16 FillColor, U8 Mod) { U16 i=0,j=0,k=0; U16 str,len; //---------------------------查找该字是否已在字库中 len=sizeof(HzLib)/sizeof(HzLib[0]); for(i=0;i str = (U8)HzLib[i].Msk[j*2]<<8|(U8)HzLib[i].Msk[j*2+1]; for (k=0;k<16;k++) { if ( str & (0x8000>>k) ) //通过移位逐位发送数据 { LCD_WrDat((U16)(LineColor&0xffff)); } else { if (Mod == NORMAL) { LCD_WrDat((U16)(FillColor&0xffff)); } else { LCD_SetGramPoit(x+k+1,y+j); /跳过这一点,即保留该点原有的信息 } 10 } } } } } /****************************************************************** * 名 称: DrawString * 功 能: 在指定的位置显示多个字符 * 参 数: 坐标:x * 坐标:y * 字符的颜色:LineColor * 字符背景颜色:FillColor * * 返 回 值: 无 ******************************************************************/ void DrawString(U16 x, U16 y, U8 *pStr, U16 LineColor,U16 FillColor, U8 Mod) { //把字符串的第一个字符的地址赋给字符指针变量pstr, //不是*pStr=\" \"详见濉跺《C程序设计》-谭浩强P252 while(1) { if (*pStr == 0) { return; } if (*pStr > 0x80) //大于0x80的为汉字 { DrawSingleHz(x, y, pStr, LineColor, FillColor, Mod); //调用显示单个汉字函数处理 x += 16; pStr += 2; } //移动指针 else //英文字符 { DrawSingleAscii(x, y, pStr, LineColor, FillColor, Mod); //调用显示单个字符函数处理 x += 8; pStr += 1; //移动指针 } } } 11 /******************************************************************** * 名 称: DispNum * 功 能: 显示触摸屏点击处的坐标(用于调试用) * 参 数: 坐标竖直要显示的位置:x,y 要显示的坐标值 存放坐标值的数组名:str * 返 回 值: 无 *******************************************************************/ void DispNum(U16 x, U16 y, U16 num) { U8 str[5]; str[0] = num/1000+0x30; str[1] = (num%1000)/100+0x30; str[2] = (num%1000)%100/10+0x30; str[3] = (num%1000)%100%10+0x30; str[4] = '\\0'; DrawString(x, y, str, RED, YELLOW, NORMAL); } /****************************************************************** * 名 称: DispSmallPic * 功 能: 在指定的位置显示一张65K色的图片 * 参 数: 显示的起始坐标:x,y 图片的宽度和高度:w,h 图片数据的数组名:str * 返 回 值: 无 ******************************************************************/ void DispSmallPic(U16 x, U16 y, U16 w, U16 h, const U8 *str) { U16 i,j,temp; for(j=0;j for(i=0;i 12 因篇幅问题不能全部显示,请点此查看更多更全内容