完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
3 个讨论
|
|
#include
#define uint unsigned int #define uchar unsigned char ***it key1=P1^0; ***it key2=P1^1; ***it key3=P1^2; ***it key4=P1^3; ***it lcden=P2^2; ***it lcdrs=P2^0; ***it lcdrw=P2^1; ***it led=P2^4; ***it sound=P2^5; uint a,b,i,min,hour,minge,minshi,hourge,hourshi,amin,ahour,aminge,aminshi,ahourge,ahourshi,sec; //unsigned char code x[]={0xFF,0xC7,0x83,0x01,0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF,0xFF}; //unsigned char code z[]={0xFF,0xE3,0xC1,0x80,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0x7F,0xFF,0xFF}; uchar code table1[]={'0','1','2','3','4','5','6','7','8','9'}; uchar code table2[]="Time:00:00 " ; uchar code Alarm_1[]="Alarm:00:00 "; uchar code nul[]=" "; uchar num1,num2; void delay(unsigned int xms) //???? { uint i,j; for(i=xms;i>0;i--) for(j=124;j>0;j--); } void write_com(uchar com) //?LCD命令控制 { delay(5) ; lcdrs=0; P0=com; delay(5); lcden=1; delay(5); lcden=0; } void write_data(uchar date) //?LCD数据控制 { delay(5); lcdrs=1; P0=date; delay(5); lcden=1; delay(5); lcden=0; } void time() { while(1) { if(key1==0) { delay(10); if(key1==0) { if(hour==23) // 设置时间 hour=0; else hour++; hourge=hour%10; hourshi=hour/10; write_com(0x0f); delay(2); write_com(0x80+6); write_data(table1[hourge]); delay(5); write_com(0x80+5); delay(2); write_data(table1[hourshi]); while(!key1); //delay(1); } } if(key2==0) { delay(10); if(key2==0) { if(min==59) //分钟设置 min=0; else min++; minge=min%10; minshi=min/10; write_com(0x0f); write_com(0x80+9); write_data(table1[minge]); delay(1); write_com(0x80+8); write_data(table1[minshi]); delay(1); while(!key2); } } if(key3==0) { delay(10); if(key3==0) { write_com(0x0c); TR1=1; while(!key3); break; } } } } void alarm() { while(1) { if(key1==0) { delay(10); if(key1==0) { if(ahour==24) ahour=0; else ahour++; ahourge=ahour%10; ahourshi=ahour/10; write_com(0x0f); //delay(2); write_com(0x80+0x40+8); write_data(':'); write_com(0x80+0x40+7); write_data(table1[ahourge]); delay(1); write_com(0x80+0x40+6); //delay(2); write_data(table1[ahourshi]); delay(1); while(!key1); } } if(key2==0) { delay(10); if(key2==0) { if(amin==59) amin=0; else amin++; aminge=amin%10; aminshi=amin/10; write_com(0x0f); //delay(2); write_com(0x80+0x40+10); write_data(table1[aminge]); delay(1); write_com(0x80+0x40+9); // delay(2); write_data(table1[aminshi]); delay(1); while(!key2); } } if(key3==0) { delay(10); if(key3==0) { write_com(0x0c); write_com(0x80+0x40); for(i=0;i<11;i++) write_data(nul[i]); while(!key3); break; } } } } void keyscan() { if(key1==0) { delay(10); if(key1==0) { while(!key1); time(); } } else if(key2==0) { delay(10); if(key2==0) { while(!key2) { ahourge=ahour%10; ahourshi=ahour/10; write_com(0x80+0x40+7); write_data(table1[ahourge]); delay(5); write_com(0x80+0x40+6); delay(2); write_data(table1[ahourshi]); aminge=amin%10; aminshi=amin/10; write_com(0x80+0x40+10); write_data(table1[aminge]); delay(5); write_com(0x80+0x40+9); delay(2); write_data(table1[aminshi]); write_com(0x80+0x40); for(i=0;i<11;++i) write_data(Alarm_1[i]); } write_com(0x80+0x40); for(i=0;i<11;i++) write_data(nul[i]); } } else if(key3==0) { delay(10); if(key3==0) { while(!key3); ahourge=ahour%10; ahourshi=ahour/10; write_com(0x80+0x40+7); write_data(table1[ahourge]); delay(5); write_com(0x80+0x40+6); delay(2); write_data(table1[ahourshi]); aminge=amin%10; aminshi=amin/10; write_com(0x80+0x40+10); write_data(table1[aminge]); delay(5); write_com(0x80+0x40+9); delay(2); write_data(table1[aminshi]); write_com(0x80+0x40); for(i=0;i<11;++i) write_data(Alarm_1[i]); alarm(); } } else if(key4==0) delay(5); if(key4==0) { while(!key4); a=a+1; if(a%2==0) { for(b=0;b<6;b++) { sound=~sound; delay(200); } sound=1; } else if(a%2==1) { sound=0; delay(300); sound=1; delay(300); } sound=1; } } } void lcd_init() lcden=0; lcdrw=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); delay(2); write_com(0x80); for(i=0;i<16;i++) { write_data(table2[i]); delay(1); } } void init() key1=1;key2=1;key3=1;key4=1;sec=0;a=0;sound=1;amin=1; //led=1; TMOD=0x11; TH1=0x3C; TL1=0xB0; EA=1; ET1=1; TR1=1; } void led1() interrupt 3 { TH1=0x3C; TL1=0xB0; num1++; num2++; if(num1==10) { num1=0; led=~led; } if(amin==min&&ahour==hour&&a%2==0) sound=0; } void main() { lcd_init(); init(); while(1) { keyscan(); if(num2==20) { num2=0; if(hour==23&&min==59&&sec==59) { hour=0;min=0;sec=0; } else if(sec==59&&min==59) { sec=0;min=0;hour++; } else if(sec==59) { sec=0;min++; } else sec++; minge=min%10; minshi=min/10; write_com(0x80+9); write_data(table1[minge]); delay(5); write_com(0x80+8); // delay(2); write_data(table1[minshi]); hourge=hour%10; hourshi=hour/10; write_com(0x80+6); write_data(table1[hourge]); delay(5); write_com(0x80+5); // delay(2); write_data(table1[hourshi]); write_com(0x80+7); write_data(':'); } } } 怎么仿真出现错误了 |
|
|
|
|
|
你想要实现的是什么功能呢?
|
|
|
|
|
|
158 浏览 0 评论
【敏矽微ME32G070开发板免费体验】之原厂2812测试例程解析
237 浏览 0 评论
655 浏览 1 评论
《DNESP32S3使用指南-IDF版_V1.6》第二十六章 INFRARED_RECEPTION实验
563 浏览 0 评论
862 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
12034 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 18:08 , Processed in 0.690249 second(s), Total 38, Slave 31 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号