加入星計劃,您可以享受以下權益:

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

基于STM32的電子鐘萬年歷時鐘鬧鐘Proteus仿真_LCD1602顯示

07/10 09:34
4697
服務支持:
技術交流群

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

虛擬商品不可退

當前內容為數(shù)字版權作品,購買后不支持退換且無法轉移使用。

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

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);               		//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);         // 顯示關閉 
    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);
}
/*--------------------------------------------------
函數(shù)說明:寫命令到液晶


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


---------------------------------------------------*/
void LCD_write_data(unsigned char w_data)
{
    LCD_RS(1);
    LCD_Write_byte(w_data);
    lcd_delay_us(340);
}
/*--------------------------------------------------
函數(shù)說明:寫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顯示的起始位置
輸入?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

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

推薦器件

更多器件
器件型號 數(shù)量 器件廠商 器件描述 數(shù)據(jù)手冊 ECAD模型 風險等級 參考價格 更多信息
ATXMEGA32E5-M4U 1 Microchip Technology Inc IC MCU 8BIT 32KB FLASH 32UQFN

ECAD模型

下載ECAD模型
$2.73 查看
ATXMEGA128A4U-MHR 1 Atmel Corporation RISC Microcontroller, 16-Bit, FLASH, AVR RISC CPU, 32MHz, CMOS, PQCC44, 7 X 7 MM, 1 MM HEIGHT, 0.50 MM PITCH, GREEN, PLASTIC, MO-220VKKD-3, VQFN-44
$4.48 查看
SAK-XC164CS-16F40FBB 1 Infineon Technologies AG Microcontroller, 16-Bit, FLASH, 40MHz, CMOS, PQFP100, 0.50 MM PITCH, GREEN, PLASTIC, TQFP-100
暫無數(shù)據(jù) 查看

相關推薦

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