采用dht11温湿度传感器,和pm2.5传感器,用tft液晶屏显示
做出来的实物图:
单片机源程序如下:
- #include "delay.h"
- #include "sys.h"
- #include "lcd.h"
- #include "usart.h"
- #include "led.h"
- #include "dht11.h"
- #include "ds18b20.h"
- #include "adc.h"
- unsigned char hjjc[72*6] = // ASCII
- {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xE7,0x1F,0x58,0x98,0x00,0x40,0x80,0x00,0x40,0x40,0x00,
- 0x40,0x40,0x00,0xC0,0xE3,0x00,0x78,0x60,0x00,0x40,0x50,0x02,0x40,0x50,0x04,0x40,0x48,0x08,0x40,0x46,0x10,0xC0,0x43,0x30,
- 0x30,0x42,0x20,0x8C,0x41,0x00,0x00,0x40,0x00,0x00,0x40,0x00,0x00,0x40,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"环",0*/
- …………限于本文篇幅 余下代码请从51黑下载附件…………
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0xC4,0x00,0x86,0x01,0x86,0x01,0x86,0x01,0x80,0x01,0xC0,0x00,
- 0x70,0x00,0x80,0x01,0x00,0x01,0x00,0x03,0x06,0x03,0x06,0x03,0x06,0x03,0x84,0x01,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"3",4*/
- };
- //ALIENTEK战舰STM32开发板实验13
- //TFTLCD显示实验
- //技术支持:www.openedv.com
- //广州市星翼电子科技有限公司
- extern u8 Res;
- extern u8 Res3;
- int tcont,cont=5;;
- extern __IO u16 ADC_ConvertedValue[4];
- void numstring(uint16_t Xpos, uint16_t Ypos, u32 mun,u16 BL)
- {
- shuzi24(Xpos, Ypos, &ASCII_Table24N[0+48*(mun/10)], BL);
- shuzi24(Xpos+12*1, Ypos, &ASCII_Table24N[0+48*(mun%10)], BL);
-
- }
- void numstrings(uint16_t Xpos, uint16_t Ypos, u32 mun,u16 BL)
- {
- shuzi24(Xpos, Ypos, &ASCII_Table24N[0+48*(mun/1000)], BL);
- shuzi24(Xpos+12*1, Ypos, &ASCII_Table24N[0+48*(mun%1000/100)], BL);
- shuzi24(Xpos+12*2, Ypos, &ASCII_Table24N[0+48*(mun%1000%100/10)], BL);
- shuzi24(Xpos+12*3, Ypos, &ASCII_Table24N[0+48*(mun%1000%100%10)], BL);
-
- }
- void zifuchar(uint16_t Xpos, uint16_t Ypos, u8 * mun,u16 BL)
- {
- shuzi24(Xpos, Ypos, mun, BL);
- shuzi24(Xpos+12*1, Ypos, mun+48*1, BL);
- shuzi24(Xpos+12*2, Ypos, mun+48*2, BL);
- shuzi24(Xpos+12*3, Ypos, mun+48*3, BL);
- shuzi24(Xpos+12*4, Ypos, mun+48*4, BL);
-
- }
- int main(void)
- {
- u8 humidity;
- u8 temp;
- short temperature;
- delay_init(); //延时函数初始化
- NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- uart_init(115200); //串口初始化为9600
- LED_Init();
- Adc_Init(); //adc8
- // USART3_Config();
- LCD_Init();
- POINT_COLOR=RED;
- wordstring(40, 10,hjjc,6,RED); //环境监测系统
- wordstring(10, 150,wd,2,RED); //温度
- wordstring(10, 180,sd,2,RED); // 湿度
- while(DS18B20_Init());
- while(1)
- {
- temperature=DS18B20_Get_Temp();
- if(temperature<0)
- {
- shuzi24(55, 150, fh, RED); //显示负号
- temperature=-temperature; //转为正数
- }else shuzi24(55, 150, qk, RED); //去掉负号
- //
- DHT11_Read_Data(&temp,&humidity); //读取温湿度值
- numstring(70, 150,temperature/10,BRED); //显示温度
- wordstring(100, 150,wd+72*2,1,RED); //温度符号
- numstring(70, 180,humidity,BRED); //显示湿度
- shuzi24(100, 180,sdfh,RED);shuzi24(112, 180,sdfh+48,RED);shuzi24(124, 180,sdfh+96,RED); //湿度符号
- zifuchar(5, 210,PM,RED);
- shuzi24(70, 210,&ASCII_Table24N[0+48*(Get_Adc_Average(1)/620)], BRED); //毫克量
- zifuchar(90, 210,MG,RED);
- delay_ms(200);
- }
- }
- /*代码说明*/
- /*main函数扫描按键显示放电预设值
- * 定时器3 放电定时
- * 定时器4 ad扫描
- */
复制代码
所有资料51hei提供下载:
课设环境监测系统.rar
(368.26 KB, 下载次数: 324)
|