lcdd.h
上传用户:njxy551199
上传日期:2022-04-06
资源大小:1990k
文件大小:14k
源码类别:

RFID编程

开发平台:

C/C++

  1. #include "lcd.h"
  2. #include "asc_zimo.h"
  3. #include "Hz_zimo.h"
  4. #define ILI9325
  5. #define ILI9325_12864
  6. U16 PenColor;
  7. U16 BackColor;
  8. //===================== 微秒延时子程序 ==========================
  9. void DelayUs(U16 us)  
  10. {
  11. while(us--);
  12. }
  13. //==================== 毫秒延时子程序 ===========================
  14. void DelayMs( U16 ms)
  15. {
  16. while(ms--)
  17. DelayUs(149);
  18. }
  19. //=================================
  20. #ifdef ILI9325_12864
  21. void LCD_WrCmd(U16 cmd)    //时序见手册          
  22. {
  23.     LCD_nCS=0;
  24.     LCD_RS=0; 
  25.     LCD_DAT=(cmd>>8); //write high byte
  26.     LCD_nWR=0;
  27.     LCD_nWR=1;
  28.     LCD_DAT=(cmd&0xff);  //write low byte
  29.     LCD_nWR=0;
  30.     LCD_nWR=1;
  31.     LCD_nCS=1;
  32. }
  33. //=================================
  34. void LCD_WrDat(U16 dat)           
  35. {
  36.     LCD_nCS=0;
  37.     LCD_RS=1;
  38.     LCD_DAT=(dat>>8); //write high byte
  39.     LCD_nWR=0;
  40.     LCD_nWR=1;
  41.     LCD_DAT=(dat&0xff);  //write low byte
  42.     LCD_nWR=0;
  43.     LCD_nWR=1;
  44.     LCD_nCS=1;
  45. }
  46. //=================================
  47. void LCD_WrDat8(U8 dat)           
  48. {
  49.     LCD_nCS=0;
  50.     LCD_RS=1;
  51.     LCD_DAT=(dat);
  52.     LCD_nWR=0;
  53.     LCD_nWR=1;
  54.     LCD_nCS=1;
  55. }
  56. U16 LCD_RdDat(void)              
  57. {
  58.     U16 buf;
  59. buf = XBYTE[0x1C00];
  60. /*    
  61.     LCD_nCS_0;
  62.     LCD_RS_1;
  63.     LCD_nRD_0;
  64.     buf=LCD_Dat_Rd; 
  65.     buf=buf & 0xff00;   //read high byte
  66.     LCD_nRD_1;
  67.     LCD_nRD_0; 
  68.     buf=(LCD_Dat_Rd>>8)|buf;//read low byte
  69.     LCD_nRD_1;
  70.     LCD_nCS_1; 
  71. */
  72.     return buf;
  73. }
  74. #endif  
  75.  
  76. //=================================
  77. void LCD_WrCmdDat(U16 addr,U16 dat)
  78. {
  79.     LCD_WrCmd(addr);
  80.     LCD_WrDat(dat);
  81. }
  82. #ifdef  ILI9325
  83. void LCD_Init(void)
  84. {
  85.     LCD_BLEN_0;
  86.     LCD_nRST_0;      //低电平复位
  87.     DelayMs(10);
  88.     LCD_nRST_1;   
  89.  //************* Start Initial Sequence **********// 
  90.     LCD_WrCmdDat(0x00E3, 0x3008);// Set internal timing 
  91.     LCD_WrCmdDat(0x00E7, 0x0012); // Set internal timing 
  92.     LCD_WrCmdDat(0x00EF, 0x1231);   // Set internal timing 
  93.     LCD_WrCmdDat(0x0001, 0x0100);  // set SS and SM bit 
  94.     LCD_WrCmdDat(0x0002, 0x0700);     // set 1 line inversion 
  95.     LCD_WrCmdDat(0x0003, 0x1030);  // set GRAM write direction and BGR=1.  
  96.     LCD_WrCmdDat(0x0004, 0x0000);    // Resize register 
  97.     LCD_WrCmdDat(0x0008, 0x0207);    // set the back porch and front porch 
  98.     LCD_WrCmdDat(0x0009, 0x0700);    //00,00// set non-display area refresh cycle ISC[3:0] 
  99.     LCD_WrCmdDat(0x000A, 0x0000);    // FMARK function 
  100.     LCD_WrCmdDat(0x000C, 0x0000);    // RGB interface setting 
  101.     LCD_WrCmdDat(0x000D, 0x0000);    // Frame marker Position 
  102.     LCD_WrCmdDat(0x000F, 0x0000);    // RGB interface polarity 
  103.   //*************Power On sequence ****************// 
  104.     LCD_WrCmdDat(0x0010, 0x00f0);    //00,00// SAP, BT[3:0], AP, DSTB, SLP, STB 
  105.     LCD_WrCmdDat(0x0011, 0x0007);     // DC1[2:0], DC0[2:0], VC[2:0] 
  106.     LCD_WrCmdDat(0x0012, 0x0096);    //00,00 // VREG1OUT voltage 
  107.     LCD_WrCmdDat(0x0013, 0x0000);     // VDV[4:0] for VCOM amplitude 
  108.       DelayMs(200);                            // Dis-charge capacitor power voltage 
  109.     LCD_WrCmdDat(0x0010, 0x1490);   // SAP, BT[3:0], AP, DSTB, SLP, STB 
  110.     LCD_WrCmdDat(0x0011, 0x0227);    // Set DC1[2:0], DC0[2:0], VC[2:0] 
  111.       DelayMs(50);                       // Delay 50ms   
  112.     LCD_WrCmdDat(0x0012, 0x001D);    // External reference voltage= Vci; 
  113.       DelayMs(50);                       // Delay 50ms 
  114.     LCD_WrCmdDat(0x0013, 0x1A00);     // Set VDV[4:0] for VCOM amplitude 
  115.     LCD_WrCmdDat(0x0029, 0x0033);   //00,0b // SetVCM[5:0] for VCOMH 
  116.     LCD_WrCmdDat(0x002B, 0x000e);  //00,00 // Set Frame Rate 
  117.       DelayMs(50);                              // Delay 50ms 
  118.     LCD_WrCmdDat(0x0020, 0x0000);   // GRAM horizontal Address 
  119.     LCD_WrCmdDat(0x0021, 0x0000);     // GRAM Vertical Address  
  120.   // ----------- Adjust the Gamma  Curve ----------// 
  121.     LCD_WrCmdDat(0x0030, 0x0007);   
  122.     LCD_WrCmdDat(0x0031, 0x0206);    
  123.     LCD_WrCmdDat(0x0032, 0x0506);   
  124.     LCD_WrCmdDat(0x0035, 0x0704); 
  125.   
  126.     LCD_WrCmdDat(0x0036, 0x1203); 
  127.   
  128.     LCD_WrCmdDat(0x0037, 0x0007); 
  129.   
  130.     LCD_WrCmdDat(0x0038, 0x0000); 
  131.   
  132.     LCD_WrCmdDat(0x0039, 0x0706); 
  133.   
  134.     LCD_WrCmdDat(0x003C, 0x0701); 
  135.    
  136.     LCD_WrCmdDat(0x003D, 0x000F); 
  137.  
  138.   //------------------ Set GRAM area ---------------// 
  139.     LCD_WrCmdDat(0x0050, 0x0000);    // Horizontal GRAM Start Address 
  140.     LCD_WrCmdDat(0x0051, 0x00EF);     // Horizontal GRAM End Address 
  141.     LCD_WrCmdDat(0x0052, 0x0000);    // Vertical GRAM Start Address 
  142.     LCD_WrCmdDat(0x0053, 0x013F);    // Vertical GRAM Start Address 
  143.     LCD_WrCmdDat(0x0060, 0xA700);    // Gate Scan Line 
  144.     LCD_WrCmdDat(0x0061, 0x0001);   // NDL,VLE, REV 
  145.     LCD_WrCmdDat(0x006A, 0x0000);    // set scrolling line 
  146.   //-------------- Panel Control -------------------// */
  147.     LCD_WrCmdDat(0x0090, 0x0010);  
  148.     LCD_WrCmdDat(0x0092, 0x0600);    
  149.     LCD_WrCmdDat(0x0093, 0x0003);  
  150.     LCD_WrCmdDat(0x0095, 0x0110); 
  151.     LCD_WrCmdDat(0x0097, 0x0000);   
  152.     LCD_WrCmdDat(0x0098, 0x0000);   
  153.  
  154.     LCD_WrCmdDat(0x0007, 0x0133);  // 262K color and display ON 
  155.     DelayMs(100);  
  156.     LCD_BLEN_1;
  157.     
  158.     PenColor=YELLOW;
  159.     BackColor=RED;
  160. }
  161. #endif
  162. /*==================================================================
  163. * Function : LCD_SetPoit
  164. * Description : 设置lcd memory point
  165. * Input Para : U8 StartX, U8 StartY
  166. * Output Para : void
  167. * Return Value: void
  168. ==================================================================*/
  169. #ifdef  ILI9325
  170. void LCD_SetGramPoit(U16 x,U16 y)
  171. {
  172.     LCD_WrCmdDat(0x0020,x);
  173.     LCD_WrCmdDat(0x0021,y);      
  174.     LCD_WrCmd(0x0022);               //设置地址后重新启动写RAM命令
  175. }
  176. #endif
  177. /*==================================================================
  178. * Function : lcd_set_write_area
  179. * Description : 设置lcd memory write的区域
  180. * Input Para : U8 StartX, U8 StartY,U8 EndX, U8 EndY
  181. * Output Para : void
  182. * Return Value: void
  183. ==================================================================*/
  184. #ifdef  ILI9325
  185. void LCD_SetWindows(U16 HSA, U16 VSA,U16 HEA, U16 VEA)
  186. {
  187.     LCD_WrCmdDat(0x0050,HSA);
  188.     LCD_WrCmdDat(0x0051,HEA);
  189.     LCD_WrCmdDat(0x0052,VSA);
  190.     LCD_WrCmdDat(0x0053,VEA);
  191.     
  192.     LCD_SetGramPoit(HSA,VSA); //根据扫描方式不同而不同
  193. }
  194. #endif
  195. /**************************************************************************************
  196. * 名    称: DispOneColor
  197. * 功    能: 使任意矩形显示某种颜色
  198. * 参    数: 颜色值:Color
  199. * 返 回 值: 无
  200. **************************************************************************************/
  201. void DispOneColor(U16 X,U16 Y,U16 W,U16 H,U16 Color)
  202. {
  203.    U16 i,j;
  204.    LCD_SetWindows(X, Y, W, H);
  205. for(i = Y; i <= H ; i++)
  206. {
  207. for(j = X; j <= W; j++)
  208. {
  209. LCD_WrDat(Color);
  210. }
  211. }
  212. }
  213. void LCD_Clear(void)
  214. {
  215.     DispOneColor(LCD_Sx, LCD_Sy, LCD_W, LCD_H,BackColor);
  216. }
  217. /*==================================================================
  218. * Function : lcd_display_full_screen_color
  219. * Description : 将全屏刷为某一颜色
  220. * Input Para : U16 val
  221. * Output Para : void
  222. * Return Value: void
  223. ==================================================================*/
  224. void Display_full_screen_color(U16 color)
  225. {
  226. U16 X, Y;
  227. LCD_SetWindows(LCD_Sx, LCD_Sy, LCD_Ex, LCD_Ey);
  228. LCD_SetGramPoit(LCD_Sx,LCD_Sy); //根据扫描方式不同而不同
  229. for(X = 0; X < LCD_W; X++)
  230. {
  231. for(Y = 0; Y < LCD_H; Y++)
  232. {
  233. LCD_WrDat(color);
  234. }
  235. }
  236. return;
  237. }
  238. /**************************************************************************************
  239. * 名    称: DrawSingleAscii
  240. * 功    能: 在指定的位置显示单个字符
  241. * 参    数: 坐标:x
  242. *           坐标:y
  243. *           字符的颜色:LineColor 
  244. *           字符背景颜色:FillColor   : 
  245. * 返 回 值: 无
  246. **************************************************************************************/
  247. void DrawSingleAscii(U16 x, U16 y, U8 *pHz, U16 LineColor,U16 FillColor, U8 Mod)
  248. {
  249. U16 j=0,i=0,k=0;
  250. U8 str;
  251. U16 len;
  252. //---------------------------查找该字是否已在字库中 
  253. len=sizeof(AsciiLib)/sizeof(AsciiLib[0]);
  254. for(j=0;j<sizeof(AsciiLib)/sizeof(AsciiLib[0]);j++)   
  255.     if((U8)AsciiLib[j].Index==pHz[0])break;
  256. //--------------------------      
  257.     if(j<len) //j<len,说明该字已经在汉字中出现
  258.     {
  259. LCD_SetWindows(x, y, x+7, y+15);
  260.         for (i=0;i<16;i++)
  261.         {
  262.             str = (U8)AsciiLib[j].Msk[i]; 
  263.             for (k=0;k<8;k++)
  264.             {
  265.                 if ( str & (0x80>>k) )     //通过移位逐位发送数据
  266. {
  267.                     LCD_WrDat((U16)(LineColor&0xffff));
  268. }
  269.                 else 
  270. {
  271. if (Mod == NORMAL)
  272.                          LCD_WrDat((U16)(FillColor&0xffff));
  273. }
  274. else
  275. {
  276.                       LCD_SetGramPoit(x+k+1,y+i); //跳过这一点,即保留该点原有的信息
  277. }
  278. }
  279.              }                            
  280.         }
  281.     }
  282. }
  283. /**************************************************************************************
  284. * 名    称: DrawSingleHz
  285. * 功    能: 在指定的位置显示汉字
  286. * 参    数: 坐标:x
  287. *           坐标:y
  288. *           字符的颜色:LineColor 
  289. *           字符背景颜色:FillColor 
  290. **************************************************************************************/
  291. void DrawSingleHz(U16 x, U16 y, U8 *pHz, U16 LineColor,U16 FillColor, U8 Mod)
  292. {
  293. U16 i=0,j=0,k=0;
  294. U16 str,len;
  295. //---------------------------查找该字是否已在字库中
  296. len=sizeof(HzLib)/sizeof(HzLib[0]);
  297. for(i=0;i<sizeof(HzLib)/sizeof(HzLib[0]);i++)   
  298.     if((U8)HzLib[i].Index[0]==pHz[0]&&(U8)HzLib[i].Index[1]==pHz[1])break;
  299. //--------------------------      
  300.     if(i<len) //j<len,说明该字已经在汉字中出现
  301.     {
  302. LCD_SetWindows(x, y, x+15, y+15);
  303.         for (j=0;j<16;j++)
  304.         {
  305.             str = (U8)HzLib[i].Msk[j*2]<<8|(U8)HzLib[i].Msk[j*2+1]; 
  306.             for (k=0;k<16;k++)
  307.             {
  308.                 if ( str & (0x8000>>k) )     //通过移位逐位发送数据
  309.                 {
  310.                     LCD_WrDat((U16)(LineColor&0xffff));
  311.                 }
  312.                 else
  313.                 {
  314.                     if (Mod == NORMAL)
  315. {
  316.                         LCD_WrDat((U16)(FillColor&0xffff));
  317. }
  318.                     else
  319.                     {
  320.                         LCD_SetGramPoit(x+k+1,y+j); //跳过这一点,即保留该点原有的信息
  321.                     }
  322.                 }               
  323.             } 
  324.         }
  325.     }
  326. }
  327. /**************************************************************************************
  328. * 名    称: DrawString
  329. * 功    能: 在指定的位置显示多个字符
  330. * 参    数: 坐标:x
  331. *           坐标:y
  332. *           字符的颜色:LineColor
  333. *           字符背景颜色:FillColor
  334. *
  335. * 返 回 值: 无
  336. *
  337. **************************************************************************************/
  338. void DrawString(U16 x, U16 y, U8 *pStr, U16 LineColor,U16 FillColor, U8 Mod)
  339. { //把字符串的第一个字符的地址赋给字符指针变量pstr,
  340. //不是*pStr="    "详见濉跺《C程序设计》-谭浩强P252
  341.     while(1)
  342.     {
  343.         if (*pStr == 0)
  344.         {
  345.             return;
  346.         }
  347.         if (*pStr > 0x80)           //大于0x80的为汉字
  348.         {
  349.             DrawSingleHz(x, y, pStr, LineColor, FillColor, Mod);   //调用显示单个汉字函数处理
  350.             x += 16;
  351.             pStr += 2;              
  352.         } //移动指针
  353.         else                        //英文字符
  354.         {
  355.             DrawSingleAscii(x, y, pStr, LineColor, FillColor, Mod);   //调用显示单个字符函数处理
  356.             x += 8;
  357.             pStr += 1;              //移动指针
  358.         }
  359.     }   
  360. }
  361. /**************************************************************************************
  362. * 名    称: DispNum
  363. * 功    能: 显示触摸屏点击处的坐标(用于调试用)
  364. * 参    数: 坐标竖直要显示的位置:x,y
  365. 要显示的坐标值
  366. 存放坐标值的数组名:str
  367. * 返 回 值: 无
  368. **************************************************************************************/
  369. void DispNum(U16 x, U16 y, U16 num,U16 LineColor,U16 FillColor, U8 Mod)
  370. {
  371.     uchar i;
  372.     uchar n[9];
  373.     n[0] =  num/10000000+0x30;
  374.     n[1] = (num%10000000)/1000000+0x30;
  375.     n[2] = (num%10000000)%1000000/100000+0x30;
  376.     n[3] = (num%10000000)%1000000%100000/10000+0x30;
  377.     n[4] = (num%10000000)%1000000%100000%10000/1000+0x30;
  378.     n[5] = (num%10000000)%1000000%100000%10000%1000/100+0x30;
  379.     n[6] = (num%10000000)%1000000%100000%10000%1000%100/10+0x30;
  380. n[7] = (num%10000000)%1000000%100000%10000%1000%100%10+0x30;
  381.     n[8] = '';
  382.    
  383.   for (i=0;i<sizeof(n);i++)
  384.     {  
  385.     if ((n[i]-0x30!=0)||(i==sizeof(n)-1)) //抑制前导0
  386.         {
  387.                 DrawString( x+Size_Asic_W/2*(i), y, n+i, LineColor, FillColor, Mod);
  388.                 return;
  389.         }
  390.     }
  391. }
  392. /**************************************************************************************
  393. * 名    称: DispSmallPic
  394. * 功    能: 在指定的位置显示一张65K色的图片
  395. * 参    数: 显示的起始坐标:x,y
  396. 图片的宽度和高度:w,h
  397. 图片数据的数组名:str
  398. * 返 回 值: 无
  399. **************************************************************************************/
  400. void DispSmallPic(U16 x, U16 y, U16 w, U16 h, const U8 *pPoint)
  401. {
  402.     U16 i,j;
  403.     for(j=0;j<h;j++)
  404.     {
  405.         LCD_SetGramPoit(x,y+j);
  406.         for(i=0;i<w;i++)   //图片数据存放的格式是高字节在前,低字节在后
  407.         {
  408.             LCD_WrDat8(*pPoint++);
  409. LCD_WrDat8(*pPoint++);
  410.         }
  411.     }
  412. }
  413. /**************************************************************************************
  414. * 名    称: disintlcd
  415. * 返 回 值: 无
  416. ***************************************************************************************/
  417. void disintlcd(void)
  418. {
  419.     U8 *pPoint ;
  420. pPoint =  gImage_head ;
  421.        
  422. DispSmallPic(0,0,240,70,pPoint);
  423. DispOneColor(0,70,239,93,RED)  ;   //biaoti
  424. DrawString(38, 74,"射 频 卡 缴 费 系 统",YELLOW, RED,  NORMAL);
  425. DispOneColor(0,94,239,319,GREEN) ;
  426.  pPoint = gImage_logotu ;
  427.  DispSmallPic(120,110,120,20,pPoint); 
  428.  DrawString(140, 134,"伟嵌科技",BLACK, GREEN,  NORMAL);
  429.  
  430.   
  431. pPoint =  gImage_ka ;
  432. DispSmallPic(15,180,50,50,pPoint);
  433.  pPoint = gImage_money ;
  434.  DispSmallPic(10,236,60,30,pPoint); 
  435.  
  436. DispOneColor(120,200,230,231,WHITE) ;//baibiao
  437. DispOneColor(120,236,230,267,WHITE) ;
  438. DrawString(80, 208,"卡号",BLACK, GREEN,  NORMAL);
  439. DrawString(80, 244,"余额",BLACK, GREEN,  NORMAL);
  440.   
  441.      
  442. }