|
实验器材: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);//密码错误,继续输入密码
- }
-
- //
-
- }
复制代码
|
|