完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
代码部分 /16电子信息工程 1班 项目:基于51单片机的LCD电子钟设计/ #include #define uchar unsigned char #define uint unsigned int ***it rs=P2^0; ***it lcden=P2^2; ***it rd=P2^1; ***it s1=P3^0; ***it s2=P3^1; ***it s3=P3^2; ***it beep=P2^3; uchar count,s1num; char miao,shi,fen,nian,yue,ri,zhou,num,tian; char yizhou8={“MON”,“TUE”,“WEN”,“THU”,“FRI”,“SAT”,“SUN”}; int pingnian[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int ruinian[13]={0,31,29,31,30,31,30,31,31,30,31,30,31}; void delay(uint z) { uint x,y; for(x=z;x>0;x–) for(y=110;y>0;y–); } void di() { uchar i; for(i=0;i<100;i++) { beep = ~beep; delay(1); } beep = 0; } void write_com(uchar com)//液晶写命令函数 { rs=0; lcden=0; P0=com; delay(5); lcden=1; delay(5); lcden=0; } void write_date(uchar date)//液晶写数据函数 { rs=1; lcden=0; P0=date; delay(5); lcden=1; delay(5); lcden=0; } void write_sfm(uchar add,uchar date)//写时分秒函数 { uchar shi,ge; shi=date/10; ge=date%10; write_com(0x80+0x40+add); write_date(0x30+shi); write_date(0x30+ge); } void write_nyr(uchar add,uchar date)//写年月日函数 { uchar shi,ge; shi=date/10; ge=date%10; write_com(0x80+add); write_date(0x30+shi); write_date(0x30+ge); } void init()//初始化函数 { num=0; rd=0; lcden=0; fen=0; miao=0; shi=0; nian=1; yue=1; ri=1; zhou=0; count=0; s1num=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); write_com(0x80+1); write_date(‘2’); write_com(0x80+2 ); write_date(‘0’); write_com(0x80+0x40+6); write_date(’:’); delay(5); write_com(0x80+0x40+9); write_date(’:’); delay(5); write_com(0x80+5); write_date(’-’); delay(5); write_com(0x80+8); write_date(’-’); delay(5); write_com(0x80+12); for(num=0;num<3;num++) { write_date(yizhou[zhou][num]); delay(5); } write_nyr(3,nian); write_nyr(6,yue); write_nyr(9,ri); write_sfm(10,miao); write_sfm(7,fen); write_sfm(4,shi); TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; } void keyscan()//按键扫描函数 { if(s10) { delay(5); if(s10) { s1num++; while(!s1); di(); if(s1num1) { TR0=0; write_com(0x80+0x40+11); write_com(0x0f); } if(s1num2) { write_com(0x80+0x40+8); } if(s1num3) { write_com(0x80+0x40+5); } if(s1num4) { write_com(0x80+14); } if(s1num5) { write_com(0x80+10); } if(s1num6) { write_com(0x80+7); } if(s1num7) { write_com(0x80+4); } if(s1num8) { s1num=0; write_com(0x0c); TR0=1; } } } if(s1num!=0) { if(s20) { delay(5); if(s20) { while(!s2); di(); if(s1num1) { miao++; if(miao>=60) miao=0; write_sfm(10,miao); write_com(0x80+0x40+11); } if(s1num2) { fen++; if(fen>=60) fen=0; write_sfm(7,fen); write_com(0x80+0x40+8); } if(s1num3) { shi++; if(shi>=24) shi=0; write_sfm(4,shi); write_com(0x80+0x40+5); } if(s1num4) { zhou++; if(zhou>=7) zhou=0; write_com(0x80+12); for(num=0;num<3;num++) { write_date(yizhou[zhou][num]); delay(5); } } if(s1num5) { ri++; if((2000+nian)%4000||(2000+nian)%40&&(2000+nian)%100!=0) tian=ruinian[yue]; else nian=pingnian[yue]; if(ri>tian) ri=1; write_nyr(9,ri); write_com(0x80+10); } if(s1num6) { yue++; if(yue>12) yue=1; write_nyr(6,yue); write_com(0x80+7); } if(s1num7) { nian++; if(nian>50) nian=0; write_nyr(3,nian); write_com(0x80+4); } } } if(s30) { delay(5); if(s30) { while(!s3); di(); if(s1num1) { miao–; if(miao<0) miao=59; write_sfm(10,miao); write_com(0x80+0x40+11); } if(s1num2) { fen–; if(fen<0) fen=59; write_sfm(7,fen); write_com(0x80+0x40+8); } if(s1num3) { shi–; if(shi<0) shi=23; write_sfm(4,shi); write_com(0x80+0x40+5); } if(s1num4) { zhou–; if(zhou<0) zhou=6; write_com(0x80+12); for(num=0;num<3;num++) { write_date(yizhou[zhou][num]); delay(5); } } if(s1num5) { ri–; if((2000+nian)%4000||(2000+nian)%40&&(2000+nian)%100!=0) tian=ruinian[yue]; else nian=pingnian[yue]; if(ri<1) ri=tian; write_nyr(9,ri); write_com(0x80+10); } if(s1num6) { yue–; if(yue<1) yue=12; write_nyr(6,yue); write_com(0x80+7); } if(s1num7) { nian–; if(nian<0) nian=50; write_nyr(3,nian); write_com(0x80+4); } } } } } void main()//主函数 { init(); while(1) { keyscan(); } } void timer0() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; count++; if(count20) { count=0; miao++; if(miao>=60) { miao=0; fen++; if(fen>=60) { fen=0; shi++; if(shi>=24) { shi=0; ri++; zhou++; if(zhou>6) zhou=0; write_com(0x80+12); for(num=0;num<3;num++) { write_date(yizhou[zhou][num]); delay(5); } if((2000+nian)%4000||(2000+nian)%4==0&&(2000+nian)%100!=0) tian=ruinian[yue]; else nian=pingnian[yue]; if(ri>tian) { ri=1; yue++; if(yue>12) { yue=1; nian++; if(nian>50) { nian=0; } write_nyr(3,nian); } write_nyr(6,yue); } write_nyr(9,ri); } write_sfm(4,shi); } write_sfm(7,fen); } write_sfm(10,miao); } } |
|
|
|
只有小组成员才能发言,加入小组>>
2557 浏览 0 评论
1158浏览 2评论
761浏览 1评论
514浏览 0评论
271浏览 0评论
447浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-26 04:46 , Processed in 1.386046 second(s), Total 80, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号