使用的单片机是 STC89C52
此设计可以 年 月 日 时 分 秒显示和闹钟功能 能通过8个按键自由调整 时 分 秒 闹钟响铃时间
带复位按键,要是模块抽风,摁复位按键即可!
使用 LCD16020A 屏幕显示 屏幕电路设有电位器,可以调整清自由屏幕晰度
原理图上均标注了每个元件的 值和型号,方便购买正确的元件
程序代码在附件里
无需改动,直接烧录即可
原理图:
PCB:
实物图:
程序运行图:
部分程序:
/** //sbit LED = P2^0; /**
* @brief 利用定时器中断 完成LED流水
*/
#include
#include "LCD1602.h"
#include "Key.h"
#include "Buzzer.h"
#include "Delay.h"
unsigned char sec = 0, min = 0, hour =0;
unsigned char table_sec = 30, table_min = 0, table_hour =0;
unsigned char mode = 0,Num;
* @brief 定时器0初始化;1毫秒@12.000MHz
* @param 无
* @retval 无
* @arg 1.设置定时器方式
* @arg 2.设置定时器初值;即延时时长
* @arg 3.打开中断
*/
void Timer0Init(void)
{
TMOD &= 0xF0; //设置定时器模式
TMOD |= 0x01; //设置定时器模式
TL0 = 0x18; //设置定时初值
TH0 = 0xFC; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0 = 1; //打开T0中断 (IE寄存器内部运行)
EA = 1; //打开总中断 (IE寄存器内部运行)
PT0 = 0; //设置优先级
}
/**
* @brief
* @param
* @arg
* @retval
*/
void main()
{
LCD_Init();
Timer0Init();
LCD_ShowString(1,1,"2022-11-09 Wes");
LCD_ShowString(2,1," : :");
while(1)
{
if(mode == 0)
{
LCD_ShowNum(2,7,sec,2);
LCD_ShowNum(2,4,min,2);
LCD_ShowNum(2,1,hour,2);
switch (Key_Scan())
{
case 1: sec++;if(sec > 59) sec = 0 ; break;
case 2: sec--;if(sec > 59) sec = 59 ; break;
case 3: min++;if(min > 59) min = 0 ;break;
case 4: min--;if(min > 59) min = 59 ;break;
case 5: hour++;if(hour > 23) hour = 0;break;
case 6: hour--;if(hour > 23) hour = 23 ;break;
case 8: mode = 1;break;
default : break;
}
Num = Key_Scan();
if (hour == table_hour & min == table_min & sec == table_sec)
{
Buzzer(10000);
}
}
if (mode == 1)
{
LCD_ShowNum(2,7,table_sec,2);
LCD_ShowNum(2,4,table_min,2);
LCD_ShowNum(2,1,table_hour,2);
switch (Key_Scan())
{
case 1: table_sec++;if(table_sec > 59) table_sec = 0 ; break;
case 2: table_sec--;if(table_sec > 59) table_sec = 59 ; break;
case 3: table_min++;if(table_min > 59) table_min = 0 ;break;
case 4: table_min--;if(table_min > 59) table_min = 59;break;
case 5: table_hour++;if(table_hour > 23) table_hour = 0;break;
case 6: table_hour--;if(table_hour > 23) table_hour = 23 ;break;
case 7: mode = 0;break;
}
}
}
}
{
T0Count = 0;
sec++;
if ( sec > 59)
{
min++;
sec = 0;
if ( min > 59)
{
hour++;
min = 0;
if ( hour > 23)
{
hour = 0;
}
}
}
}
}
相关文章









