加入星計(jì)劃,您可以享受以下權(quán)益:

  • 創(chuàng)作內(nèi)容快速變現(xiàn)
  • 行業(yè)影響力擴(kuò)散
  • 作品版權(quán)保護(hù)
  • 300W+ 專業(yè)用戶
  • 1.5W+ 優(yōu)質(zhì)創(chuàng)作者
  • 5000+ 長(zhǎng)期合作伙伴
立即加入

基于STM32的電子鐘萬(wàn)年歷時(shí)鐘鬧鐘Proteus仿真_LCD1602顯示

07/10 09:34
4235
服務(wù)支持:
技術(shù)交流群

完成交易后在“購(gòu)買成功”頁(yè)面掃碼入群,即可與技術(shù)大咖們分享疑惑和經(jīng)驗(yàn)、收獲成長(zhǎng)和認(rèn)同、領(lǐng)取優(yōu)惠和紅包等。

虛擬商品不可退

當(dāng)前內(nèi)容為數(shù)字版權(quán)作品,購(gòu)買后不支持退換且無(wú)法轉(zhuǎn)移使用。

加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點(diǎn)資訊討論
放大
實(shí)物圖
相關(guān)方案
  • 方案介紹
  • 相關(guān)文件
  • 推薦器件
  • 相關(guān)推薦
  • 電子產(chǎn)業(yè)圖譜
申請(qǐng)入駐 產(chǎn)業(yè)圖譜

STM32電子鐘萬(wàn)年歷時(shí)鐘鬧鐘_LCD1602液晶屏 (仿真+原理圖+PCB+源碼+參考報(bào)告)
仿真:protues 8.9
程序編譯器:keil 5
編程語(yǔ)言:C語(yǔ)言
編號(hào)C0003

基本功能:

1.具有顯示年、月、日、時(shí)、分、秒功能;

2.能計(jì)算并顯示星期;

3.能手動(dòng)調(diào)整時(shí)間,設(shè)置鬧鐘;

4.具有鬧鐘功能,時(shí)間到聲光報(bào)警(蜂鳴器嘟嘟嘟,LED燈閃爍)。

文件清單:

  1. Proteus8.9 仿真圖;
  2. C語(yǔ)言源代碼,Keil5打開(kāi);
  3. Altium Designer 原理圖 源文件和PDF;
  4. Altium Designer PCB 源文件和PDF;
  5. 參考報(bào)告(論文)。

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

原理圖(提供源文件):
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);               		//3?ê??ˉ?óê±oˉêy
  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);         // 顯示關(guān)閉 
    lcd_delay_ms(4); 
    LCD_write_cmd(0x01);         // 顯示清屏 
    lcd_delay_ms(4); 
    LCD_write_cmd(0x06);         // 顯示光標(biāo)移動(dòng)設(shè)置 
    lcd_delay_ms(4);
    LCD_write_cmd(0x0c);         // 顯示開(kāi),光標(biāo)開(kāi),光標(biāo)閃爍
    lcd_delay_ms(4);
		LCD_write_cmd(0x01);         //清屏
		lcd_delay_ms(4);
}
/*--------------------------------------------------
函數(shù)說(shuō)明:寫命令到液晶


---------------------------------------------------*/
void LCD_write_cmd(unsigned char cmd)
{
    LCD_RS(0);
    LCD_Write_byte(cmd);
    lcd_delay_us(340);
}
/*--------------------------------------------------
函數(shù)說(shuō)明:寫數(shù)據(jù)到液晶


---------------------------------------------------*/
void LCD_write_data(unsigned char w_data)
{
    LCD_RS(1);
    LCD_Write_byte(w_data);
    lcd_delay_us(340);
}
/*--------------------------------------------------
函數(shù)說(shuō)明:寫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        : 設(shè)置LCD顯示的起始位置
輸入?yún)?shù):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  : 英文字符串顯示函數(shù)
輸入?yún)?shù):*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

  • 設(shè)計(jì)資料獲取聯(lián)系方式.doc

推薦器件

更多器件
器件型號(hào) 數(shù)量 器件廠商 器件描述 數(shù)據(jù)手冊(cè) ECAD模型 風(fēng)險(xiǎn)等級(jí) 參考價(jià)格 更多信息
MK70FN1M0VMJ15 1 Freescale Semiconductor Kinetis K 32-bit MCU, ARM Cortex-M4 core, 1MB Flash, 150MHz, Graphics LCD, MAPBGA 256

ECAD模型

下載ECAD模型
$18.16 查看
STM32H757XIH6TR 1 STMicroelectronics RISC Microcontroller
暫無(wú)數(shù)據(jù) 查看
STM32H743XIH6 1 STMicroelectronics High-performance and DSP with DP-FPU, Arm Cortex-M7 MCU with 2MBytes of Flash memory, 1MB RAM, 480 MHz CPU, Art Accelerator, L1 cache, external memory interface, large set of peripherals

ECAD模型

下載ECAD模型
$31.15 查看

相關(guān)推薦

電子產(chǎn)業(yè)圖譜