- #include "stm32f4xx.h"
- #include "delay.h"
- #include "usart.h"
- #include "LED.h"
- #include "lcd.h"
- #include "Key.h"
- #include "usmart.h"
- #include "DS18B20.h"
-
- //LCD状态设置函数
- void led_set(u8 sta)//只要工程目录下有usmart调试函数,主函数就必须调用这两个函数
- {
- LED1=sta;
- }
- //函数参数调用测试函数
- void test_fun(void(*ledset)(u8),u8 sta)
- {
- led_set(sta);
- }
-
- int main(void)
- {
- u8 t=0;
- short temperature;
- delay_init(168);
- uart_init(115200);
-
- LED_Init();
- LCD_Init();
- POINT_COLOR=RED;
- LCD_ShowString(30,50,200,16,16,"Explorer STM32F4");
- LCD_ShowString(30,70,200,16,16,"DS18B20 Test");
- LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
- LCD_ShowString(30,110,200,16,16,"2023/06/22");
-
- while(DS18B20_Init()) //初始化返回值是检验DS18B20能否被开发板检测到,返回1也就是未检测到DS18B20
- {
- LCD_ShowString(30,130,200,16,16,"DS18B20 ERROR");
- delay_ms(200);
- LCD_Fill(30,130,239,130+16,WHITE); //清屏,清屏的范围是:x 30~239;y 130~130+16,也就是左边130行往下清两行
- delay_ms(200);
- }
- LCD_ShowString(30,130,200,16,16,"DS18B20 OK");
- POINT_COLOR=BLUE;
- LCD_ShowString(30,150,200,16,16,"Temp: . C");
- while(1)
- {
- if(t%10==0) //每100ms读取一次
- {
- temperature=DS18B20_Get_Temperature(); //调用读取温度函数,将读到的十进制数赋值给temperature
- if(temperature<0) //温度为负
- {
- LCD_ShowChar(30+5*8,150,'-',16,0); //显示负号
- temperature=-temperature; //负数变正数
- }
- else
- {
- LCD_ShowChar(30+5*8,150,' ',16,0); //去掉负号
- }
- LCD_ShowNum(30+5*8+8,150,temperature/10,2,16); //显示整数位
- //30+5*8+8:30起始坐标,5*8表示Temp:占用的字节,8表示的是符号位占用的字节
- LCD_ShowNum(30+5*8+4*8,150,temperature%10,1,16); //显示小数部分
- }
- delay_ms(10);
- t++;
- if(t==20)
- {
- t=0;
- LED0=!LED0;
- }
- }
- }
-
-
-