#include "ioconfig.h"
#include "1602.h"
#include "USART.h"
#include "18B20.h"
#include "stdio.h"
#include "pwm.h"
#include "pid.h"
#include "keypad.h"
#include "delay12.h"
uchar dis_buf[8];
uchar temp[]="";
bit welcome_flag=0;
void LCD_Numpwm(uchar x,uchar y,uint dataw)
{
Num[0]=dataw%1000/100+'0';
Num[1]=dataw%100/10+'0';
Num[2]=dataw%10+'0';
Num[3]=' ';
Num[4]='\0';
LCD_Str(x,y,Num);
}
void compare_temper()
{
unsigned char i;
if(set_temper>temper)
{
if(set_temper-temper>50)
{
pwm_set(100);
LCD_Numpwm(4,1,100);
}
else
{
for(i=0;i<10;i++)
{
rin=Temp_Change();
rout = PIDCalc ( &spid,rin );
}
if(rout>=100) rout=100;
if(rout<=10) rout=10;
pwm_set(rout);
}
LCD_Str(12,1,"run!");
}
else if(set_temper<=temper)
{
pwm_set(0);
LCD_Str(12,1,"stop");
}
}
void welcome_menu(void)
{
LCD_Write(CMD,0X01);
LCD_Str(0,0," Welcome!");
LCD_Str(0,1," enter to menu");
while(!welcome_flag)
{
if(keyscan()=='9')
{
LCD_Write(CMD,0X01);
LCD_Str(0,0,"T: T0:");
LCD_Str(0,1,"Pwm: %");
welcome_flag=1;
}
}
pwm_set(0); // set_temper=500; pwm_set(50);
// LCD_Num(10,0,set_temper);
}
void cleanbuf(void)
{
unsigned char i;
for(i=0;i<16;i++)
{
temp[i]='\0';
}
}
void Sys_Init(void)
{
LCD_Init();
UsartInit();
Timer0Init();
PIDBEGIN();
}
void main(void)
{
uchar i=0;
bit shezhi=0;
Sys_Init();
welcome_menu();
while(1)
{
temp[0]=keyscan();
if(temp[0]=='9')
{
cleanbuf();
shezhi=1;
LCD_Write(CMD,0X01);
LCD_Str(0,0,"Put in set_T:");
LCD_Char(9,1,0xdf);
LCD_Char(10,1,'C');
while(shezhi)
{
delay_ms(50);
temp[i]=keyscan();
if(temp[i]!=0xf0)
{
LCD_Char(6+i,1,temp[i]);
i++;
if(i>=2)
{
i=0;
shezhi=0;
set_temper=((temp[0]-0x30)*10+(temp[1]-0x30))*10;
delay_ms(100);
LCD_Write(CMD,0X01);
LCD_Str(0,0,"T: T0:");
LCD_Str(0,1,"Pwm: %");
LCD_Num(10,0,set_temper);
// break;
}
}
}
}
temper=Temp_Change();
compare_temper();
}
}
|