资讯详情

STM32电子钟万年历Proteus仿真_LCD1602显示

STM三十二电子钟万年历Proteus仿真_LCD1602液晶屏 (仿真 原理图 PCB 源码 报告) 仿真:protues 8.9 程序编译器:keil 5 编程语言:C语言 编号C0003

数据文件下载链接: https://pan.baidu.com/s/1Sz10LAfeCJrHctztBF4vdA?pwd=3f17  提取码:3f17  

基本功能: 1.具有显示年、月、日、时、分、秒的功能; 2.能计算和显示周; 3.可手动调整时间; 4.闹钟功能。

文件清单:

  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);
}
/*-------------------------------------------------- 函数说明:写命令到液晶 ---------------------------------------------------*/
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++;
    }
}

资料清单:

标签: 贴片二极管丝印f17

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台