您的位置 首页 方案

1602LCD液晶怎么编写数字电子钟

以前,学习单片机,都没有开发板,因此感觉编写数字电子钟的程序,是非常难的,简直就是不知道如何着手。现在已经对单片机各种操作都…

曾经,学习单片机,都没有开发板,因而感觉编写数字电子钟的程序,是十分难的,几乎便是不知道怎么着手。 现在现已对单片机各种操作都逐步了解了,因而刚刚就现已完成了自己关于数字电子钟的一点小小的规划思维

因为时刻联系,现在现已比较晚了,所以就暂时不编写按键功用,可是现已完成了动态计时功用了,明日再持续增加按键功用。
#include
#include”MyFuntion.h” //自定义头文件
unsigned char year1=20; // 年1
unsigned char year2=12; // 年2
unsigned char month=1; // 月
unsigned char day=22; // 日
unsigned char hour=23; // 时
unsigned char minute=12; // 分
unsigned char second=56; // 秒
unsigned char table1[10];
unsigned char table2[8];
unsigned char t; //定时器T0 产生中止次数
//unsigned char t1; //定时器T1 产生中止次数
/*
//独立按键P1口
sbit Key1=P3^0; //Key1 撤销调时 康复单片机调时之前的实践时刻
sbit Key2=P3^1; //Key2 进入调整时刻状况: 中止定时器T0,发动定时器T1.
sbit Key3=P3^2; //Key3 退出调整时刻状况: 发动定时器T0,中止定时器T1.
sbit Key4=P3^3; //Key4 挑选调整时刻: 秒, 分, 时, 日, 月, 年
sbit Key5=P3^4; //Key5 调时: 递加 一起发动蜂鸣器
sbit Key6=P3^5; //Key6 Key6 调时: 递减 一起发动蜂鸣器
*/
void Init_Table_YMD() //年月日
//进行对 时刻的转化 以致于能够把时刻发送到1602LCD显现
{
//把 year, month, day 转化为一个字符存储在数组table1
table1[0]=year1/10;
table1[1]=year1%10;
table1[2]=year2/10;
table1[3]=year2%10;
table1[4]=-;
table1[5]=month/10;
table1[6]=month%10;
table1[7]=-;
table1[8]=day/10;
table1[9]=day%10;
}
void Init_Table_HMS() // 时分秒
{
//把 hour, minute, second 转化为一个字符存储在数组table2
table2[0]=hour/10;
table2[1]=hour%10;
table2[2]=:;
table2[3]=minute/10;
table2[4]=minute%10;
table2[5]=:;
table2[6]=second/10;
table2[7]=second%10;
}
void IncreaseTime() // 秒钟 递加
{
second++;
if(second==60)
{
second=0;
minute++;
if(minute==60)
{
minute=0;
hour++;
if(hour==24)
{
hour=0;
}
}
}
Init_Table_HMS(); //时分秒
DisplayLCD_HMS(table2, 8); //LCD显现时刻 时分秒
}
void main()
{
TMOD=0X01;
EA=1;
ET0=1;
// ET1=1;
TR0=1; //发动定时器T0
// TR1=0; //中止定时器T1 即还没有发动定时器T1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
InitLCD(); //初始化LCD
Init_Table_YMD(); // LCD 时刻表 年月日
Init_Table_HMS(); // LCD 时刻表 时分秒
DisplayLCD_YMD(table1, 10); //LCD显现时刻 年月日
DisplayLCD_HMS(table2, 8); //LCD显现时刻 时分秒
while(1)
{
if(t==20)
{
t=0;
IncreaseTime();
}
}
// while(1);
}
void LCD_Timer0() interrupt 1 using 0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/fangan/266783.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部