当前位置:网站首页>(原创)制作一个采用 LCD1602 显示的电子钟,在 LCD 上显示当前的时间。显示格式为“时时:分分:秒秒”。设有 4 个功能键k1~k4,功能如下:(1)k1——进入时间修改。
(原创)制作一个采用 LCD1602 显示的电子钟,在 LCD 上显示当前的时间。显示格式为“时时:分分:秒秒”。设有 4 个功能键k1~k4,功能如下:(1)k1——进入时间修改。
2022-07-06 09:20:00 【axu_990707】
(原创)制作一个采用 LCD1602 显示的电子钟,在 LCD 上显示当前的时间。显示格式为“时时:分分:秒秒”。设有 4 个功能键k1~k4,功能如下:
(1)k1——进入时间修改。
(2)k2——修改时数,按一下 k2,当前时数增1。
(3)k3——修改分数,按一下 k3,当前分数增 1。
(4)k4——确认修改完成,电子钟按修改后的时间运行显示。
源码和仿真链接
链接: 点击前往下载
以下是程序代码
//头文件部分 名称见主程序 需要创建 .h 文件
//不会使用请直接下载源码 链接在文章开头和结尾都有
#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;
}
}
仿真图片: 
总结
主程序一直显示时,分,秒三个变量到1602上,无论时分秒三个变量的值是否改变,每当显数任务完成后就会立即刷新一次。这样,只要时分秒变量改变,程序会立即做出响应。而时分秒三变量的值通过定时和int0中断一起完成的。在正常计数状态,三变量的值通过定时中断进行增加/置零。当按下按钮1(也就是int0中断)后,三变量的值倚靠P30、P31、P33相连的按钮来发生改变。
源码和仿真链接
链接: 点击前往下载
边栏推荐
- Caching mechanism of leveldb
- Cloud native trend in 2022
- 【九阳神功】2020复旦大学应用统计真题+解析
- 13 power map
- Branch and loop statements
- TYUT太原理工大学2022软工导论大题汇总
- 1. C language matrix addition and subtraction method
- Service ability of Hongmeng harmonyos learning notes to realize cross end communication
- Small exercise of library management system
- IPv6 experiment
猜你喜欢

学编程的八大电脑操作,总有一款你不会

Alibaba cloud microservices (IV) service mesh overview and instance istio

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

The overseas sales of Xiaomi mobile phones are nearly 140million, which may explain why Xiaomi ov doesn't need Hongmeng

Tyut Taiyuan University of technology 2022 introduction to software engineering summary

2.C语言初阶练习题(2)

hashCode()与equals()之间的关系

Database operation of tyut Taiyuan University of technology 2022 database

What are the advantages of using SQL in Excel VBA

3. Number guessing game
随机推荐
Pit avoidance Guide: Thirteen characteristics of garbage NFT project
TYUT太原理工大学2022数据库题库选择题总结
View UI Plus 发布 1.2.0 版本,新增 Image、Skeleton、Typography组件
1. C language matrix addition and subtraction method
最新坦克大战2022-全程开发笔记-1
5.MSDN的下载和使用
凡人修仙学指针-2
重载和重写的区别
9. Pointer (upper)
Redis cache obsolescence strategy
Application architecture of large live broadcast platform
Cloud native trend in 2022
杂谈0516
最新坦克大战2022-全程开发笔记-2
(超详细二)onenet数据可视化详解,如何用截取数据流绘图
【九阳神功】2016复旦大学应用统计真题+解析
A brief introduction to the database of tyut Taiyuan University of technology in previous years
Voir ui plus version 1.3.1 pour améliorer l'expérience Typescript
8. C language - bit operator and displacement operator
MySQL limit x, -1 doesn't work, -1 does not work, and an error is reported