|
實驗器材:51單片機(實際用的是stc12,51單片機出問題了 )、lcd12864夜晶帶中文字庫、4x4矩陣鍵盤、蜂鳴器、led(后面兩個器材有問題,可忽略)
問題:昨天研究到深夜lcd顯示技術,遇到顯示后清屏不起作用,前后的數據來回顯示。求走過路過的大佬指教指教小弟 ,留下大佬光輝的足跡
代碼奉上:
lcd12864.h
main.c
- #include<STC15.H>
- #include"lcd12864.h"
- #include<string.h>
- #include<intrins.h>
- #include<math.h>
- uchar hang;
- #define KeyBus P1
- sbit fengmingqi=P0^0;
- sbit led=P3^0;
- xchar mimacuowu[]={"密碼錯誤"};
- xchar mimazhengque[]={"密碼正確"};
- xchar CorpInf1[]={"請設置密碼:"};
- xchar CorpInf2[]={"請輸入密碼:"};
- xchar CorpInf[]={
- "lcd12864清屏前后的shuju"
- };
- unsigned char keyscan(void)
- {
- unsigned char temH, temL, key;
- KeyBus = 0x0f;
- if(KeyBus!=0x0f)
- {
- temL = KeyBus;
- KeyBus = 0xf0;
- _nop_();_nop_();_nop_();_nop_();
- temH = KeyBus;
- switch(temL)
- {
- case 0x0e: key = 1; break;
- case 0x0d: key = 2; break;
- case 0x0b: key = 3; break;
- case 0x07: key = 4; break;
- default: return 0;
- }
- switch(temH)
- {
- case 0xe0: return key;break;
- case 0xd0: return key + 4;break;
- case 0xb0: return key + 8;break;
- case 0x70: return key + 12;break;
- default: return 0;
- }
- }return 0;
- }
- void gpio()
- {
- P0M1=0;P0M0=0;
- P1M1=0;P1M0=0;
- P2M1=0;P2M0=0;
- P3M1=0;P3M0=0;
- P4M1=0;P4M0=0;
- P5M1=0;P5M0=0;
- P6M1=0;P6M0=0;
- P7M1=0;P7M0=0;
- }
- void lcd(xchar *CorpInf,uchar n)
- {
- unsigned char i=0,m=0;
- switch(n)
- {
- case 0:LCD12864_SetWindow(0, 0);m=0;break;
- case 1:LCD12864_SetWindow(1, 0);m=1;break;
- case 2:LCD12864_SetWindow(2, 0);m=2;break;
- case 3:LCD12864_SetWindow(3, 0);m=3;break;
- }
-
- while(CorpInf[i]!='\0')
- {
- LCD12864_WriteData(CorpInf[i]);
- i++;
- switch(m)
- {
- case 0:if(i==16){LCD12864_SetWindow(1,0);}if(i==32){LCD12864_SetWindow(2,0);}if(i==48){LCD12864_SetWindow(3,0);}break;
- case 1:if(i==16)LCD12864_SetWindow(2,0);if(i==32)LCD12864_SetWindow(3,0);break;
- case 2:if(i==16)LCD12864_SetWindow(3,0);break;
- default:break;
- }
- }
- }
- int mima_shuru()
- {
- uint i,ws,shuju=0;uchar string[]={0,0,0,0,0,0,0,0,0,0,0,0,0};//鍵盤值,位數,輸入的數據,寫入的數據
- for(ws=0;ws<13;ws++)
- {
- i=keyscan();
- while(i==0); //等待鍵盤輸入
- led=0;fengmingqi=1;
- i-=1;
- if(i==10)break; //10為確定
- if(i>10)
- {
- ws--;continue; //大于10為無效鍵
- }
- string[ws]=i*pow(10,ws); //進行10次冪寫入數據
- }
- for(;ws>=0;ws--)
- {
- shuju=shuju+string[ws]; //計算出每次寫入的數據之和
- }return shuju; //返回輸入的數據
- }
- void main()
- {
- uint xh=1,yzm,mima; //對錯是否循環,驗證碼(測試的密碼),設定的密碼
- gpio(); //I/O初始化
- // LCD12864_Init(); //lcd初始化
- // lcd(CorpInf,0); //lcd顯示屏初始界面
- // LCD12864_Delay1ms(5000);
- //
- // //LCD12864_Init();
- // //LCD12864_ClearScreen();
- // LCD12864_WriteData(0x01);
- // LCD12864_Delay1ms(5);
- //
- //
- //
- // //LCD12864_Delay1ms(5000); //延時顯示5s
- //
- // //LCD12864_ClearScreen();
- //
- // lcd(CorpInf1,0);
- // LCD12864_Delay1ms(5000);
- //設置密碼
- while(xh)
- {
- mima=mima_shuru();
- lcd(CorpInf2,0);
- yzm=mima_shuru(); //測試的密碼
- if(yzm==mima)
- {
- lcd(mimazhengque,2);//密碼正確,退出循環
- xh=2;
- }else lcd(mimacuowu,3);//密碼錯誤,繼續輸入密碼
- }
-
- //
-
- }
復制代碼
|
|