当前位置:网站首页>(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
边栏推荐
- Questions and answers of "basic experiment" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
- 仿牛客技术博客项目常见问题及解答(二)
- 6. Function recursion
- [the Nine Yang Manual] 2019 Fudan University Applied Statistics real problem + analysis
- 3. C language uses algebraic cofactor to calculate determinant
- (super detailed II) detailed visualization of onenet data, how to plot with intercepted data flow
- [中国近代史] 第九章测验
- 2. Preliminary exercises of C language (2)
- 【手撕代码】单例模式及生产者/消费者模式
- Database operation of tyut Taiyuan University of technology 2022 database
猜你喜欢
The latest tank battle 2022 - Notes on the whole development -2
View UI plus released version 1.3.0, adding space and $imagepreview components
6. Function recursion
【手撕代码】单例模式及生产者/消费者模式
E-R graph to relational model of the 2022 database of tyut Taiyuan University of Technology
Decomposition relation model of the 2022 database of tyut Taiyuan University of Technology
C language to achieve mine sweeping game (full version)
Smart classroom solution and mobile teaching concept description
8. C language - bit operator and displacement operator
3.输入和输出函数(printf、scanf、getchar和putchar)
随机推荐
5. Download and use of MSDN
13 power map
Aurora system model of learning database
Implement queue with stack
关于双亲委派机制和类加载的过程
View UI plus released version 1.3.1 to enhance the experience of typescript
稻 城 亚 丁
Tyut Taiyuan University of technology 2022 "Mao Gai" must be recited
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
8. C language - bit operator and displacement operator
20220211-CTF-MISC-006-pure_ Color (use of stegsolve tool) -007 Aesop_ Secret (AES decryption)
(ultra detailed onenet TCP protocol access) arduino+esp8266-01s access to the Internet of things platform, upload real-time data collection /tcp transparent transmission (and how to obtain and write L
[中国近代史] 第六章测验
List set map queue deque stack
更改VS主题及设置背景图片
西安电子科技大学22学年上学期《信号与系统》试题及答案
[the Nine Yang Manual] 2019 Fudan University Applied Statistics real problem + analysis
2. Preliminary exercises of C language (2)
(super detailed II) detailed visualization of onenet data, how to plot with intercepted data flow
1.C语言矩阵加减法