lcdd.h
资源名称:RFID.rar [点击查看]
上传用户:njxy551199
上传日期:2022-04-06
资源大小:1990k
文件大小:14k
源码类别:
RFID编程
开发平台:
C/C++
- #include "lcd.h"
- #include "asc_zimo.h"
- #include "Hz_zimo.h"
- #define ILI9325
- #define ILI9325_12864
- U16 PenColor;
- U16 BackColor;
- //===================== 微秒延时子程序 ==========================
- void DelayUs(U16 us)
- {
- while(us--);
- }
- //==================== 毫秒延时子程序 ===========================
- void DelayMs( U16 ms)
- {
- while(ms--)
- DelayUs(149);
- }
- //=================================
- #ifdef ILI9325_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;
- }
- //=================================
- 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;
- }
- //=================================
- /*
- void LCD_WrDat8(U8 dat)
- {
- LCD_nCS=0;
- LCD_RS=1;
- LCD_DAT=(dat);
- 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
- //=================================
- 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
- 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
- /*==================================================================
- * Function : LCD_SetPoit
- * Description : 设置lcd memory point
- * Input Para : U8 StartX, U8 StartY
- * Output Para : void
- * Return Value: void
- ==================================================================*/
- #ifdef ILI9325
- void LCD_SetGramPoit(U16 x,U16 y)
- {
- LCD_WrCmdDat(0x0020,x);
- LCD_WrCmdDat(0x0021,y);
- LCD_WrCmd(0x0022); //设置地址后重新启动写RAM命令
- }
- #endif
- /*==================================================================
- * 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
- /**************************************************************************************
- * 名 称: DispOneColor
- * 功 能: 使任意矩形显示某种颜色
- * 参 数: 颜色值:Color
- * 返 回 值: 无
- **************************************************************************************/
- void DispOneColor(U16 X,U16 Y,U16 W,U16 H,U16 Color)
- {
- U16 i,j;
- LCD_SetWindows(X, Y, W, H);
- for(i = Y; i <= H ; i++)
- {
- for(j = X; j <= W; j++)
- {
- LCD_WrDat(Color);
- }
- }
- }
- /*
- 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;
- }
- /**************************************************************************************
- * 名 称: 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<sizeof(AsciiLib)/sizeof(AsciiLib[0]);j++)
- if((U8)AsciiLib[j].Index==pHz[0])break;
- //--------------------------
- if(j<len) //j<len,说明该字已经在汉字中出现
- {
- LCD_SetWindows(x, y, x+7, y+15);
- for (i=0;i<16;i++)
- {
- str = (U8)AsciiLib[j].Msk[i];
- for (k=0;k<8;k++)
- {
- 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); //跳过这一点,即保留该点原有的信息
- }
- }
- }
- }
- }
- }
- /**************************************************************************************
- * 名 称: 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<sizeof(HzLib)/sizeof(HzLib[0]);i++)
- if((U8)HzLib[i].Index[0]==pHz[0]&&(U8)HzLib[i].Index[1]==pHz[1])break;
- //--------------------------
- if(i<len) //j<len,说明该字已经在汉字中出现
- {
- LCD_SetWindows(x, y, x+15, y+15);
- for (j=0;j<16;j++)
- {
- 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); //跳过这一点,即保留该点原有的信息
- }
- }
- }
- }
- }
- }
- /**************************************************************************************
- * 名 称: 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; //移动指针
- }
- }
- }
- /**************************************************************************************
- * 名 称: DispNum
- * 功 能: 显示触摸屏点击处的坐标(用于调试用)
- * 参 数: 坐标竖直要显示的位置:x,y
- 要显示的坐标值
- 存放坐标值的数组名:str
- * 返 回 值: 无
- **************************************************************************************/
- /*
- void DispNum(U16 x, U16 y, U16 num,U16 LineColor,U16 FillColor, U8 Mod)
- {
- uchar i;
- uchar n[9];
- n[0] = num/10000000+0x30;
- n[1] = (num%10000000)/1000000+0x30;
- n[2] = (num%10000000)%1000000/100000+0x30;
- n[3] = (num%10000000)%1000000%100000/10000+0x30;
- n[4] = (num%10000000)%1000000%100000%10000/1000+0x30;
- n[5] = (num%10000000)%1000000%100000%10000%1000/100+0x30;
- n[6] = (num%10000000)%1000000%100000%10000%1000%100/10+0x30;
- n[7] = (num%10000000)%1000000%100000%10000%1000%100%10+0x30;
- n[8] = ' ';
- for (i=0;i<sizeof(n);i++)
- {
- if ((n[i]-0x30!=0)||(i==sizeof(n)-1)) //抑制前导0
- {
- DrawString( x+Size_Asic_W/2*(i), y, n+i, LineColor, FillColor, Mod);
- return;
- }
- }
- }
- */
- /**************************************************************************************
- * 名 称: DispSmallPic
- * 功 能: 在指定的位置显示一张65K色的图片
- * 参 数: 显示的起始坐标:x,y
- 图片的宽度和高度:w,h
- 图片数据的数组名:str
- * 返 回 值: 无
- **************************************************************************************/
- /*
- void DispSmallPic(U16 x, U16 y, U16 w, U16 h, const U8 *pPoint)
- {
- U16 i,j;
- for(j=0;j<h;j++)
- {
- LCD_SetGramPoit(x,y+j);
- for(i=0;i<w;i++) //图片数据存放的格式是高字节在前,低字节在后
- {
- LCD_WrDat8(*pPoint++);
- LCD_WrDat8(*pPoint++);
- }
- }
- }
- */
- /**************************************************************************************
- * 名 称: disintlcd
- * 返 回 值: 无
- ***************************************************************************************/
- void disintlcd(void)
- {
- DispOneColor(0,0,239,69,BLUE) ; //head
- DispOneColor(0,70,239,93,RED) ; //biaoti
- DrawString(38, 74,"射 频 卡 缴 费 系 统",BLACK, RED, NORMAL);
- DispOneColor(0,94,239,319,GREEN) ;
- DispOneColor(15,170,64,219,BLUE) ;
- DispOneColor(120,200,230,231,WHITE) ;//baibiao
- DispOneColor(120,236,230,267,WHITE) ;
- DrawString(80, 208,"卡号",BLACK, GREEN, NORMAL);
- DrawString(80, 244,"余额",BLACK, GREEN, NORMAL);
- DispOneColor(120,297,239,316,BLUE) ;
- DrawString(50, 299,"伟嵌科技",BLACK, GREEN, NORMAL);
- }