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++;
}
1602LCD液晶数字电子 相关文章:
- 1602LCD液晶数字电子钟 时钟表 C语言(11-18)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)