temperature controlled fan
Posted: 16 Apr 2018 08:51
hello. so i have a problem with the code. im using the following:
MikroC application
pic and pickit2
pic16f887
lm35
two potentiometer
lcd
fan
this is the program:
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections
//variables
char Txt[7];
float Temp_Ref ;
unsigned int temp;
float mV, ActualTemp;
unsigned char inTemp;
//end variables
void main() {
//configuration
TRISA=0xff;
trisB=0x1f;
TRISD=0;
trisc=0;
ansel=0x03;
anselh=0x00;
//end configuration
// lcd part 1
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1, 4, "Automatic");
Lcd_Out(2, 2, "Temp Control");
delay_ms(1000);
//end lcd part 1
// fan off
portd.f0=0;
Lcd_Cmd(_LCD_CLEAR);
while(1)
{
// ADC
temp = ADC_Read(0);
mV = temp * 5000.0/1024.0;
ActualTemp = mV/10.0 ;
Temp_Ref=ActualTemp;
//end ADC
Lcd_Out(1, 1, "Enter Temp");
FloatToStr( Temp_Ref,Txt);
Lcd_Out(1,10,Txt);
Lcd_Chr(1,15,223);
Lcd_Chr(1,16,'C');
Lcd_Out(2, 1, "Temp= ");
FloatToStr(ActualTemp,Txt);
Txt[4] = 0;
Lcd_Out(2,7,Txt);
Lcd_Out(2,12," ");
if (Temp_Ref > ActualTemp){portd.f0=0;}
if (Temp_Ref < ActualTemp){portd.f0=1;}
if (Temp_Ref == ActualTemp){portd.f0=0;}
Delay_ms(2000);
}
}
the idea is if the temperature is above the wanted temperature. the fan will turn on. if not it's off.
the display should display "automatic temprature" and then "enter temp". and i should enter the temp from the potentiometer.
the problem im having is : first the code is skipping "automatic..."
secondly the lcd displays "enter tem(and b/w the brackets its displaying the temperature of the lm35sensor)"
the connection is fine. but the problem is with the code that i cant figure out.
thanks to whoever tries to help and sorry for my long post
MikroC application
pic and pickit2
pic16f887
lm35
two potentiometer
lcd
fan
this is the program:
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections
//variables
char Txt[7];
float Temp_Ref ;
unsigned int temp;
float mV, ActualTemp;
unsigned char inTemp;
//end variables
void main() {
//configuration
TRISA=0xff;
trisB=0x1f;
TRISD=0;
trisc=0;
ansel=0x03;
anselh=0x00;
//end configuration
// lcd part 1
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1, 4, "Automatic");
Lcd_Out(2, 2, "Temp Control");
delay_ms(1000);
//end lcd part 1
// fan off
portd.f0=0;
Lcd_Cmd(_LCD_CLEAR);
while(1)
{
// ADC
temp = ADC_Read(0);
mV = temp * 5000.0/1024.0;
ActualTemp = mV/10.0 ;
Temp_Ref=ActualTemp;
//end ADC
Lcd_Out(1, 1, "Enter Temp");
FloatToStr( Temp_Ref,Txt);
Lcd_Out(1,10,Txt);
Lcd_Chr(1,15,223);
Lcd_Chr(1,16,'C');
Lcd_Out(2, 1, "Temp= ");
FloatToStr(ActualTemp,Txt);
Txt[4] = 0;
Lcd_Out(2,7,Txt);
Lcd_Out(2,12," ");
if (Temp_Ref > ActualTemp){portd.f0=0;}
if (Temp_Ref < ActualTemp){portd.f0=1;}
if (Temp_Ref == ActualTemp){portd.f0=0;}
Delay_ms(2000);
}
}
the idea is if the temperature is above the wanted temperature. the fan will turn on. if not it's off.
the display should display "automatic temprature" and then "enter temp". and i should enter the temp from the potentiometer.
the problem im having is : first the code is skipping "automatic..."
secondly the lcd displays "enter tem(and b/w the brackets its displaying the temperature of the lm35sensor)"
the connection is fine. but the problem is with the code that i cant figure out.
thanks to whoever tries to help and sorry for my long post