当前位置:网站首页>(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 : ![Simulation file download resources can be obtained](/img/68/fc966574353f1f40574778cb4c5e4b.png)
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
边栏推荐
- 【九阳神功】2022复旦大学应用统计真题+解析
- [面試時]——我如何講清楚TCP實現可靠傳輸的機制
- Redis的两种持久化机制RDB和AOF的原理和优缺点
- arduino+水位传感器+led显示+蜂鸣器报警
- 受检异常和非受检异常的区别和理解
- [the Nine Yang Manual] 2021 Fudan University Applied Statistics real problem + analysis
- [graduation season · advanced technology Er] goodbye, my student days
- MySQL中count(*)的实现方式
- 【九阳神功】2020复旦大学应用统计真题+解析
- 最新坦克大战2022-全程开发笔记-3
猜你喜欢
强化学习系列(一):基本原理和概念
Rich Shenzhen people and renting Shenzhen people
1. C language matrix addition and subtraction method
3.C语言用代数余子式计算行列式
4.分支语句和循环语句
C语言入门指南
[面试时]——我如何讲清楚TCP实现可靠传输的机制
1.C语言初阶练习题(1)
Arduino+ds18b20 temperature sensor (buzzer alarm) +lcd1602 display (IIC drive)
3.输入和输出函数(printf、scanf、getchar和putchar)
随机推荐
Cloud native trend in 2022
CorelDRAW plug-in -- GMS plug-in development -- Introduction to VBA -- GMS plug-in installation -- Security -- macro Manager -- CDR plug-in (I)
西安电子科技大学22学年上学期《基础实验》试题及答案
魏牌:产品叫好声一片,但为何销量还是受挫
ROS machine voice
5月14日杂谈
Atomic and nonatomic
ArrayList的自动扩容机制实现原理
透彻理解LRU算法——详解力扣146题及Redis中LRU缓存淘汰
View UI Plus 發布 1.3.1 版本,增强 TypeScript 使用體驗
Application architecture of large live broadcast platform
(super detailed II) detailed visualization of onenet data, how to plot with intercepted data flow
5.函数递归练习
8.C语言——位操作符与位移操作符
The overseas sales of Xiaomi mobile phones are nearly 140million, which may explain why Xiaomi ov doesn't need Hongmeng
(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
甲、乙机之间采用方式 1 双向串行通信,具体要求如下: (1)甲机的 k1 按键可通过串行口控制乙机的 LEDI 点亮、LED2 灭,甲机的 k2 按键控制 乙机的 LED1
4.二分查找
Relational algebra of tyut Taiyuan University of technology 2022 database
Voir ui plus version 1.3.1 pour améliorer l'expérience Typescript