CAUVERY
Newbie level 1
Hello everyone,am beginner to the microcontroller programming. am working on temperature controlled heater relay using pic16f887 in hitech compiler and display the temperature in seven segment. am using LM35 sensor.so when the process starts heater relay will be on, whenever temperature is greater than 100 the heater relay should switch off(when heater relay off--temperature drops below 100 after certain time and again relay on). am getting correct output up to this level of code. now i want to switch on/off heater only two times i.e when temperature goes greater than 100 for third time the relay should permanently switch off.so i add flag varaible to count the operation but unfortunately in my code increment operator doesn't work inside the condition and relay on/off occurs only first time. what should do to on/off twice.
In simple words I can say.
(1st time--process starts--temperature rising--relay on--temperature rise>100--relay off--temperature drops below 100--again relay on--2nd time--temperature rise>100--relay off permanently(dont care about the temperature drop)
if i get guidance what can be done to solve this issue, it will be more helpful, here i attached my code..
In simple words I can say.
(1st time--process starts--temperature rising--relay on--temperature rise>100--relay off--temperature drops below 100--again relay on--2nd time--temperature rise>100--relay off permanently(dont care about the temperature drop)
if i get guidance what can be done to solve this issue, it will be more helpful, here i attached my code..
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 #include<htc.h> __CONFIG(0x20F2); __CONFIG(0x3055); #define _XTAL_FREQ 12000000 #define D1 RD0 #define D2 RD1 #define D3 RD2 #define D4 RD3 void ADC_Initialize() { ADCON0 = 0b01010001; ADCON1 = 0b11000000; } unsigned int ADC_Read(unsigned char channel) { GO_nDONE = 1; while(GO_nDONE); return ((ADRESH<<8)+ADRESL); } void main() { unsigned int i,a,b,c,d,e,f,g,h,adc; int flag=0; unsigned int seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; TRISC=0x00; TRISD=0x10; ADC_Initialize(); while(1) { adc = (ADC_Read(4)); k = adc*0.488281; if(k>100) //temperature greater than 100 { flag=flag+1; // increment if(flag>=0 && flag<4) RD6=0; //relay permanently off } else { RD6=1; //temperature less than 100-relay on } a=k%10; b=k/10; PORTC=seg[a];D1=1; __delay_ms(5);D1=0; c=b%10; d=b/10; PORTC=seg[c];D2=1; __delay_ms(5);D2=0; e=d%10; f=d/10; PORTC=seg[e];D3=1; __delay_ms(5);D3=0; g=f%10; h=f/10; PORTC=seg[g];D4=1; __delay_ms(5);D4=0; } }
Last edited by a moderator: