#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "lcd.h"
#include "ds18b20.h"
#include "key.h"
#include "stm32f10x_gpio.h"
int main(void)
{
u8 t=0;
u8 key;
u16 a=0;
u16 b=40;
short temperature;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
delay_init();
uart_init(9600);
LED_Init();
LCD_Init();
KEY_Init();
POINT_COLOR=RED;
LCD_ShowString(60,50,200,16,16,"Temperature Controller");
LCD_ShowString(60,70,200,16,16,"Upper Temp: . C");
LCD_ShowString(60,90,200,16,16,"Lower Temp: . C");
LCD_ShowString(60,110,200,16,16,"2015/6/12");
while(DS18B20_Init()) //DS18B20??????
{
LCD_ShowString(60,130,200,16,16,"DS18B20 Error");
delay_ms(200);
LCD_Fill(60,130,239,130+16,WHITE);
delay_ms(200);
}
LCD_ShowString(60,130,200,16,16,"DS18B20 OK");
POINT_COLOR=BLUE;
LCD_ShowString(60,150,200,16,16,"Temp: . C");
while(1)
{
if(t%10==0)
{
temperature=DS18B20_Get_Temp();
if(temperature<0)
{
LCD_ShowChar(60+40,150,'-',16,0);
temperature=-temperature;
}else LCD_ShowChar(60+40,150,' ',16,0);
LCD_ShowNum(60+40+8,150,temperature/10,2,16);
LCD_ShowNum(60+40+32,150,temperature%10,1,16);
key=KEY_Scan(0);
if(key==KEY0_PRES)
{
LCD_ShowxNum(164,150,a,1,16,0);
a++;
//LCD_ShowNum(164,70,5,2,16);
}
if(key==KEY1_PRES)
{
LCD_ShowxNum(164,150,b,1,16,0);
b--;
//LCD_ShowNum(60+88,90,b,2,16);
}
if(temperature<=a|temperature>=b)
GPIO_SetBits(GPIOA,GPIO_Pin_2);
else GPIO_ResetBits(GPIOA,GPIO_Pin_2);
delay_ms(10);
t++;
}
}
}
|