#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "lcd.h"
#include "temperate.h"
void init()
{
delay_init(); //延时函数初始化
uart_init(9600); //串口初始化为9600
LED_Init(); //初始化与LED连接的硬件接口
LCD_Init();
T_Adc_Init();
POINT_COLOR=RED;//设置字体为红色
LCD_ShowString(60,40,200,24,24,"ADC Test ^-^");
LCD_ShowString(60,70,200,16,16,"Medium difficulty");
LCD_ShowString(60,90,200,16,16,"2015/1/25");
LCD_ShowString(60,110,200,16,16,"By--Mr yh");
//显示提示信息
POINT_COLOR=BLUE;//设置字体为蓝色
LCD_ShowString(60,130,200,16,16,"TEMP_VAL:");
LCD_ShowString(60,150,200,16,16,"TEMP_VOL:0.000V");
LCD_ShowString(60,170,200,16,16,"TEMPERATE:00.00C");
}
int main(void)
{
u16 adcnum;
float tem,temperate;
init();
while(1)
{
adcnum=T_Get_Adc_Average(ADC_CH_TEMP,10);
LCD_ShowxNum(132,130,adcnum,4,16,0);//显示ADC的值
tem=(float)adcnum*(3.3/4096);
temperate=tem;
adcnum=tem;
LCD_ShowxNum(132,150,adcnum,1,16,0);//显示电压值的整数位
tem-=(u8)tem;
LCD_ShowxNum(148,150,(u32)(tem*1000),3,16,0X80);//显示电压值的小数位
temperate=(1.43-temperate)/0.0043+25; //计算出当前温度值
LCD_ShowxNum(140,170,(u8)temperate,2,16,0); //显示温度整数部分
temperate-=(u8)temperate;
LCD_ShowxNum(164,170,temperate*100,2,16,0X80);//显示温度小数部分
LED0=!LED0;
delay_ms(250);
}
}