久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2043|回復(fù): 1
收起左側(cè)

單片機(jī)+LCD12864屏畫點(diǎn)程序出現(xiàn)這種亂碼是啥情況?

[復(fù)制鏈接]
ID:466381 發(fā)表于 2021-4-20 19:00 | 顯示全部樓層 |閱讀模式
51hei圖片20210420185822.jpg
  1. #include "lcd12864.h"
  2. /**
  3. * @name:
  4. * @description:
  5. * @author: 何影萌
  6. * @version:
  7. * @return {*}
  8. * @param {int} ms
  9. */
  10. int delay(int ms)
  11. {
  12.   int lanzixuan;
  13.     while(ms--)
  14.   {
  15.       uint8_t i;
  16.     for(i=0;i<250;i++)  
  17.      {
  18.       _nop_();         
  19.     _nop_();
  20.     _nop_();
  21.     _nop_();
  22.      }
  23.   }
  24.   return lanzixuan;
  25. }   
  26. /*******************************************************************/
  27. /*                                                                 */
  28. /*檢查LCD忙狀態(tài)                                                    */
  29. /*lcd_busy為1時,忙,等待。lcd-busy為0時,閑,可寫指令與數(shù)據(jù)。      */
  30. /*                                                                 */
  31. /*******************************************************************/
  32. bit lcd_busy()
  33. {                          
  34.     bit result;
  35.     LCD_RS = 0;
  36.     LCD_RW = 1;
  37.     LCD_EN = 1;
  38.     delayNOP();
  39.     result = (bit)(P0&0x80);
  40.     LCD_EN = 0;
  41.     return(result);
  42. }
  43. /*******************************************************************/
  44. /*                                                                 */
  45. /*寫指令數(shù)據(jù)到LCD                                                  */
  46. /*RS=L,RW=L,E=高脈沖,D0-D7=指令碼。                             */
  47. /*                                                                 */
  48. /*******************************************************************/
  49. void lcd_wcmd(uint8_t cmd)
  50. {                          
  51.    while(lcd_busy());
  52.     LCD_RS = 0;
  53.     LCD_RW = 0;
  54.     LCD_EN = 0;
  55.     _nop_();
  56.     _nop_();
  57.     P0 = cmd;
  58.     delayNOP();
  59.     LCD_EN = 1;
  60.     delayNOP();
  61.     LCD_EN = 0;  
  62. }
  63. /*******************************************************************/
  64. /*                                                                 */
  65. /*寫顯示數(shù)據(jù)到LCD                                                  */
  66. /*RS=H,RW=L,E=高脈沖,D0-D7=數(shù)據(jù)。                               */
  67. /*                                                                 */
  68. /*******************************************************************/
  69. void lcd_wdat(uint8_t dat)
  70. {                          
  71.    while(lcd_busy());
  72.     LCD_RS = 1;
  73.     LCD_RW = 0;
  74.     LCD_EN = 0;
  75.     P0 = dat;
  76.     delayNOP();
  77.     LCD_EN = 1;
  78.     delayNOP();
  79.     LCD_EN = 0;
  80. }
  81. /*******************************************************************/
  82. /*                                                                 */
  83. /*寫字符串到LCD                                                  */
  84. /*RS=H,RW=L,E=高脈沖,D0-D7=數(shù)據(jù)。                               */
  85. /*                                                                 */
  86. /*******************************************************************/
  87. void lcd_wstr(uint8_t *Str)
  88. {
  89.   while(*Str)
  90.   {
  91.     lcd_wdat(*Str++);
  92.   }
  93. }

  94. /*******************************************
  95. 函數(shù)名稱:Draw_PM
  96. 功    能:在整個液晶屏幕上畫圖
  97. 參    數(shù):無
  98. 返回值  :無
  99. ********************************************/
  100. void Draw_PM(const uint8_t *ptr)
  101. {
  102.   uint8_t i,j,k;
  103.   lcd_wcmd(0x34);        //打開擴(kuò)展指令集
  104.   i = 0x80;            
  105.   for(j = 0;j < 32;j++)
  106.   {
  107.         lcd_wcmd(i++);
  108.         lcd_wcmd(0x80);
  109.       for(k = 0;k < 16;k++)
  110.       {
  111.           lcd_wdat(*ptr++);
  112.       }
  113.   }
  114.   i = 0x80;
  115.   for(j = 0;j < 32;j++)
  116.   {
  117.       lcd_wcmd(i++);
  118.         lcd_wcmd(0x88);   
  119.       for(k = 0;k < 16;k++)
  120.       {
  121.           lcd_wdat(*ptr++);
  122.       }
  123.   }  
  124.     lcd_wcmd(0x36);        //打開繪圖顯示
  125.     lcd_wcmd(0x30);        //回到基本指令集
  126. }

  127. /*******************************************************************/
  128. /*                                                                 */
  129. /*  LCD初始化設(shè)定                                                  */
  130. /*                                                                 */
  131. /*******************************************************************/
  132. void lcd_init()
  133. {
  134.     delay(50);
  135.     wela=0;
  136.     dula=0;
  137.     LCD_PSB = 1;         //并口方式

  138.     lcd_wcmd(0x34);      //擴(kuò)充指令操作
  139.     delay(5);
  140.     lcd_wcmd(0x30);      //基本指令操作
  141.     delay(5);
  142.     lcd_wcmd(0x0C);      //顯示開,關(guān)光標(biāo)
  143.     delay(5);
  144.     lcd_wcmd(0x01);      //清除LCD的顯示內(nèi)容
  145.     delay(5);
  146. }

  147. /*********************************************************/
  148. /*                                                       */
  149. /* 設(shè)定顯示位置                                          */
  150. /*                                                       */
  151. /*********************************************************/

  152. void lcd_pos(uint8_t X,uint8_t Y)
  153. {                          
  154.    uint8_t  pos;
  155.    if (X==0)
  156.      {X=0x80;}
  157.    else if (X==1)
  158.      {X=0x90;}
  159.    else if (X==2)
  160.      {X=0x88;}
  161.    else if (X==3)
  162.      {X=0x98;}
  163.    pos = X+Y ;  
  164.    lcd_wcmd(pos);     //顯示地址
  165. }
  166. /**
  167. * @name:
  168. * @description: 以下為藍(lán)靈電子新增加的功能
  169. * @author: 何影萌
  170. * @version:
  171. * @return {*}
  172. */
  173. /**
  174. * @brief 讀取數(shù)據(jù)
  175. * @return uint8_t
  176. */

  177. uint8_t Lanling_Read_Dat()
  178. {
  179.   uint8_t datas;
  180.   while(lcd_busy());
  181.   LCD_RS=1;
  182.   LCD_RW=1;
  183.   LCD_EN=1;
  184.   delayNOP();
  185.   datas=P0;
  186.   delayNOP();
  187.   LCD_EN=0;
  188.   return datas;
  189. }
  190. /**
  191. * @brief 畫點(diǎn)
  192. * @param x
  193. * @param y
  194. */
  195. void Lanling_Draw_Point(uint8_t x,uint8_t y)
  196. {
  197.   uint8_t temph,templ;
  198.   uint8_t x_byte,x_bit;
  199.   uint8_t y_byte,y_bit;
  200.   lcd_wcmd(0x34);
  201.   lcd_wcmd(0x36);
  202.   x_byte=x>>4;
  203.   x_bit=x&0x0f;
  204.   y_byte=y>>5;
  205.   y_bit=y%32;
  206.   lcd_wcmd(0x80+y_bit);
  207.   lcd_wcmd(0x80+x_byte+y_byte*8);
  208.   temph=Lanling_Read_Dat();
  209.   temph=Lanling_Read_Dat();
  210.   templ=Lanling_Read_Dat();
  211.   lcd_wcmd(0x80+y_bit);
  212.   lcd_wcmd(0x80+x_byte+y_byte*8);
  213.   if(x_bit<8)
  214.   {
  215.     lcd_wdat(temph|(0x01<<(7-x_bit)));
  216.     lcd_wdat(templ);
  217.   }
  218.   else
  219.   {
  220.     lcd_wdat(temph);
  221.     lcd_wdat(templ|(0x01<<(15-x_bit)));   
  222.   }  

  223. }
  224. /**
  225. * @brief 清除點(diǎn)
  226. * @param x
  227. * @param y
  228. */
  229. void Lanling_Clear_Point(uint8_t x,uint8_t y)
  230. {
  231.   uint8_t temph,templ;
  232.   uint8_t x_byte,x_bit;
  233.   uint8_t y_byte,y_bit;
  234.   lcd_wcmd(0x34);
  235.   lcd_wcmd(0x36);
  236.   x_byte=x>>4;
  237.   x_bit=x&0x0f;
  238.   y_byte=y/32;
  239.   y_bit=y%32;
  240.   lcd_wcmd(0x80+y_bit);
  241.   lcd_wcmd(0x80+x_byte+y_byte*8);
  242.   temph=Lanling_Read_Dat();
  243.   temph=Lanling_Read_Dat();
  244.   templ=Lanling_Read_Dat();
  245.   lcd_wcmd(0x80+y_bit);
  246.   lcd_wcmd(0x80+x_byte+y_byte*8);
  247.   if(x_bit<8)
  248.   {
  249.     lcd_wdat(temph&(~(0x01<<(7-x_bit))));
  250.     lcd_wdat(templ);
  251.   }
  252.   else
  253.   {
  254.     lcd_wdat(temph);
  255.     lcd_wdat(templ&(~(0x01<<(15-x_bit))));   
  256.   }  
  257. }
  258. /**
  259. * @brief 藍(lán)靈電子專屬清屏函數(shù)
  260. */
  261. void Lanling_Clr()
  262. {
  263.   uint8_t i,j,k;
  264.   lcd_wcmd(0x34);
  265.   lcd_wcmd(0x36);
  266.   for(i=0;i<2;i++)
  267.   {
  268.     for(j=0;j<32;j++)
  269.     {
  270.       lcd_wcmd(0x80+j);
  271.       lcd_wcmd(0x80+i*8);
  272.       for(k=0;k<16;k++)
  273.       {
  274.         lcd_wdat(0x00);
  275.       }
  276.     }
  277.   }
  278.   lcd_wcmd(0x30);      //基本指令操作
  279. }


  280. /*Main.c*/
  281. void main()
  282. {
  283.     unsigned char i;
  284.     lcd_init();  
  285.     Lanling_Clr();
  286.     for(i=0;i<64;i++)
  287.     {
  288.         Lanling_Draw_Point(i,i);
  289.     }
  290.     for(i=64;i<128;i++)
  291.     {
  292.         Lanling_Draw_Point(i,127-i);
  293.     }
  294.     while(1);
  295. }
復(fù)制代碼


回復(fù)

使用道具 舉報(bào)

ID:584814 發(fā)表于 2021-4-21 10:29 | 顯示全部樓層
1、程序有問題
2、液晶屏壞了
沒有第3
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 小视频你懂得 | 人干人人| 亚洲欧美日韩久久 | 综合天天久久 | 亚洲高清在线观看 | 日韩在线视频一区 | 久久国产精品色av免费观看 | 在线免费毛片 | 日韩一区二区福利视频 | 欧美二区在线 | 国产成人免费网站 | 国产精品久久久久久238 | 亚洲美女网站 | 欧美 日韩 中文 | 亚洲第一av网站 | 精品久久久久国产免费第一页 | 夜夜爽99久久国产综合精品女不卡 | 日韩欧美在线精品 | 日韩中文字幕在线观看 | 国产免费一区 | 日韩欧美在线一区 | 91精品国产91久久久久久最新 | 欧美日韩精品免费 | 久久激情五月丁香伊人 | 国产一区二区三区 | 黄色日本片 | 亚洲精品乱码久久久久v最新版 | 中文字幕不卡在线观看 | 99爱国产| 亚洲精品一 | 亚洲欧美日韩中文在线 | 欧美综合一区二区 | 在线视频一区二区三区 | 日本韩国电影免费观看 | 日韩欧美三区 | 亚洲第一在线 | 久久久久久av | 欧美舔穴| 久久香蕉精品视频 | 国产一区二区在线免费观看 | 久久久久国|