当前位置:网站首页>(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
边栏推荐
- 2.初识C语言(2)
- [au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP
- 仿牛客技术博客项目常见问题及解答(三)
- 【手撕代码】单例模式及生产者/消费者模式
- 【九阳神功】2018复旦大学应用统计真题+解析
- Quickly generate illustrations
- 为什么要使用Redis
- PriorityQueue (large root heap / small root heap /topk problem)
- 学编程的八大电脑操作,总有一款你不会
- 最新坦克大战2022-全程开发笔记-3
猜你喜欢
随机推荐
自定义RPC项目——常见问题及详解(注册中心)
Relational algebra of tyut Taiyuan University of technology 2022 database
IPv6 experiment
Caching mechanism of leveldb
8. C language - bit operator and displacement operator
更改VS主题及设置背景图片
1.初识C语言(1)
Rich Shenzhen people and renting Shenzhen people
Voir ui plus version 1.3.1 pour améliorer l'expérience Typescript
7. Relationship between array, pointer and array
仿牛客技术博客项目常见问题及解答(三)
[modern Chinese history] Chapter 9 test
Data manipulation language (DML)
20220211-CTF-MISC-006-pure_ Color (use of stegsolve tool) -007 Aesop_ Secret (AES decryption)
MySQL中count(*)的实现方式
Mortal immortal cultivation pointer-2
6. Function recursion
Smart classroom solution and mobile teaching concept description
3. C language uses algebraic cofactor to calculate determinant
Leetcode. 3. Longest substring without repeated characters - more than 100% solution