主函数ds18b20.h
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "lcd.h"
#include "ds18b20.h"
int main(void)
{undefined
u8 t=0;
short temperature;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组 2
delay_init(168); //初始化延时函数
uart_init(115200); //初始化串口波特率为 115200
LED_Init(); //初始化 LED
LCD_Init();
POINT_COLOR=RED;//设置字体为红色
LCD_ShowString(30,50,200,16,16,"ALIX");
LCD_ShowString(30,70,200,16,16,"DS18B20 TEST");
LCD_ShowString(30,90,200,16,16,"ALIX");
LCD_ShowString(30,110,200,16,16,"2018/7/22");
while(DS18B20_Init()) //DS18B20 初始化
{undefined
LCD_ShowString(30,130,200,16,16,"DS18B20 Error");
delay_ms(200);
LCD_Fill(30,130,239,130+16,WHITE);
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)
{undefined
if(t%10==0)//每 100ms 读取一次
{undefined
temperature=DS18B20_Get_Temp();
if(temperature<0)
{undefined
LCD_ShowChar(30+40,150,'-',16,0); //显示负号
temperature=-temperature; //转为正数
}else LCD_ShowChar(30+40,150,' ',16,0); //去掉负号
LCD_ShowNum(30+40+8,150,temperature/10,2,16); //显示正数部分
LCD_ShowNum(30+40+32,150,temperature%10,1,16); //显示小数部分
}
delay_ms(10); t++;
if(t==20)
{undefined
t=0; LED0=!LED0;
}
}
|