当前位置:网站首页>(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
边栏推荐
- 关于双亲委派机制和类加载的过程
- (超详细onenet TCP协议接入)arduino+esp8266-01s接入物联网平台,上传实时采集数据/TCP透传(以及lua脚本如何获取和编写)
- 魏牌:产品叫好声一片,但为何销量还是受挫
- Mortal immortal cultivation pointer-1
- Tyut outline of 2022 database examination of Taiyuan University of Technology
- C language Getting Started Guide
- 透彻理解LRU算法——详解力扣146题及Redis中LRU缓存淘汰
- View UI plus released version 1.3.1 to enhance the experience of typescript
- hashCode()与equals()之间的关系
- IPv6 experiment
猜你喜欢

View UI plus released version 1.2.0 and added image, skeleton and typography components
![[au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP](/img/d6/109042b77de2f3cfbf866b24e89a45.png)
[au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP

9. Pointer (upper)

Change vs theme and set background picture

Decomposition relation model of the 2022 database of tyut Taiyuan University of Technology

Leetcode.3 无重复字符的最长子串——超过100%的解法

C language Getting Started Guide

3. C language uses algebraic cofactor to calculate determinant

5. Function recursion exercise

Questions and answers of "Fundamentals of RF circuits" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
随机推荐
View UI plus released version 1.3.1 to enhance the experience of typescript
JS interview questions (I)
2. Preliminary exercises of C language (2)
IPv6 experiment
8. C language - bit operator and displacement operator
List set map queue deque stack
受检异常和非受检异常的区别和理解
[the Nine Yang Manual] 2019 Fudan University Applied Statistics real problem + analysis
Solution: warning:tensorflow:gradients do not exist for variables ['deny_1/kernel:0', 'deny_1/bias:0',
Relational algebra of tyut Taiyuan University of technology 2022 database
1. C language matrix addition and subtraction method
重载和重写的区别
Wei Pai: the product is applauded, but why is the sales volume still frustrated
Data manipulation language (DML)
View UI Plus 发布 1.1.0 版本,支持 SSR、支持 Nuxt、增加 TS 声明文件
1.C语言矩阵加减法
Questions and answers of "signal and system" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
Database operation of tyut Taiyuan University of technology 2022 database
[the Nine Yang Manual] 2018 Fudan University Applied Statistics real problem + analysis
Redis的两种持久化机制RDB和AOF的原理和优缺点