找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 1569|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

8位數(shù)據(jù)顯示屏

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:145466 發(fā)表于 2016-11-1 08:07 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
  1. /**************************************************************************************
  2. * 名    稱:
  3. * 功    能:
  4. * 參    數(shù):
  5. * 返 回 值:
  6. *
  7. * 修改歷史:
  8. *   版本    日期     作者     
  9. *   ----------------------------------------------------
  10. *   1.0   
  11. **************************************************************************************/
  12. void send_command(unsigned int Cmd)
  13. {
  14.   CS=0;
  15.   RS=0;
  16.   num_out=Cmd;  RW=0;RW=1;
  17.   CS=1;
  18. }
  19. /**************************************************************************************
  20. * 名    稱:
  21. * 功    能:
  22. * 參    數(shù):
  23. * 返 回 值:
  24. *
  25. * 修改歷史:
  26. *   版本    日期     作者     
  27. *   ----------------------------------------------------
  28. *   1.0   
  29. **************************************************************************************/
  30. void send_byte(uchar Data)
  31. {
  32.   RS=1;
  33.   CS=0;  num_out=Data;  RW=0;RW=1;  CS=1;
  34. }
  35. /**************************************************************************************
  36. * 名    稱:
  37. * 功    能:
  38. * 參    數(shù):
  39. * 返 回 值:
  40. *
  41. * 修改歷史:
  42. *   版本    日期     作者     
  43. *   ----------------------------------------------------
  44. *   1.0   
  45. **************************************************************************************/
  46. void send_data(uint num)
  47. {
  48.   RS=1;
  49.   CS=0;  num_out=(num>>8);  RW=0;RW=1;  CS=1;
  50.   CS=0;  num_out=num;  RW=0;RW=1;  CS=1;
  51. }

  52. /**************************************************************************************
  53. * 名    稱:
  54. * 功    能:
  55. * 參    數(shù):
  56. * 返 回 值:
  57. *
  58. * 修改歷史:
  59. *   版本    日期     作者     
  60. *   ----------------------------------------------------
  61. *   1.0   
  62. **************************************************************************************/
  63. void write_com(unsigned int Cmd,unsigned int num)
  64. {
  65.   CS=0;
  66.   Rd=1;
  67.   RS=0;
  68.   num_out=Cmd;   RW=0;RW=1;
  69.   RS=1;
  70.   num_out=num;  RW=0;RW=1;
  71.   CS=1;
  72. }

  73. /**************************************************************************************
  74. * 名    稱:
  75. * 功    能:
  76. * 參    數(shù):
  77. * 返 回 值:
  78. *
  79. * 修改歷史:
  80. *   版本    日期     作者     
  81. *   ----------------------------------------------------
  82. *   1.0   
  83. **************************************************************************************/
  84. void lcd_init(void)
  85. {
  86.         CS=1;        RW=1;         Rd=1;        RS=1;
  87.         RST=0;         DelayNS( 1000 );RST=1;
  88.         send_command(0x11);         DelayNS( 1500 );
  89.                                                         // sleep out/power on(SLPOUT)
  90.         send_command(0x20);                // display inversion off
  91.         send_command(0x38);                // ID mode off (IDMOFF)
  92.         send_command(0x13);                // Normal display mode on (Partial mode off)
  93.                                                         // color mode Interface pixel format  (COLMOD)
  94.         write_com(0x3A,0x05);        // 16-bit/pixel , 1-times data transfer
  95.         write_com(0xC0,0x00);        // power control 1      (PWCTR1) , GVDD voltage set 4.65
  96.         write_com(0xC1,0x05);DelayNS( 1500 );        
  97.                                                         // VCOMH voltage set 4.10V
  98.         write_com(0xC5,0xc7);        //;c0h   VCOMH voltage set 4.175V
  99.         write_com(0xC6,0x07);DelayNS( 1500 );
  100.                                                         //;07       ;VCOMAC voltage set 4.8V ;
  101.                                                         // Gamma voltage adjustalbe level
  102.                                                         //Gamma + Polarity correction characteristics set
  103.         send_command(0xE0);

  104.         send_byte(0x21);
  105.         send_byte(0x11);  
  106.         send_byte(0x21);  
  107.         send_byte(0x22);  
  108.         send_byte(0x22);  
  109.         send_byte(0x33);  
  110.         send_byte(0x03);  

  111.         write_com(0x36,0x10);        // MY=1; MX=0; MV=0; ML=0; RGB=0
  112.         send_command(0x37);
  113.         send_byte(0x00);
  114.         send_byte(0x00);                // display on
  115.         send_command(0x29);
  116. }
  117. /**************************************************************************************
  118. * 名    稱:
  119. * 功    能:
  120. * 參    數(shù):
  121. * 返 回 值:
  122. *
  123. * 修改歷史:
  124. *   版本    日期     作者     
  125. *   ----------------------------------------------------
  126. *   1.0   
  127. **************************************************************************************/
  128. void LCD_SetArea( uchar x0, uchar y0, uchar x1, uchar y1 )
  129. {
  130.         send_command(0x2A);
  131.         send_byte(0x00);
  132.         send_byte(x0);
  133.         send_byte(0x00);
  134.         send_byte(x1);

  135.         send_command(0x2B);
  136.         send_byte(0x00);
  137.         send_byte(y0);
  138.         send_byte(0x00);
  139.         send_byte(y1);
  140. }
  141. /**************************************************************************************
  142. * 名    稱:
  143. * 功    能:
  144. * 參    數(shù):
  145. * 返 回 值:
  146. *
  147. * 修改歷史:
  148. *   版本    日期     作者     
  149. *   ----------------------------------------------------
  150. *   1.0   
  151. **************************************************************************************/
  152. void Set_ramaddr(uchar x,uchar y)
  153. {
  154.         send_command(0x2A);
  155.         send_byte(0x00);
  156.         send_byte(x);
  157.         send_byte(0x00);
  158.         send_byte(x);

  159.         send_command(0x2B);
  160.         send_byte(0x00);
  161.         send_byte(y);
  162.         send_byte(0x00);
  163.         send_byte(y);
  164. }
  165. /**************************************************************************************
  166. * 名    稱: DispOneColor
  167. * 功    能: 全屏顯示某種顏色
  168. * 參    數(shù): Color   : 顏色值
  169. * 返 回 值: 無(wú)
  170. *
  171. * 修改歷史:
  172. *   版本    日期     作者     
  173. *   ----------------------------------------------------
  174. *   1.0   
  175. **************************************************************************************/
  176. void DispOneColor(uint Color)
  177. {
  178.     uchar i,j;
  179.     LCD_SetArea(0,0,kuan-1,gao);
  180.     send_command(0x2C);
  181.     for(j=0;j<kuan;j++)
  182.         for(i=0;i<gao;i++)
  183.             send_data(Color);
  184. }
  185. /**************************************************************************************
  186. * 名    稱: DispClear
  187. * 功    能: 清除顯示屏的顯示內(nèi)容
  188. * 參    數(shù): 無(wú)
  189. * 返 回 值: 無(wú)
  190. *
  191. * 修改歷史:
  192. *   版本    日期     作者     
  193. *   ----------------------------------------------------
  194. *   1.0   
  195. **************************************************************************************/
  196. void DispClear(void)
  197. {
  198.     DispOneColor(BLACK);
  199. }
  200. /**************************************************************************************
  201. * 名    稱: DrawSingleAscii
  202. * 功    能: 在指定的位置單個(gè)字符
  203. * 參    數(shù): x           : x坐標(biāo)
  204. *                       y         : y坐標(biāo)
  205. *               LineColor : 字符的顏色
  206. *           FillColor   : 字符背景顏色
  207. * 返 回 值: 無(wú)
  208. *
  209. * 修改歷史:
  210. *   版本    日期     作者     
  211. *   ----------------------------------------------------
  212. *   1.0   
  213. **************************************************************************************/
  214. void DrawSingleAscii(uint x, uint y, uchar *pAscii, uint LineColor,uint FillColor, uchar Mod)
  215. {
  216.     uchar i, j;
  217.     uchar str;
  218.     uint OffSet;

  219.     OffSet = (*pAscii - 32)*16;
  220.     for (i=0;i<16;i++)
  221.     {
  222.         str = *(AsciiLib + OffSet + i);  
  223.         for (j=0;j<8;j++)
  224.         {
  225.             Set_ramaddr(x+j,y+i);
  226.                 send_command(0x2C);
  227.                         if ( str & (0x80>>j) )     //0x80>>j
  228.             {
  229.                 send_data((uint)(LineColor&0xffff));
  230.             }
  231.             else
  232.             {
  233.                 if (NORMAL == Mod)
  234.                     send_data((uint)(FillColor&0xffff));
  235.                 else
  236.                 {
  237.                     Set_ramaddr(x+j+1,y+i);
  238.                     send_command(0x2C);  
  239.                 }
  240.             }               
  241.         }
  242.     }
  243. }
  244. /**************************************************************************************
  245. * 名    稱: DrawSingleHz
  246. * 功    能: 在指定的位置顯示漢字
  247. * 參    數(shù): x           : x坐標(biāo)
  248. *                       y       : y坐標(biāo)
  249. *               LineColor : 漢字的顏色
  250. *           FillColor   : 漢字背景顏色
  251. * 返 回 值: 無(wú)
  252. *
  253. * 修改歷史:
  254. *   版本    日期     作者     
  255. *   ----------------------------------------------------
  256. *   1.0   
  257. **************************************************************************************/
  258. void DrawSingleHz(uint x, uint y, uchar *pHz, uint LineColor,uint FillColor, uchar Mod)
  259. {
  260. uint j=0,i=0,k=0;
  261. uint str,len;
  262. //---------------------------統(tǒng)計(jì)是否在字庫(kù)中出現(xiàn)
  263. len=sizeof(HzLib)/sizeof(HzLib[0]);
  264. for(j=0;j<sizeof(HzLib)/sizeof(HzLib[0]);j++)   
  265.     if((uchar)HzLib[j].Index[0]==pHz[0]&&(uchar)HzLib[j].Index[1]==pHz[1])break;
  266. //--------------------------      
  267.     if(j<len)
  268.     {
  269.                 for (i=0;i<HZ_column;i++)
  270.         {
  271.             str = (uchar)HzLib[j].Msk[i*2]<<8|(uchar)HzLib[j].Msk[i*2+1];

  272.             for (k=0;k<HZ_column;k++)
  273.             {
  274.                 Set_ramaddr(x+k,y+i);
  275.                     send_command(0x2C);               
  276.                                 if ( str & (0x8000>>k) )     //0x8000>>k
  277.                 {
  278.                                         send_data((uint)(LineColor&0xffff));
  279.                 }
  280.                 else
  281.                 {
  282.                     if (NORMAL == Mod)
  283.                         send_data((uint)(FillColor&0xffff));
  284.                     else
  285.                     {
  286.                         Set_ramaddr(x+k+1,y+i);
  287.                         send_command(0x2C);  
  288.                     }
  289.                 }               
  290.             }
  291.         }
  292.     }
  293. }

  294. /**************************************************************************************
  295. * 名    稱: DrawString
  296. * 功    能: 在指定的位置顯示多個(gè)字符
  297. * 參    數(shù): x           : x坐標(biāo)
  298. *                       y         : y坐標(biāo)
  299. *               LineColor : 字符的顏色
  300. *           FillColor   : 字符背景顏色
  301. * 返 回 值: 無(wú)
  302. *
  303. * 修改歷史:
  304. *   版本    日期     作者     
  305. *   ----------------------------------------------------
  306. *   1.0   
  307. **************************************************************************************/
  308. void DrawString(uint x, uint y, uchar *pStr, uint LineColor,uint FillColor, uchar Mod)
  309. {

  310.     while(1)
  311.     {
  312.         if (*pStr == 0)
  313.         {
  314.             return;
  315.         }

  316.         if (*pStr > 0x80)           //漢字
  317.         {
  318.             DrawSingleHz(x, y, pStr, LineColor, FillColor, Mod);
  319.             x += HZ_column;
  320.             pStr += 2;              
  321.         }
  322.         else                        //英文字符
  323.         {
  324.             DrawSingleAscii(x, y, pStr, LineColor, FillColor, Mod);
  325.             x += 8;
  326.             pStr += 1;              
  327.         }
  328.     }   
  329. }
  330. /**************************************************************************************
  331. * 名    稱:
  332. * 功    能:
  333. * 參    數(shù):
  334. * 返 回 值:
  335. *
  336. * 修改歷史:
  337. *   版本    日期     作者     
  338. *   ----------------------------------------------------
  339. *   1.0   
  340. **************************************************************************************/
  341. void DispNum(unsigned int x, unsigned int y, unsigned short num)
  342. {
  343.     unsigned char str[5];

  344.     str[0] = num/1000+0x30;
  345.     str[1] = (num%1000)/100+0x30;
  346.     str[2] = (num%1000)%100/10+0x30;
  347.     str[3] = (num%1000)%100%10+0x30;
  348.     str[4] = '\0';

  349.     DrawString(x, y, str, RED, YELLOW, NORMAL);                                                                                
  350. }                                                                                                                                                                        
  351. /**************************************************************************************
  352. * 名    稱: DispSmallPic
  353. * 功    能: 在指定的位置顯示一張65K色的圖片
  354. * 參    數(shù): str     : 圖片數(shù)組名
  355. * 返 回 值: 無(wú)
  356. *
  357. * 修改歷史:
  358. *   版本    日期     作者     
  359. *   ----------------------------------------------------
  360. *   1.0   
  361. **************************************************************************************/
  362. void DispSmallPic(uint x, uint y, uint w, uint h, const uchar *str)
  363. {
  364.     uint i,j,temp;
  365.         LCD_SetArea(x,y,x+w-1,y+h-1);
  366.         send_command(0x2C);
  367.         for(i=0;i<w*h;i++)
  368.         {   //send_data(*(unsigned short *)(&str[(j*w+i)*2]));       //高位在前
  369.             temp=str[(j*w+i)*2+1]<<8;     //低位在前
  370.             temp|=str[(j*w+i)*2];
  371.             send_data(temp);
  372.         }
  373. }                                                                                                                        


復(fù)制代碼

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表