




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、本程序是基于單片機電子密碼鎖畢業(yè)設計的全部程序。程序經過調試成功,并做出成品。供各界好友分享,未經本人(王明珠QQ516682439)同意不能外傳。謝謝合作。原理圖如下:#include <reg52.h>#include <intrins.h>sbit RS = P24;/定義端口 sbit RW = P25;sbit EN = P26;sbit SCK=P36;sbit SDA=P34;sbit RST = P35; / DS1302復位sbit speak = P20;bit ReadRTC_Flag=0;#define RS_CLR RS=0 #define R
2、S_SET RS=1#define RW_CLR RW=0 #define RW_SET RW=1 #define EN_CLR EN=0#define EN_SET EN=1unsigned char g,tk,ti=1,r,hz,lz,x,z=0;unsigned char a,b=8,temp,temp1,temp2,temp3,temp4,temp5,temp6,temp7=3,temp8,temp9,temp10;unsigned char table16=0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43
3、,0x44,0x45,0x46;unsigned char table16=0x30,0x30,0x30,0x30,0x30,0x30;unsigned char table26=0x31,0x31,0x31,0x31,0x31,0x31;unsigned char MM6=2,2,2,2,2,2;unsigned char l_tmpdate7=0,42,9,27,6,3,9;/秒分時日月周年08-05-15 12:00:00unsigned char l_tmpdisplay8; /秒分時unsigned char r_tmpdisplay8; / 日月周年code unsigned ch
4、ar write_rtc_address7=0x80,0x82,0x84,0x86,0x88,0x8a,0x8c; /秒分時日月周年 最低位讀寫位code unsigned char read_rtc_address7=0x81,0x83,0x85,0x87,0x89,0x8b,0x8d; /顯示位碼表 */*延時函數*/void delay_us(unsigned int n) /延時 如果需要高精度延時 請嵌入匯編 if (n = 0) return ; while (-n); /*延時函數*/ void delay_ms(unsigned int i) unsigned char a,
5、b; for (a = 1; a < i; a+) for (b = 1;b; b+) ; /*顯示屏命令寫入函數*/ void LCD_write_com(unsigned char com) RS_CLR; RW_CLR; EN_SET; P0 = com; delay_us(5); EN_CLR; /*顯示屏數據寫入函數*/ void LCD_write_Data(unsigned char Data) RS_SET; RW_CLR; EN_SET; P0 = Data; delay_us(5); EN_CLR; /*顯示屏清空顯示*/ void LCD_clear(void) L
6、CD_write_com(0x01); delay_ms(5); /*顯示屏字符串寫入函數*/ void LCD_write_str(unsigned char x,unsigned char y,unsigned char *s) if (y = 1) LCD_write_com(0x80 + x); if(y=2) LCD_write_com(0xC0 + x); while (*s) LCD_write_Data( *s); s +; /*顯示屏單字符寫入函數*/ void LCD_write_char(unsigned char x,unsigned char y,unsigned c
7、har Data) if (y = 1) LCD_write_com(0x80 + x); if(y=2) LCD_write_com(0xC0 + x); LCD_write_Data( Data); /*顯示屏初始化函數*/ void LCD_init(void) LCD_write_com(0x38); /*6顯示模式設置*/ delay_ms(5); LCD_write_com(0x08); /*4顯示關閉*/ LCD_write_com(0x01); /*顯示清屏*/ LCD_write_com(0x06); /*顯示光標移動設置*/ delay_ms(5); LCD_write_c
8、om(0x0c); /*顯示開及光標設置*/ /*/ /*/void Write_Ds1302_Byte(unsigned char temp) unsigned char i; for (i=0;i<8;i+) /循環(huán)8次 寫入數據 SCK=0; SDA=temp&0x01; /每次傳輸低字節(jié) temp>>=1; /右移一位 SCK=1; /*/void Write_Ds1302( unsigned char address,unsigned char dat ) RST=0;_nop_(); SCK=0;_nop_(); RST=1; _nop_(); /啟動 W
9、rite_Ds1302_Byte(address);/發(fā)送地址 Write_Ds1302_Byte(dat);/發(fā)送數據 RST=0; /恢復/*/unsigned char Read_Ds1302 ( unsigned char address ) unsigned char i,temp=0x00; RST=0;_nop_(); SCK=0;_nop_(); RST=1;_nop_(); Write_Ds1302_Byte(address); for (i=0;i<8;i+) /循環(huán)8次 讀取數據 if(SDA) temp|=0x80;/每次傳輸低字節(jié)SCK=0;temp>&g
10、t;=1;/右移一位 SCK=1; RST=0;_nop_();/以下為DS1302復位的穩(wěn)定時間 RST=0;SCK=0;_nop_();SCK=1;_nop_();SDA=0;_nop_();SDA=1;_nop_();return (temp);/返回/*/void Read_RTC(void)/讀取 日歷 unsigned char *p; p=read_rtc_address; /地址傳遞 for(r=0;r<7;r+)/分7次讀取 秒分時日月周年 l_tmpdater=Read_Ds1302(*p); p+; delay_us(10); /*/void Set_RTC(voi
11、d)/設定 日歷unsigned char i,*p,tmp;for(i=0;i<7;i+) /BCD處理 tmp=l_tmpdatei/10; /十進制變十六進制l_tmpdatei=l_tmpdatei%10;l_tmpdatei=l_tmpdatei+tmp*16; Write_Ds1302(0x8E,0X00); p=write_rtc_address;/傳地址 for(i=0;i<7;i+)/7次寫入 秒分時日月周年 Write_Ds1302(*p,l_tmpdatei); p+; delay_us(10); Write_Ds1302(0x8E,0x80);void ti
12、me() /unsigned char i;Read_RTC(); l_tmpdisplay0=l_tmpdate2/16;/數據的轉換,因我們采用09的顯示,將數據分開l_tmpdisplay1=l_tmpdate2&0x0f;/l_tmpdisplay2='a' /加入"-"l_tmpdisplay3=l_tmpdate1/16;/l_tmpdisplay4=l_tmpdate1&0x0f;/l_tmpdisplay5=b;l_tmpdisplay6=l_tmpdate0/16; / 分l_tmpdisplay7=l_tmpdate0&a
13、mp;0x0f; /秒r_tmpdisplay0=l_tmpdate6/16;/年r_tmpdisplay1=l_tmpdate6&0x0f;/r_tmpdisplay2=10;r_tmpdisplay3=l_tmpdate4/16; / 月r_tmpdisplay4=l_tmpdate4&0x0f;/r_tmpdisplay5=10;r_tmpdisplay6=l_tmpdate3/16; /日r_tmpdisplay7=l_tmpdate3&0x0f; temp1=r_tmpdisplayti; temp2=tabletemp1; LCD_write_char(tk
14、,1,temp2); LCD_write_char(1,1,0xb0); LCD_write_char(4,1,0xb0); LCD_write_char(7,1,0xb0); delay_ms(10); tk+; if(tk=7) tk=0; ti+; if(ti=8) ti=1; delay_ms(10); temp3=l_tmpdisplaya; temp4=tabletemp3; LCD_write_char(b,1,temp4); LCD_write_char(10,1,0xb0); LCD_write_char(13,1,0xb0); delay_ms(10); b+; if(b=
15、16) b=8; a+; if(a=8) a=0;delay_ms(10); /*/*void InitTIMER0(void) TMOD|=0x01;/定時器設置 16位 TH0=(65536-2500)/256; TL0=(65536-2500)%256; ET0=1; TR0=1; EA=1;*/*/*/key()P3=0X0f;if(P3&0x0f)!=0x0f) delay_ms(10); if(P3&0x0f)!=0x0f) hz=0x7f; while(1) P3=hz; if(P3!=hz) return(P3); else hz=(hz>>1)|0
16、x80; / if(hz=0xf7) / hz=0x7f; else return 0; /*/void ajcl(unsigned char jz) if(jz=0x81) temp5=table0;if(jz=0x82) temp5=table1;if(jz=0x84) temp5=table2;if(jz=0x88) temp5=table3;if(jz=0x41) temp5=table4;if(jz=0x42) temp5=table5;if(jz=0x44) temp5=table6;if(jz=0x48) temp5=table7;if(jz=0x21) temp5=table8
17、;if(jz=0x22) temp5=table9;if(jz=0x24) temp5=table10; / A 左if(jz=0x28) temp5=table11; / B 右if(jz=0x11) temp5=table12; / C 取消if(jz=0x12) temp5=table13; / D修改時間if(jz=0x14) temp5=table14; / E修改密碼if(jz=0x18) temp5=table15; / F 確認/*/*/*/*/*/ void main(void) unsigned char d,k=0,e=0,f=0,h,l,MM1=0,MM2,an=0,t
18、t=0,rr=0,u=0; unsigned char t=0,i=1,st=1,st1=1,m,n=0,st2=1,st3,jz=0XFF,st4=1,st5=1,st6=1;/InitTIMER0();LCD_init(); Set_RTC();while(1) time(); t=0;i=1;st=1;st1=1;m=0,n=0;time();st2=1;st3=0;jz=0XFF;st4=1;st5=1;st6=1;d=0;k=0;e=0;f=0;h=0;l=0,MM1=0;time();MM2=0;an=0;tt=0;rr=0;u=0;time();g=0;tk=0;ti=1;r=0
19、;hz=0;lz=0;x=0;z=0;time();a=0;b=8;temp=0;temp1=0;time();temp2=0;temp3=0;time();temp4=0;temp5=0;temp6=0;temp7=3;temp8=0;temp9=0;temp10=0;P1=0xff; time();jz=key(); ajcl(jz);/LCD_write_com(0x0D); LCD_write_str(0,2,"Hi! Good Moring"); / jz=key(); if(P3&0x0f)!=0x0f) while(P3&0x0f)!=0x0f
20、); while(st) time(); LCD_write_str(0,2,"Input code ");if(an=1) LCD_write_str(0,2,"Input again"); if(P3&0x0f)!=0x0f) while(P3&0x0f)!=0x0f); LCD_write_com(0x01); st1=1; st2=1; time(); while(st1) time(); jz=key(); ajcl(jz); if(P3&0x0f)!=0x0f) while(P3&0x0f)!=0x0f) ;
21、LCD_write_char(d,2,0x2a) ;/改TEMP5就可以 了 table1d=temp5;delay_ms(10);/temp6=table1d;/g=d+6;/LCD_write_char(g,2,temp6); d+;if(d=6)d=0;/P1=0xfe; st2=1; delay_ms(250); LCD_write_str(0,2,"Waiting"); delay_ms(250); for(l=7;l<15;l+) delay_ms(100); LCD_write_str(l,2,"."); delay_ms(100);
22、 while(st2) time();delay_us(150); k=0; for(h=0;h<6;h+) MM1=table1h; temp6=MMh; MM2=tabletemp6; if(MM1=MM2) k+; if(k>5) P1=0xfe;LCD_write_str(0,2,"Coming in Please");for(m=0;m<55;m+)speak=!speak;delay_us(220);delay_ms(200);delay_ms(200);delay_ms(200);P1=0xff; st2=0;st1=0;st=0;st3=1
23、;LCD_write_com(0x01); if(k<=5) P1=0xfd; / LCD_write_str(0,2,"Input again");an=1;if(n>1) LCD_write_str(0,2,"KO!#$%&*?!"); LCD_write_str(0,1,"KO!#$%&*?!");temp7-;temp8=tabletemp7;LCD_write_char(15,2,temp8);delay_ms(50);P1=0xff; for(m=0;m<245;m+)speak=!spe
24、ak;delay_us(20);delay_ms(50); P1=0xfd;for(m=0;m<245;m+)speak=!speak;delay_us(20);P1=0xff;speak=1;st2=0;st1=0;if(temp7=0) P1=0xff; delay_ms(15); temp7+; n+; st1=1; st2=1; if(n=20) /10秒鐘 st1=0; st2=0; /LCD_write_com(0x01); while(st3) time(); LCD_write_str(0,2,"change MM time"); jz=key();
25、ajcl(jz); if(temp5=0x46) while(temp5=0x46) temp5=0x23; LCD_write_str(0,2," OK "); while(st6) jz=key(); ajcl(jz); if(temp5=0x44) /mm P1=0xfb; LCD_write_str(0,2,"Put your code"); delay_ms(200); delay_ms(200); LCD_write_str(0,2," ");while(st5) time();jz=key(); ajcl(jz); if
26、(P3&0x0f)!=0x0f) while(P3&0x0f)!=0x0f) ; table2tt=temp5; delay_ms(10); /temp6=table2tt; LCD_write_char(tt,2,0x2a) ;/改TEMP5就可以 了 tt+; / delay_ms(10);if(tt=6) LCD_write_str(0,2,"Put code again");delay_ms(250);delay_ms(250);delay_ms(250);delay_ms(250); LCD_write_str(0,2," ")
27、; /tt=0; while(st4) delay_ms(10); / P1=0xf0; jz=key(); ajcl(jz); if(P3&0x0f)!=0x0f) while(P3&0x0f)!=0x0f);/delay_ms(10); /temp6=temp5; LCD_write_char(z,2,0x2a) ;/改TEMP5就可以 了 temp6=table2z; z+; if(temp6=temp5) rr+; if(rr>5) LCD_write_str(0,2,"Code ok"); for(m=0;m<55;m+) speak=!speak;delay_us(220);P1=0XFE; delay_ms(250); delay_ms(250); delay_ms(250); delay_ms(250); delay_ms(250); delay_ms(250);for(u=0;u<6
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 學校生物園管理制度
- 學校詩詞曲管理制度
- 學法校資產管理制度
- 學生穿校服管理制度
- 安全生產部管理制度
- 安裝隊科室管理制度
- 定銷房銷售管理制度
- 實訓室環(huán)境管理制度
- 審核制度及管理制度
- 客棧經營與管理制度
- 系統(tǒng)集成方案及實施步驟
- 2025年隴南村文書考試題及答案
- 2025年中科院心理咨詢師培訓考試復習題庫-上(單選題)
- ?;壈踩逃?/a>
- 馬克思主義基本原理與科技創(chuàng)新的結合心得體會
- 美發(fā)店投資入股協(xié)議書8篇
- 第四單元 課題3 物質組成的表示教學設計-2024-2025學年九年級化學人教版(2024)上冊
- DeepSeek零基礎到精通手冊(保姆級教程)
- 2024年中國軟件行業(yè)基準數據 (CSBMK-202410)
- 小學四年級下冊四則混合運算及簡便運算
- 公共政策分析概論 課件 第3章 政策主體、政策客體與政策環(huán)境
評論
0/150
提交評論