{
uchar com[2] = {lcdcom_w,lcddata_w};
CS = 1;
LCD_Read_busy();
LCD_SendByte(com[k]);
LCD_SendByte(0xf0 & value); value = value << 4;
LCD_SendByte(0xf0 & value); CS = 0; }
void INIT_LCD() {
Delayms(30);
LCD_Write(0, 0x30);Delayms(1); LCD_Write(0, 0x0c);Delayms(1); LCD_Write(0, 0x01);Delayms(1); LCD_Write(0, 0x06);Delayms(1); LCD_Write(0, 0x80);Delayms(1); }
void LCD_Clear() {
LCD_Write(0, 0x01); }
void LCD_Write_x_y(uchar x, uchar y) {
LCD_Write(0, addr_tab[8*y + x]); }
void LCD_Write_str(uchar x, uchar y, uchar *value) {
LCD_Write(0, addr_tab[8*y + x]); while(*value > 0) { LCD_Write(1, *value); value++; } }
void LCD_Write_Num(uchar x, uchar y, uchar Value) {
LCD_Write(0, addr_tab[8*y + x]); LCD_Write(1, Value); }
void LCD_Write_Hanzi(uchar x, uchar y, uchar *Value) {
28
}
LCD_Write(0, addr_tab[8*y + x]); while(*Value > 0) { LCD_Write(1, *Value); Value++; }
7.5 主程序
#include \
sbit beer = P0^4;
uchar KEY_main = 255; uchar minma[8] ={0}; uchar anma[8] ={0}; bit OPEN = 0;
void main_key();
uchar MIMA_shuru(); void MIMA_change();
void MIMA_zhuanhuan(uchar *minma, uchar *anma); uchar MIMA_bidui(uchar *minma, uchar *anma); void MIMA_save(); void show_menu();
void show_huanyingjiemian(); void SYS_init();
void INTERRUPT_ON(); void INTERRUPT_OFF();
void main() {
SYS_init(); show_menu(); while(1) { main_key(); } }
void main_key() {
if(KEY_main != 255) {
29
if(OPEN == 0) { switch(KEY_main) { case 1://开锁 { KEY_main=255; INTERRUPT_OFF(); 中的进行对比
动作
错误
LCD_Clear(); LCD_Write_Hanzi(0, 0, \请输入密码: \显示开锁界面 INTERRUPT_ON(); if(MIMA_shuru()) { if(MIMA_bidui(minma, anma))//转换为暗码与存储器 { INTERRUPT_OFF(); LCD_Clear(); OPEN = 1; LCD_Write_Hanzi(0, 0, \锁已打开!\执行开锁 Delayms(800); INTERRUPT_ON(); show_huanyingjiemian(); } else { INTERRUPT_OFF(); LCD_Clear(); LCD_Write_Hanzi(0, 0, \输入错误!\提示输入 Delayms(800); INTERRUPT_ON(); show_menu(); } break; } else break; } case 2://修改密码 { KEY_main=255;
30
INTERRUPT_OFF(); LCD_Clear(); LCD_Write_Hanzi(0, 0, \请输入旧密码:\显示修改密码界面
INTERRUPT_ON(); if(MIMA_shuru()) { if(MIMA_bidui(minma, anma))//转换为暗码与存储器中的进行对比
{ MIMA_change();//进入修改密码函数 show_menu(); } else { INTERRUPT_OFF(); LCD_Clear(); LCD_Write_Hanzi(0, 0, \输入错误!\提示输入错误
Delayms(800); INTERRUPT_ON(); show_menu(); } break; } else break; } } } else { switch(KEY_main) { case 1://开蜂鸣器 { beer = 0; break; } case 2://关蜂鸣器 { beer = 1; break; }
31
case 3://退出 { OPEN = 0; show_menu(); break; } } } } }
uchar MIMA_shuru() {
uchar cnt = 0, i = 0, j = 1;
for(i = 0; i < 8; i++) { minma[i]=0; }
INTERRUPT_ON(); KEY_main=255;
while(KEY_main==255); INTERRUPT_OFF(); LCD_Write_x_y(0, 1);
while(KEY_main!=10)//当按键不是确定键 { if(KEY_main<10&&cnt<8)//8位密码 { minma[cnt++]=KEY_main; LCD_Write(1, KEY_main+0x30);//显示密码 } else if(KEY_main==11) { j = 0; show_menu(); break; } INTERRUPT_ON(); KEY_main=255; while(KEY_main==255);//等键按下 INTERRUPT_OFF(); }
KEY_main=255;
return j;
32
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库课程设计 - 红外遥控电子密码锁的设计与实现(7)在线全文阅读。
相关推荐: