当前位置:网站首页>(original) make an electronic clock with LCD1602 display to display the current time on the LCD. The display format is "hour: minute: Second: second". There are four function keys K1 ~ K4, and the fun
(original) make an electronic clock with LCD1602 display to display the current time on the LCD. The display format is "hour: minute: Second: second". There are four function keys K1 ~ K4, and the fun
2022-07-06 13:38:00 【axu_ nine hundred and ninety thousand seven hundred and seven】
( original ) Make one using LCD1602 Display electronic clock , stay LCD The current time is displayed on . Display format is “ always : Points... Points : Seconds seconds ”. Equipped with 4 Function keys k1~k4, Function as follows :
(1)k1—— Enter time modification .
(2)k2—— Modification hours , Click k2, Current hours increase 1.
(3)k3—— Revise the score , Click k3, The current score increases 1.
(4)k4—— Confirm that the modification is complete , The electronic clock runs and displays according to the modified time .
Source code and simulation link
link : Click to download
The following is the program code
// Header file section See the main program for the name Need to create .h file
// If you can't use it, please download the source code directly Links are at the beginning and end of the article
#include<intrins.h>
sbit RS=P2^6;
sbit RW=P2^5;
sbit E=P2^7;
unsigned char j=20;
unsigned char hour = 23;
unsigned char minute = 59;
unsigned char second = 58;
sbit P30=P3^0;
sbit P31=P3^1;
sbit P32=P3^2;
sbit P33=P3^3;
void delay(unsigned char time){
unsigned char i,j,k;
for(k=0;k<time;k++){
for(i=0;i<20;i++)
for(j=0;j<15;j++);
}
}
void delay1(unsigned char time){
unsigned char i,j,k;
for(k=0;k<time;k++){
for(i=0;i<255;i++)
for(j=0;j<255;j++);
}
}
void delay2(){
unsigned char i,j;
for(i=0;i<255;i++)
for(j=0;j<255;j++);
}
void write_command(unsigned char com){
E=0;
RS=0;
RW=0;
P0=com;
E=1;
_nop_();
E=0;
delay(1);
}
void lcd_initial(void){
write_command(0x38);
write_command(0x0c);
write_command(0x06);
write_command(0x01);
delay(1);
}
void write_data(unsigned char dat){
E=0;
RS=1;
RW=0;
P0=dat;
E=1;
_nop_();
E=0;
delay(1);
}
void string(unsigned char ad,unsigned char *s){
write_command(ad);
while(*s>0){
write_data(*s++);
delay(4);
}
}
void string1(unsigned char ad,unsigned char s){
unsigned char ge = s%10;
unsigned char shi = s/10;
write_command(ad);
write_data(shi+48);
delay(4);
write_data(ge+48);
delay(4);
}
void showSchHo(void){
string(0x80,"schooling hours");
string(0xc0,"Time");
string1(0xc5,hour);
string(0xc7,":");
string1(0xc8,minute);
string(0xca,":");
string1(0xcb,second);
}
void showOK(void){
string(0x80,"...IT IS OK!...");
string(0xc0,"Time");
string1(0xc5,hour);
string(0xc7,":");
string1(0xc8,minute);
string(0xca,":");
string1(0xcb,second);
}
void showCa(void){
string(0x80,".....Casio.....");
string(0xc0,"Time");
string1(0xc5,hour);
string(0xc7,":");
string1(0xc8,minute);
string(0xca,":");
string1(0xcb,second);
}
#include<reg51.h>
#include<LCD1602Time.h>
void main(){
IT0=1;
EA=1;
EX0=1;
TR0=1;
ET0=1;
TMOD=0x01;
TH0=0x4c;
TL0=0x00;
lcd_initial();
while(1){
showCa();
}
}
void int0(void) interrupt 0 {
unsigned char key = 1;
showSchHo();
while(key){
if(P30 == 0){
delay2();
if(P30 == 0){
hour++;
showSchHo();
if(hour == 24){
hour = 0;
showSchHo();
}
}
}
if(P31 == 0){
delay2();
if(P31 == 0){
minute++;
showSchHo();
if(minute == 60){
minute = 0;
showSchHo();
}
}
}
if(P33 == 0){
delay2();
if(P33 == 0){
key = 0;
showOK();
delay1(3);
}
}
}
}
void time(void) interrupt 1 {
TH0=0x4c;
TL0=0x00;
j--;
if(j==0){
second++;
if(second == 60){
second = 0;
minute++;
if(minute == 60){
minute = 0;
hour++;
if(hour == 24){
hour = 0;
}
}
}
j = 20;
}
}
Simulation picture : 
summary
When the main program is always displayed , branch , Seconds three variables to 1602 On , Whether the values of the three variables change , Every time the number display task is completed, it will be refreshed immediately . such , As long as the time, minute and second variables change , The program will respond immediately . The value of the three variables of time, minute and second is determined by timing and int0 Interrupt to complete together . In the normal counting state , The value of the three variables is increased by a timed interrupt / Zeroing . When the button is pressed 1( That is to say int0 interrupt ) after , The value of three variables depends on P30、P31、P33 Connected buttons to change .
Source code and simulation link
link : Click to download
边栏推荐
- There is always one of the eight computer operations that you can't learn programming
- 关于双亲委派机制和类加载的过程
- [面試時]——我如何講清楚TCP實現可靠傳輸的機制
- E-R graph to relational model of the 2022 database of tyut Taiyuan University of Technology
- 1.初识C语言(1)
- Floating point comparison, CMP, tabulation ideas
- 凡人修仙学指针-2
- 3.输入和输出函数(printf、scanf、getchar和putchar)
- 9. Pointer (upper)
- 重载和重写的区别
猜你喜欢

(超详细二)onenet数据可视化详解,如何用截取数据流绘图

Arduino+ water level sensor +led display + buzzer alarm

西安电子科技大学22学年上学期《信号与系统》试题及答案

仿牛客技术博客项目常见问题及解答(一)

Quickly generate illustrations

Thoroughly understand LRU algorithm - explain 146 questions in detail and eliminate LRU cache in redis

最新坦克大战2022-全程开发笔记-2

透彻理解LRU算法——详解力扣146题及Redis中LRU缓存淘汰

5.MSDN的下载和使用

8.C语言——位操作符与位移操作符
随机推荐
为什么要使用Redis
自定义RPC项目——常见问题及详解(注册中心)
Summary of multiple choice questions in the 2022 database of tyut Taiyuan University of Technology
View UI plus released version 1.3.1 to enhance the experience of typescript
Wei Pai: the product is applauded, but why is the sales volume still frustrated
MySQL Database Constraints
Solution: warning:tensorflow:gradients do not exist for variables ['deny_1/kernel:0', 'deny_1/bias:0',
13 power map
5. Function recursion exercise
[while your roommate plays games, let's see a problem]
Tyut Taiyuan University of technology 2022 "Mao Gai" must be recited
【九阳神功】2022复旦大学应用统计真题+解析
Smart classroom solution and mobile teaching concept description
Decomposition relation model of the 2022 database of tyut Taiyuan University of Technology
仿牛客技术博客项目常见问题及解答(一)
6.函数的递归
【毕业季·进击的技术er】再见了,我的学生时代
Relational algebra of tyut Taiyuan University of technology 2022 database
透彻理解LRU算法——详解力扣146题及Redis中LRU缓存淘汰
Caching mechanism of leveldb