您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > 基于AVR单片机的带密码显示的DS302仿真设计
广州白云技师学院电子系技师班《单片机技术》课程项目化教学系列基于AVR单片机(ATMEGE16A)的带密码显示的DS302仿真设计廖高灵功能:1、开机密码123456用户可以根据自己需求修改2、进入时钟界面通过K1,K2,K3调整时钟仿真界面:程序代码:(已经通过调试)/*************************main_1302.c**************************/#includeiom16v.h#includemacros.h#include1602_jp_sz.c#include1302_sz.c#includekeyboard.c#includejzkeyboard.c#includepassword.c#defineucharunsignedchar#defineuintunsignedintvoiddelay1(uintx){uinti,j;for(i=x;i0;i--)for(j=600;j0;j--);}voidwrite_time(){miao=change1(miao);fen=change1(fen);si=change1(si);ri=change1(ri);yue=change1(yue);xq=change1(xq);nian=change1(nian);write_ds1302(0x80,miao);write_ds1302(0x82,fen);write_ds1302(0x84,si);write_ds1302(0x86,ri);write_ds1302(0x88,yue);write_ds1302(0x8a,xq);write_ds1302(0x8c,nian);}ucharchange(uchardat)//16-10{uchara,b;a=dat/16;a=10*a;b=dat%16;dat=a+b;returndat;}ucharchange1(uchardat)//10-16{uchara,b;a=dat/10;a=16*a;b=dat%10;dat=a+b;returndat;}voidshow_time(){//uchara,b;miao=read_ds1302(0x81);fen=read_ds1302(0x83);si=read_ds1302(0x85);ri=read_ds1302(0x87);yue=read_ds1302(0x89);xq=read_ds1302(0x8b);nian=read_ds1302(0x8d);miao=change(miao);fen=change(fen);si=change(si);ri=change(ri);yue=change(yue);xq=change(xq);nian=change(nian);_1602dis_sfm(si,fen,miao);_1602dis_nyrq(nian,yue,ri,xq);}voidmain(){DDRD&=~BIT(PC0)&~BIT(PC1)&~BIT(PC2);PORTD|=BIT(PC0)|BIT(PC1)|BIT(PC2);DDRC=0XFF;init1602();delay1(20);lcd_inputpassword();while(1){password();while(flag){show_time();keyboard();}}}/*********************1602_jp_sz.c**********************//******************************************///功能:1602显示时钟//管脚配置:PB为数据,PD3=RS,PD6=RW,PD7=E;//k1=PA0,K2=PA1,K3=PA2;/*******************************************/#includeiom16v.h#includemacros.h#defineucharunsignedchar#defineuintunsignedint//#pragmainterrupt_handlers_f_m:9#pragmadata:codeconstuchartable1[]=20--;constuchartable2[]=::;signedcharsi,fen,miao,nian,yue,ri,xq;ucharup,down;voiddelay(uintx){uinti,j;for(i=x;i0;i--)for(j=600;j0;j--);}/*************lcd1602************************/voidwrite1602_cm(ucharcm){DDRB=0XFF;DDRD|=BIT(PD3)|BIT(PD6)|BIT(PD7);PORTD&=~BIT(PD3);//RS=0;PORTD&=~BIT(PD6);//RW=0;PORTD&=~BIT(PD7);//E=0;delay(1);PORTB=cm;PORTD|=BIT(PD7);//E=1;delay(1);PORTD&=~BIT(PD7);//E=0;PORTD|=BIT(PD3);//RS=1;}voidwrite1602_dat(uchardat){DDRB=0XFF;DDRD|=BIT(PD3)|BIT(PD6)|BIT(PD7);PORTD|=BIT(PD3);//RS=1;PORTD&=~BIT(PD6);//RW=0;PORTD&=~BIT(PD7);//E=0;delay(1);PORTB=dat;PORTD|=BIT(PD7);//E=1;delay(1);PORTD&=~BIT(PD7);//E=0;PORTD&=~BIT(PD3);//RS=0;}void_1602dis_2line(ucharaddr,uchardat){ucharsi,ge;si=dat/10;ge=dat%10;write1602_cm(0x80+0x40+addr);write1602_dat(0x30+si);delay(1);write1602_dat(0x30+ge);delay(1);}void_1602dis_1line(ucharaddr,uchardat){ucharsi,ge;si=dat/10;ge=dat%10;write1602_cm(0x80+addr);write1602_dat(0x30+si);delay(1);write1602_dat(0x30+ge);delay(1);}void_1602dis_sfm(uchars,ucharf,ucharm){_1602dis_2line(3,s);_1602dis_2line(6,f);_1602dis_2line(9,m);}void_1602dis_nyrq(ucharn,uchary,ucharr,ucharq){_1602dis_1line(4,n);_1602dis_1line(7,y);_1602dis_1line(10,r);_1602dis_1line(13,q);}voidinit1602(){/*TCCR1B=0X04;//256分频TCNT1H=(65535-31250)/256;TCNT1L=(65535-31250)%256;//1sTIMSK|=BIT(2);SREG|=BIT(7);*/write1602_cm(0x38);write1602_cm(0x0C);write1602_cm(0x06);write1602_cm(0x01);//si=9;fen=3;miao=23;}voidlcd_time_init(){uchari;write1602_cm(0x80);for(i=0;i15;i++){write1602_dat(table1[i]);delay(5);}write1602_cm(0x80+0X40);for(i=0;i11;i++){write1602_dat(table2[i]);delay(5);}}/************************1302_sz.c******************************//*******************ds1302*****************///功能:读取1302时钟//管脚分配:PC1=SCKPC0=I/OPC2=CE/******************************************/#includemacros.h#include1302.h#defineucharunsignedchar#defineuintunsignedintvoiddelay2(uintx){uinti,j;for(i=x;i0;i--)for(j=600;j0;j--);}voidwrite_dat(uchardat){uchari,temp;DDRC=0XFF;temp=dat;for(i=8;i0;i--){if(temp&0x01)IO_H;elseIO_L;temp=temp1;//10011101sclk_H;sclk_L;}}ucharread_dat(){uchari,temp;DDRC&=~BIT(PC0);PORTC|=BIT(PC0);for(i=8;i0;i--){temp=temp1;if(PINC&0x01){temp=temp|0x80;}sclk_H;sclk_L;}returntemp;}voidwrite_ds1302(ucharadd,uchardat){CE_L;sclk_L;CE_H;write_dat(add);write_dat(dat);//sclk_L;CE_L;}ucharread_ds1302(ucharadd){uchartemp;CE_L;sclk_L;CE_H;write_dat(add);temp=read_dat();sclk_H;CE_L;returntemp;}/*****************************keyboard.c**************************//******************************************************************//独立键盘k1=PDOk2=PD1k3=PD2/*****************************************************************/#definek1PIND&0x01#definek2PIND&0X02#definek3PIND&0X04ucharnum;voidK1(){if(~k1){num++;}}voidkeyboard(){if(~k1){num++;write1602_cm(0x80+0x40+10);write1602_cm(0x0f);}while(~k1);while(num==1)///////miao+-{write1602_cm(0x80+0x40+10);K1();while(~k1);if(~k2){miao++;if(miao==60){miao=0;}while(~k2);_1602dis_2line(9,miao);}if(~k3){miao--;if(miao==0xff){miao=59;}while(~k3);_1602dis_2line(9,miao);}}while(num==2)//fen+-{write1602_cm(0x80+0x40+7);K1();while(~k1);if(~k2){fen++;if(fen==60){fen=0;}while(~k2);_1602dis_2line(6,fen);}if(~k3){fen--;if(fen==0x
本文标题:基于AVR单片机的带密码显示的DS302仿真设计
链接地址:https://www.777doc.com/doc-2568637 .html