当前位置:网站首页>(原创)制作一个采用 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相连的按钮来发生改变。
源码和仿真链接
链接: 点击前往下载
边栏推荐
- FileInputStream和BufferedInputStream的比较
- 7.数组、指针和数组的关系
- Redis的两种持久化机制RDB和AOF的原理和优缺点
- 【九阳神功】2018复旦大学应用统计真题+解析
- There is always one of the eight computer operations that you can't learn programming
- MySQL Database Constraints
- Network layer 7 protocol
- Rich Shenzhen people and renting Shenzhen people
- 6. Function recursion
- 7. Relationship between array, pointer and array
猜你喜欢
(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
9.指针(上)
Decomposition relation model of the 2022 database of tyut Taiyuan University of Technology
4.二分查找
The latest tank battle 2022 full development notes-1
1.初识C语言(1)
4.分支语句和循环语句
TYUT太原理工大学2022数据库大题之分解关系模式
8.C语言——位操作符与位移操作符
最新坦克大战2022-全程开发笔记-2
随机推荐
Questions and answers of "basic experiment" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
arduino+DS18B20温度传感器(蜂鸣器报警)+LCD1602显示(IIC驱动)
167. Sum of two numbers II - input ordered array - Double pointers
Quickly generate illustrations
5. Function recursion exercise
View UI Plus 发布 1.2.0 版本,新增 Image、Skeleton、Typography组件
(超详细onenet TCP协议接入)arduino+esp8266-01s接入物联网平台,上传实时采集数据/TCP透传(以及lua脚本如何获取和编写)
Network layer 7 protocol
Mortal immortal cultivation pointer-1
(超详细二)onenet数据可视化详解,如何用截取数据流绘图
View UI Plus 发布 1.3.0 版本,新增 Space、$ImagePreview 组件
TYUT太原理工大学2022数据库大题之概念模型设计
ABA问题遇到过吗,详细说以下,如何避免ABA问题
Alibaba cloud microservices (I) service registry Nacos, rest template and feign client
hashCode()与equals()之间的关系
165. Compare version number - string
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
MPLS experiment
最新坦克大战2022-全程开发笔记-2
凡人修仙学指针-1