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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3246|回復: 2
打印 上一主題 下一主題
收起左側

單片機+lcd12864清屏顯示出錯?

[復制鏈接]
跳轉到指定樓層
樓主
實驗器材:51單片機(實際用的是stc12,51單片機出問題了)、lcd12864夜晶帶中文字庫、4x4矩陣鍵盤、蜂鳴器、led(后面兩個器材有問題,可忽略)


問題:昨天研究到深夜lcd顯示技術,遇到顯示后清屏不起作用,前后的數據來回顯示。求走過路過的大佬指教指教小弟,留下大佬光輝的足跡
代碼奉上:
lcd12864.h

  1. #ifndef __LCD12864_H
  2. #define __LCD12864_H
  3. #include<stc15.h>
  4. #define xchar unsigned char code
  5. #define uchar unsigned char

  6. #endif

  7. #ifndef uint
  8. #define uint unsigned int
  9. #endif
  10. #define LCD12864_DATAPORT P2

  11. sbit LCD12864_RS  =  P0^7;
  12. sbit LCD12864_RW  =  P0^6;
  13. sbit LCD12864_EN  =  P0^5;
  14. sbit LCD12864_PSB =  P0^4;
  15. sbit LCD12864_RST =  P0^3;
  16. void LCD12864_Delay1ms(uint c);
  17. uchar LCD12864_Busy();
  18. void LCD12864_WriteCmd(uchar cmd);
  19. void LCD12864_WriteData(uchar dat);
  20. void LCD12864_Init();
  21. void LCD12864_ClearScreen(void);
  22. void LCD12864_SetWindow(uchar x, uchar y);
  23. void LCD12864_Delay1ms(uint c)
  24. {
  25.     uchar a,b;
  26.         for(; c>0; c--)
  27.         {
  28.             for(b=199; b>0; b--)
  29.                 {
  30.                 for(a=1; a>0; a--);
  31.                 }
  32.         }
  33. }
  34. uchar LCD12864_Busy(void)
  35. {
  36.         uchar i = 0;
  37.         LCD12864_RS = 0;
  38.         LCD12864_RW = 1;
  39.         LCD12864_EN = 1;
  40.         LCD12864_Delay1ms(1);
  41.         while((LCD12864_DATAPORT & 0x80) == 0x80)
  42.         {
  43.                 i++;
  44.                 if(i > 100)
  45.                 {
  46.                         LCD12864_EN = 0;
  47.                         return 0;
  48.                 }
  49.         }
  50.         LCD12864_EN = 0;
  51.         return 1;
  52. }
  53. void LCD12864_WriteCmd(uchar cmd)
  54. {
  55.         uchar i;
  56.         i = 0;
  57.         while( LCD12864_Busy() == 0)
  58.         {
  59.                 LCD12864_Delay1ms(1);
  60.                 i++;
  61.                 if( i>100)
  62.                 {
  63.                         return;
  64.                 }        
  65.         }
  66.         LCD12864_RS = 0;
  67.         LCD12864_RW = 0;
  68.         LCD12864_EN = 0;
  69.         LCD12864_DATAPORT = cmd;
  70.         LCD12864_EN = 1;
  71.         LCD12864_Delay1ms(5);
  72.         LCD12864_EN = 0;                                            
  73. }
  74. void LCD12864_WriteData(uchar dat)
  75. {
  76.         uchar i;
  77.         i = 0;
  78.         while( LCD12864_Busy() == 0)
  79.         {
  80.                 LCD12864_Delay1ms(1);
  81.                 i++;
  82.                 if( i>100)
  83.                 {
  84.                         return;
  85.                 }        
  86.         }
  87.         LCD12864_RS = 1;
  88.         LCD12864_RW = 0;
  89.         LCD12864_EN = 0;
  90.         LCD12864_DATAPORT = dat;
  91.         LCD12864_EN = 1;
  92.         LCD12864_Delay1ms(5);
  93.         LCD12864_EN = 0;                                                                    
  94. }
  95. #ifdef LCD12864_PICTURE
  96. uchar LCD12864_ReadData(void)
  97. {
  98.         uchar i, readValue;
  99.         i = 0;
  100.         while( LCD12864_Busy() == 0)
  101.         {
  102.                 LCD12864_Delay1ms(1);
  103.                 i++;
  104.                 if( i>100)
  105.                 {
  106.                         return 0;
  107.                 }        
  108.         }
  109.         LCD12864_RS = 1;
  110.         LCD12864_RW = 1;
  111.         LCD12864_EN = 0;
  112.         LCD12864_Delay1ms(1);
  113.         LCD12864_EN = 1;
  114.         LCD12864_Delay1ms(1);
  115.         readValue = LCD12864_DATAPORT;
  116.         LCD12864_EN = 0;
  117.         return readValue;
  118. }
  119. #endif
  120. void LCD12864_Init()
  121. {
  122.         LCD12864_PSB = 1;
  123.         LCD12864_RST = 1;
  124.         LCD12864_WriteCmd(0x30);
  125.         LCD12864_WriteCmd(0x0c);
  126.         LCD12864_WriteCmd(0x01);
  127. }
  128. #ifdef LCD12864_PICTURE
  129. void LCD12864_ClearScreen(void)
  130. {
  131.         uchar i,j;
  132.         LCD12864_WriteCmd(0x34);
  133.         for(i=0;i<32;i++)
  134.         {
  135.                 LCD12864_WriteCmd(0x80+i);
  136.                 LCD12864_WriteCmd(0x80);
  137.                 for(j=0;j<32;j++)
  138.                 {
  139.                         LCD12864_WriteData(0x01);        
  140.                 }
  141.         }
  142.         LCD12864_WriteCmd(0x36);
  143.         LCD12864_WriteCmd(0x30);
  144.         
  145.         
  146.         
  147. }
  148. #endif
  149. void LCD12864_SetWindow(uchar x, uchar y)
  150. {
  151.         uchar pos;
  152.         if(x == 0)
  153.         {
  154.                 x = 0x80;
  155.         }
  156.         else if(x == 1)
  157.         {
  158.                 x = 0x90;        
  159.         }
  160.         else if(x == 2)
  161.         {
  162.                 x = 0x88;
  163.         }
  164.         else if(x == 3)
  165.         {
  166.                 x = 0x98;
  167.         }
  168.         pos = x + y;
  169.         LCD12864_WriteCmd(pos);
  170. }
復制代碼





main.c



  1. #include<STC15.H>
  2. #include"lcd12864.h"
  3. #include<string.h>
  4. #include<intrins.h>
  5. #include<math.h>
  6. uchar hang;
  7. #define KeyBus P1
  8. sbit fengmingqi=P0^0;
  9. sbit led=P3^0;
  10. xchar mimacuowu[]={"密碼錯誤"};
  11. xchar mimazhengque[]={"密碼正確"};
  12. xchar CorpInf1[]={"請設置密碼:"};
  13. xchar CorpInf2[]={"請輸入密碼:"};
  14. xchar CorpInf[]={        
  15.         "lcd12864清屏前后的shuju"
  16. };

  17. unsigned char keyscan(void)
  18. {
  19.     unsigned char temH, temL, key;
  20.     KeyBus = 0x0f;                 
  21.         if(KeyBus!=0x0f)
  22.         {        
  23.                 temL = KeyBus;
  24.             KeyBus = 0xf0;
  25.                 _nop_();_nop_();_nop_();_nop_();
  26.                 temH = KeyBus;        
  27.             switch(temL)
  28.                 {
  29.                         case 0x0e: key = 1; break;
  30.                         case 0x0d: key = 2; break;
  31.                         case 0x0b: key = 3; break;
  32.                         case 0x07: key = 4; break;
  33.                         default: return 0;
  34.             }
  35.             switch(temH)
  36.                 {
  37.                         case 0xe0: return key;break;
  38.                         case 0xd0: return key + 4;break;
  39.                         case 0xb0: return key + 8;break;
  40.                         case 0x70: return key + 12;break;
  41.                         default: return 0;
  42.                 }
  43.         }return 0;
  44. }
  45. void gpio()
  46. {
  47.         P0M1=0;P0M0=0;
  48.         P1M1=0;P1M0=0;
  49.         P2M1=0;P2M0=0;
  50.         P3M1=0;P3M0=0;
  51.         P4M1=0;P4M0=0;
  52.         P5M1=0;P5M0=0;
  53.         P6M1=0;P6M0=0;
  54.         P7M1=0;P7M0=0;
  55. }

  56. void lcd(xchar *CorpInf,uchar n)
  57. {
  58.         unsigned char i=0,m=0;
  59.         switch(n)
  60.         {
  61.                 case 0:LCD12864_SetWindow(0, 0);m=0;break;
  62.                 case 1:LCD12864_SetWindow(1, 0);m=1;break;
  63.                 case 2:LCD12864_SetWindow(2, 0);m=2;break;
  64.                 case 3:LCD12864_SetWindow(3, 0);m=3;break;
  65.         }
  66.         
  67.         while(CorpInf[i]!='\0')
  68.         {               
  69.                 LCD12864_WriteData(CorpInf[i]);
  70.                 i++;
  71.                 switch(m)
  72.                 {
  73.                         case 0:if(i==16){LCD12864_SetWindow(1,0);}if(i==32){LCD12864_SetWindow(2,0);}if(i==48){LCD12864_SetWindow(3,0);}break;
  74.                         case 1:if(i==16)LCD12864_SetWindow(2,0);if(i==32)LCD12864_SetWindow(3,0);break;
  75.                         case 2:if(i==16)LCD12864_SetWindow(3,0);break;
  76.                         default:break;
  77.                 }
  78.         }
  79. }
  80. int mima_shuru()
  81. {
  82.         uint i,ws,shuju=0;uchar string[]={0,0,0,0,0,0,0,0,0,0,0,0,0};//鍵盤值,位數,輸入的數據,寫入的數據
  83.         for(ws=0;ws<13;ws++)
  84.         {
  85.                 i=keyscan();
  86.                 while(i==0);                                                                //等待鍵盤輸入
  87.                 led=0;fengmingqi=1;
  88.                 i-=1;
  89.                 if(i==10)break;                                                                                        //10為確定
  90.                 if(i>10)
  91.                 {
  92.                         ws--;continue;                                                                                //大于10為無效鍵
  93.                 }
  94.                 string[ws]=i*pow(10,ws);                                                //進行10次冪寫入數據
  95.         }
  96.         for(;ws>=0;ws--)
  97.         {
  98.                 shuju=shuju+string[ws];                                                        //計算出每次寫入的數據之和
  99.         }return shuju;                                                                                                //返回輸入的數據
  100. }

  101. void main()
  102. {
  103.         uint xh=1,yzm,mima;                                                                                //對錯是否循環,驗證碼(測試的密碼),設定的密碼
  104.         gpio();                                                                                                                                //I/O初始化
  105. //        LCD12864_Init();                                                                                        //lcd初始化
  106. //        lcd(CorpInf,0);                                                                                                //lcd顯示屏初始界面
  107. //        LCD12864_Delay1ms(5000);
  108. //        
  109. //        //LCD12864_Init();
  110. //        //LCD12864_ClearScreen();
  111. //        LCD12864_WriteData(0x01);
  112. //        LCD12864_Delay1ms(5);
  113. //        
  114. //        
  115. //        
  116. //        //LCD12864_Delay1ms(5000);                                                                //延時顯示5s
  117. //        
  118. //        //LCD12864_ClearScreen();
  119. //        
  120. //        lcd(CorpInf1,0);
  121. //        LCD12864_Delay1ms(5000);
  122.                                                                                 //設置密碼
  123.         while(xh)
  124.         {
  125.                 mima=mima_shuru();
  126.                 lcd(CorpInf2,0);
  127.                 yzm=mima_shuru();                                                                                //測試的密碼
  128.                 if(yzm==mima)
  129.                 {
  130.                         lcd(mimazhengque,2);//密碼正確,退出循環
  131.                         xh=2;
  132.                 }else lcd(mimacuowu,3);//密碼錯誤,繼續輸入密碼
  133.         }
  134.         
  135.         //
  136.                

  137. }
復制代碼

IMG_20191212_003029.gif (2.37 MB, 下載次數: 51)

IMG_20191212_003029.gif
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:646787 發表于 2019-12-12 11:45 | 只看該作者
LCD12864_Init()函數的注釋忘取消了
回復

使用道具 舉報

板凳
ID:646787 發表于 2019-12-12 12:13 | 只看該作者
問題已解覺,是我自己的問題,清屏代碼復制成寫數據【哭笑】,好像還沒審核過,算了當作回憶留在那

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 回帖助人的獎勵!

查看全部評分

回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 日韩精品视频一区二区三区 | 正在播放国产精品 | 亚洲精品综合 | 欧美一级欧美三级在线观看 | 婷婷久久网 | 99久久中文字幕三级久久日本 | 中文字幕av免费 | 性精品 | 91影院在线观看 | www.嫩草| 日日摸天天添天天添破 | 亚洲不卡在线观看 | 欧美精品成人一区二区三区四区 | 日韩有码一区 | 国产高清视频一区 | 日韩欧美视频在线 | 久久精品免费 | 99精品99 | 午夜欧美一区二区三区在线播放 | 免费一区| 国产欧美一区二区三区日本久久久 | 中文字幕亚洲精品 | 国产一级片网站 | 天天爽一爽| aaa天堂 | 久久综合久色欧美综合狠狠 | 狠狠躁躁夜夜躁波多野结依 | av一区二区三区四区 | 午夜av电影 | 青青草精品视频 | 亚洲一区视频在线 | 一区二区三区四区在线视频 | 久久久久中文字幕 | 亚洲美女一区二区三区 | 久久久精品一区 | 国产精品久久二区 | 久在草 | 国产午夜三级一区二区三 | 高清黄色毛片 | 国产精品久久久久久久岛一牛影视 | 欧美不卡网站 |