基于stm32温湿度 LCD可显示学号姓名
单片机源程序如下:
- #include "sys.h"
- #include "delay.h"
- #include "usart.h"
- #include "led.h"
- #include "lcd.h"
- #include "key.h"
- #include "usmart.h"
- #include "malloc.h"
- #include "sdio_sdcard.h"
- #include "w25qxx.h"
- #include "ff.h"
- #include "exfuns.h"
- #include "text.h"
- #include "rtc.h"
- #include "beep.h"
- #include "dht11.h"
- int main(void)
- {
- // u32 fontcnt;
- // u8 i,j;
- // u8 fontx[2];//gbk码
- u8 key1;
- u8 t=0;
- u8 t1=0;
- u8 j=30;
- u8 temperature;
- u8 humidity;
- BEEP_Init();
- delay_init(); //延时函数初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
- uart_init(115200); //串口初始化为115200
- usmart_dev.init(72); //初始化USMART
- LED_Init(); //初始化与LED连接的硬件接口
- KEY_Init(); //初始化按键
- LCD_Init(); //初始化LCD
- RTC_Init();
- DHT11_Init();
- W25QXX_Init(); //初始化W25Q128
- my_mem_init(SRAMIN); //初始化内部内存池
- exfuns_init(); //为fatfs相关变量申请内存
- f_mount(fs[0],"0:",1); //挂载SD卡
- f_mount(fs[1],"1:",1); //挂载FLASH.
- while(font_init()) //检查字库
- {
- //UPD:
- LCD_Clear(WHITE); //清屏
- POINT_COLOR=RED; //设置字体为红色
- LCD_ShowString(30,50,200,16,16,"WarShip STM32");
- while(SD_Init()) //检测SD卡
- {
- LCD_ShowString(30,70,200,16,16,"SD Card Failed!");
- delay_ms(200);
- LCD_Fill(30,70,200+30,70+16,WHITE);
- delay_ms(200);
- }
- LCD_ShowString(30,70,200,16,16,"SD Card OK");
- LCD_ShowString(30,90,200,16,16,"Font Updating...");
- key1=update_font(20,110,16,"0:");//更新字库
- while(key1)//更新失败
- {
- LCD_ShowString(30,110,200,16,16,"Font Update Failed!");
- delay_ms(200);
- LCD_Fill(20,110,200+20,110+16,WHITE);
- delay_ms(200);
- }
- LCD_ShowString(30,110,200,16,16,"Font Update Success! ");
- delay_ms(1500);
- LCD_Clear(WHITE);//清屏
- }
- POINT_COLOR=RED;
- Show_Str(150,50,200,24,"温湿度检测系统",24,0);
- POINT_COLOR=BLUE;
- Show_Str(60,350,240,24,"学号:",24,0);
- Show_Str(60,310,200,24,"姓名\",24,0);
- LCD_ShowString(60,240,200,24,24,"Temp: C");
- LCD_ShowString(60,270,200,24,24,"Humi: %");
- while(1)
- {
- if(t!=calendar.sec)
- {
- t=calendar.sec;
- LCD_ShowNum(60,130,calendar.w_year,4,24);
- LCD_ShowNum(120,130,calendar.w_month,2,24);
- LCD_ShowNum(150,130,calendar.w_date,2,24);
- switch(calendar.week)
- {
- case 0:
- Show_Str(60,210,200,24,"星期天 ",24,0);
- break;
- case 1:
- Show_Str(60,210,200,24,"星期一 ",24,0);
-
- break;
- case 2:
- Show_Str(60,210,200,24,"星期二 ",24,0);
- // LCD_ShowString(60,210,200,24,24,"星期二 ");
- break;
- case 3:
- Show_Str(60,210,200,24,"星期三 ",24,0);
- // LCD_ShowString(60,210,200,24,24,"星期三 ");
- break;
- case 4:
- Show_Str(60,210,200,24,"星期四 ",24,0);
- // LCD_ShowString(60,210,200,24,24,"星期四 ");
- break;
- case 5:
- Show_Str(60,210,200,24,"星期五 ",24,0);
- // LCD_ShowString(60,210,200,24,24,"星期五 ");
- break;
- case 6:
- Show_Str(60,210,200,24,"星期六 ",24,0);
- // LCD_ShowString(60,210,200,24,24,"Saturday ");
- break;
- }
- LCD_ShowNum(60,170,calendar.hour,2,24);
- LCD_ShowNum(90,170,calendar.min,2,24);
- LCD_ShowNum(120,170,calendar.sec,2,24);
- LED0=!LED0;
- }
- delay_ms(10);
- LED0=!LED0;
- if(t1%10==0) //每100ms读取一次
- {
- DHT11_Read_Data(&temperature,&humidity); //读取温湿度值
- LCD_ShowNum(60+60,240,temperature,2,24); //显示温度
- LCD_ShowNum(60+60,270,humidity,2,24); //显示湿度
- if(temperature>=j)
- {
- BEEP=~BEEP;
- delay_ms(20);
- }
- }
- delay_ms(10);
- t1++;
- if(t1==20)
- {
- t1=0;
- LED0=!LED0;
- }
- }
- }
复制代码
所有资料51hei提供下载:
温湿度.rar
(1.69 MB, 下载次数: 176)
|