加入星计划,您可以享受以下权益:

  • 创作内容快速变现
  • 行业影响力扩散
  • 作品版权保护
  • 300W+ 专业用户
  • 1.5W+ 优质创作者
  • 5000+ 长期合作伙伴
立即加入

基于STM32的电子钟万年历时钟闹钟Proteus仿真_LCD1602显示

07/10 09:34
4235
服务支持:
技术交流群

完成交易后在“购买成功”页面扫码入群,即可与技术大咖们分享疑惑和经验、收获成长和认同、领取优惠和红包等。

虚拟商品不可退

当前内容为数字版权作品,购买后不支持退换且无法转移使用。

加入交流群
扫码加入
获取工程师必备礼包
参与热点资讯讨论
放大
实物图
相关方案
  • 方案介绍
  • 相关文件
  • 推荐器件
  • 相关推荐
  • 电子产业图谱
申请入驻 产业图谱

STM32电子钟万年历时钟闹钟_LCD1602液晶屏 (仿真+原理图+PCB+源码+参考报告)
仿真:protues 8.9
程序编译器:keil 5
编程语言:C语言
编号C0003

基本功能:

1.具有显示年、月、日、时、分、秒功能;

2.能计算并显示星期;

3.能手动调整时间,设置闹钟;

4.具有闹钟功能,时间到声光报警(蜂鸣器嘟嘟嘟,LED灯闪烁)。

文件清单:

  1. Proteus8.9 仿真图;
  2. C语言源代码Keil5打开;
  3. Altium Designer 原理图 源文件和PDF;
  4. Altium Designer PCB 源文件和PDF;
  5. 参考报告(论文)。

仿真图(提供源文件):
在这里插入图片描述

原理图(提供源文件):
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++;
    }
}

RTC初始化

/* Includes ------------------------------------------------------------------*/
#include "rtc.h"

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

RTC_HandleTypeDef hrtc;


uint8_t table_week[12]={0,3,3,6,1,4,6,2,5,0,3,5};

uint8_t RTC_Get_Week(uint16_t year,uint8_t month,uint8_t day)
{ 
 uint16_t temp2;
 uint8_t yearH, yearL;
 
 yearH=year/100; yearL=year%100;
 // ???21??,????100 
 if (yearH>19)yearL+=100;
 // ???????1900???? 
 temp2=yearL+yearL/4;
 temp2=temp2%7;
 temp2=temp2+day + table_week[month-1];
 if (yearL%4==0&&month<3)temp2--;
 return(temp2%7);
}

/* RTC init function */
void MX_RTC_Init(void)
{
  RTC_TimeTypeDef sTime = {0};
  RTC_DateTypeDef DateToUpdate = {0};

  /** Initialize RTC Only 
  */
  hrtc.Instance = RTC;
  hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
  hrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM;
  if (HAL_RTC_Init(&hrtc) != HAL_OK)
  {

  }
		
  DateToUpdate.Year = YEAR;
  DateToUpdate.Month = MONTH;
  DateToUpdate.Date = DATE;
  DateToUpdate.WeekDay = WEEK;

  if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BIN) != HAL_OK)
  {}

		
  sTime.Hours = HOUR;
  sTime.Minutes = MIN;
  sTime.Seconds = SEC;

  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
  {}

}

void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
{

  if(rtcHandle->Instance==RTC)
  {
  /* USER CODE BEGIN RTC_MspInit 0 */

  /* USER CODE END RTC_MspInit 0 */
    HAL_PWR_EnableBkUpAccess();
    /* Enable BKP CLK enable for backup registers */
    __HAL_RCC_BKP_CLK_ENABLE();
    /* RTC clock enable */
    __HAL_RCC_RTC_ENABLE();
  /* USER CODE BEGIN RTC_MspInit 1 */

  /* USER CODE END RTC_MspInit 1 */
  }
}

void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
{

  if(rtcHandle->Instance==RTC)
  {
  /* USER CODE BEGIN RTC_MspDeInit 0 */

  /* USER CODE END RTC_MspDeInit 0 */
    /* Peripheral clock disable */
    __HAL_RCC_RTC_DISABLE();
  /* USER CODE BEGIN RTC_MspDeInit 1 */

  /* USER CODE END RTC_MspDeInit 1 */
  }
} 


/* USER CODE BEGIN 1 */
/* USER CODE BEGIN Prototypes */
/* USER CODE END 1 */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

资料清单:

在这里插入图片描述
下载链接:
https://docs.qq.com/doc/DS2p1UktYbmlTdER6

  • 设计资料获取联系方式.doc

推荐器件

更多器件
器件型号 数量 器件厂商 器件描述 数据手册 ECAD模型 风险等级 参考价格 更多信息
CP2102N-A02-GQFN28R 1 Silicon Laboratories Inc USB Bus Controller, CMOS, QFN-28

ECAD模型

下载ECAD模型
$2.5 查看
ATXMEGA32A4U-MH 1 Microchip Technology Inc IC MCU 8BIT 32KB FLASH 44VQFN
$3.4 查看
MC56F8323VFBE 1 Freescale Semiconductor 16-bit DSC, 56800E core, 32KB Flash, 60MHz, QFP 64

ECAD模型

下载ECAD模型
$14.69 查看

相关推荐

电子产业图谱