temperature controlled fan

General discussion on mikroC.
Post Reply
Author
Message
co6alt
Posts: 2
Joined: 16 Apr 2018 08:31

temperature controlled fan

#1 Post by co6alt » 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

User avatar
marko.stankovic
mikroElektronika team
Posts: 108
Joined: 18 Dec 2017 15:44

Re: temperature controlled fan

#2 Post by marko.stankovic » 18 Apr 2018 09:10

Hi,

I tested your code on the EasyPIC v7 development board and it worked properly.
Can you please attach a project in a zip archive?
Also, could you tell me which LCD you are using?

Best regards,
Marko Stankovic.

co6alt
Posts: 2
Joined: 16 Apr 2018 08:31

Re: temperature controlled fan

#3 Post by co6alt » 18 Apr 2018 12:09

hello thanks for replying. firstly, i played with the code a little bit after posting this so i managed to fix most of the problems. But only two remains now. A) is that the temperature sensor(LM35) is still not giving accurate reading even after putting the potentiometer code as comments. if i un-comment the code it'll allow me to control the sensor from the potentiometer but it shouldnt be so im still trying to find out why. B) the fan is still not working but i havent worked on it yet because i still have A to solve.

Secondly, i tried my code in proteus 8 and it worked just fine i dont know why in the implementation in the circuit is not working

Thirdly, i updated the code a little bit so just a heads up.

As for the lcd im using LM016L but that is not an issue anymore. youll find the code attached. thank you.
Attachments
fan.rar
(47.42 KiB) Downloaded 141 times

Post Reply

Return to “mikroC General”