STM32电子钟万年历时钟闹钟
- 🚩基本功能:
- 🚩仿真图:
- 🚩原理图:
- PCB:
- 🚩程序:
- 🚩资料清单&&下载链接:
- 🚩[资料文件下载链接](https://pan.baidu.com/s/1Sz10LAfeCJrHctztBF4vdA?pwd=3f17 )
# 🚩STM32电子钟万年历时钟闹钟LCD1602仿真设计
(仿真+原理图+PCB+源码+讲解视频)
仿真:protues 8.9
程序编译器:keil 5
编程语言:C语言
编号C0003
资料文件下载链接
🚩基本功能:
题目要求:
1.具有显示年、月、日、时、分、秒功能;
2.能计算并显示星期;
3.能手动调整时间,设置闹钟;
4.具有闹钟功能,时间到声光报警(蜂鸣器嘟嘟嘟,LED灯闪烁)。
- Proteus8.9 仿真图;
- C语言源代码,Keil5打开;
- Altium Designer 原理图 源文件和PDF;
- Altium Designer PCB 源文件和PDF;
- 参考报告(论文)。
🚩仿真图:
🚩原理图:
PCB:
🚩程序:
int main(void)
{
bool i = 0;
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
delay_init(10); //³õʼ»¯ÑÓʱº¯Êý
TIM3_Init(2400-1, 72-1); // 10ms
MX_RTC_Init();
Key_Init();
Beep_Init();
LCD_Init();
sAlrm_g.Alm_Hour = 0;
sAlrm_g.Alm_Min = 0;
sAlrm_g.Alm_Sec = 10;
while(1)
{
switch(set_mode)
{
case 0:
HAL_RTC_GetDate(&hrtc, &sDate_g, RTC_FORMAT_BIN);
HAL_RTC_GetTime(&hrtc, &sTime_g, RTC_FORMAT_BIN);
Conv_Disp_Data(0);
LCD_write_string(0, 0, (char*)temp_line_one);
LCD_write_string(0, 1, (char*)temp_line_two);
break;
case 1:
Conv_Disp_Data(i*1);
i = !i;
LCD_write_string(0, 0, (char*)temp_line_one);
break;
case 2:
Conv_Disp_Data(i*2);
i = !i;
LCD_write_string(0, 0, (char*)temp_line_one);
break;
case 3:
Conv_Disp_Data(i*3);
i = !i;
LCD_write_string(0, 0, (char*)temp_line_one);
break;
case 4:
Conv_Disp_Data(i*4);
i = !i;
LCD_write_string(0, 0, (char*)temp_line_one);
break;
case 5:
Conv_Disp_Data(i*5);
i = !i;
LCD_write_string(0, 0, (char*)temp_line_one);
break;
case 6:
Conv_Disp_Data(i*6);
i = !i;
LCD_write_string(0, 0, (char*)temp_line_one);
break;
case 7:
Conv_Disp_Data(i*7);
i = !i;
LCD_write_string(0, 1, (char*)temp_line_two);
break;
case 8:
Conv_Disp_Data(i*8);
i = !i;
LCD_write_string(0, 1, (char*)temp_line_two);
break;
case 9:
Conv_Disp_Data(i*9);
i = !i;
LCD_write_string(0, 1, (char*)temp_line_two);
break;
default:
break;
}
if( (sTime_g.Hours == sAlrm_g.Alm_Hour) && (sTime_g.Minutes == sAlrm_g.Alm_Min) && (sTime_g.Seconds == sAlrm_g.Alm_Sec) )
{
for(uint8_t j = 0; j < 10; j++)
{
LED2_TOG();
HAL_Delay(300);
}
}
HAL_Delay(100);
}
}
#include "lcd1602.h"
#define DELAY_2N 0
void lcd_delay_us(unsigned int t)
{
unsigned int i, j;
for(i = 10; i > 0; i--)
for(j = t; j > 0; j--);
}
void lcd_delay_ms(unsigned int t)
{
unsigned int i;
for(i = t; i > 0; i--)
lcd_delay_us(10);
}
//==================================================
void LCD_Init(void)
{
GPIO_InitTypeDef GPIO_Initure;
LCD_CTRL_CLK();
LCD_DATA_CLK();
GPIO_Initure.Pin = LCD_RS_PIN|LCD_RW_PIN|LCD_EN_PIN;
GPIO_Initure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_Initure.Pull = GPIO_PULLUP;
GPIO_Initure.Speed = GPIO_SPEED_FREQ_MEDIUM;
HAL_GPIO_Init(LCD_CTRL_PORT, &GPIO_Initure);
GPIO_Initure.Pin = LCD_DATA0_PIN|LCD_DATA1_PIN|LCD_DATA2_PIN|LCD_DATA3_PIN|LCD_DATA4_PIN|LCD_DATA5_PIN|LCD_DATA6_PIN|LCD_DATA7_PIN;
HAL_GPIO_Init(LCD_DATA_PORT, &GPIO_Initure);
LCD_RW(0); //读写位直接低电平,只写不读
/*********************液晶初始化**************************/
lcd_delay_us(340);
LCD_RS(0);
LCD_write_cmd(0x38); // 8bit显示模式,2行,5x7字体
lcd_delay_ms(4);
LCD_write_cmd(0x08); // 显示关闭
lcd_delay_ms(4);
LCD_write_cmd(0x01); // 显示清屏
lcd_delay_ms(4);
LCD_write_cmd(0x06); // 显示光标移动设置
lcd_delay_ms(4);
LCD_write_cmd(0x0c); // 显示开,光标开,光标闪烁
lcd_delay_ms(4);
LCD_write_cmd(0x01); //清屏
lcd_delay_ms(4);
}
/*--------------------------------------------------
函数说明:写命令到液晶
---------------------------------------------------*/
void LCD_write_cmd(unsigned char cmd)
{
LCD_RS(0);
LCD_Write_byte(cmd);
lcd_delay_us(340);
}
/*--------------------------------------------------
函数说明:写数据到液晶
---------------------------------------------------*/
void LCD_write_data(unsigned char w_data)
{
LCD_RS(1);
LCD_Write_byte(w_data);
lcd_delay_us(340);
}
/*--------------------------------------------------
函数说明:写4bit到液晶
--------------------------------------------------*/
void LCD_Write_byte(unsigned char num)
{
if (num&0x01)
data0(1);
else
data0(0);
if (num&0x02)
data1(1);
else
data1(0);
if (num&0x04)
data2(1);
else
data2(0);
if (num&0x08)
data3(1);
else
data3(0);
if (num&0x10)
data4(1);
else
data4(0);
if (num&0x20)
data5(1);
else
data5(0);
if (num&0x40)
data6(1);
else
data6(0);
if (num&0x80)
data7(1);
else
data7(0);
lcd_delay_us(340);
LCD_EN(1);
lcd_delay_us(340);
LCD_EN(0);
lcd_delay_us(340);
}
/*----------------------------------------------------
LCD_set_xy : 设置LCD显示的起始位置
输入参数:x、y : 显示字符串的位置,X:0-15,Y:0-1
-----------------------------------------------------*/
void LCD_set_xy( unsigned char x, unsigned char y )
{
unsigned char address = 0;
if (y==0)
{
address=0x80+x;
}
else
{
address=0xc0+x;
}
// y ? (address=0xc0+x): (address=0x80+x) ;
LCD_write_cmd(address);
}
/*---------------------------------------------------
LCD_write_string : 英文字符串显示函数
输入参数:*s :英文字符串指针;
X、Y : 显示字符串的位置
---------------------------------------------------*/
void LCD_write_string(unsigned char X,unsigned char Y, char *s)
{
LCD_set_xy(X,Y);
while (*s != NULL)
{
LCD_write_data(*s);
s++;
}
}
//=======================================================
void LCD_wstring(unsigned char X,unsigned char *s)
{
LCD_write_cmd(X);
while (*s)
{
LCD_write_data(*s);
s++;
}
}