/* Buildmet project 27-12-06. Modified for Dryspell by KS Natarajan. Additions tower drying LED and timing change
Suitable for PCB DSP Vr 1.11
WHEN switch is open pin 13 is 5 volt. The dew point poor-->cycle not stretched-->the cycle will be continued
WHEN switch is shorted pin 13 is 0 volt the dew point good-->cycle stretch -->the cycle will hold at the present state
// Progarm timings changed for UL controller model DS31-200. modification done by vignesh on 15/12/2010
*/
#include<htc.h>
#define PB(p,b) ((unsigned)&(p)*8+(b))
#define gen_init() PORTA=0,PORTC=0,TRISA=0x0c,TRISC=0,CMCON=0x07,OSCCAL=0xff,OPTION=0X80,\
INTCON=0,IOCA=0,PIE1=0;T1CON=0x00,VRCON=0;
bit dew_input @ PB(PORTA,2); //
bit switch1 @ PB(PORTA,3); //
bit PIN2_led1 @ PB(PORTA,5); //
bit PIN3_led2 @ PB(PORTA,4); //
bit PIN5_led6 @ PB(PORTC,5);
bit PIN10_led9 @ PB(PORTC,0);
bit Dewpoint_Switch @ PB(PORTA,0); // This is actually pin 13
bit PIN12_led10 @ PB(PORTA,1); //
bit PIN6_40_percent_led3 @ PB(PORTC,4);
bit PIN7_60_percent_led4 @ PB(PORTC,3); //
bit PIN8_80_percent_led5 @ PB(PORTC,2); //
bit PIN9_100_percent_led7 @ PB(PORTC,1); //
#define preload_tmr1() TMR1H=0x15,TMR1L=0x50; //0.5 sec delay
#define init_tmr1() T1CON=0x00,PIE1=0x01,PEIE=1;
#define enable_tmr1 TMR1ON=1;
#define disable_tmr1 TMR1ON=0;
unsigned char sw_count,count,data,tensec_count,sec_count;
unsigned int min_count,min_5_count;
bit sec_7_flag,dew_flag,init_flag,dec_flag;
void eeprom_write1(void)
{
EECON1=0;
EEIF=0;
EEADR=0x05;
EEDATA=sw_count; //LS BYTES pulse_width DATA save
WREN=1;
EECON2=0x55;
EECON2=0xaa;
WR=1;
while(!EEIF);
asm("nop");
}
void eeprom_read1(void)
{
EEADR=0x05;
EEDATA=0;
EECON1=0;
RD=1;
while(RD);
data=EEDATA;
}
void led_set1(void)
{
PIN3_led2=0;
PIN2_led1=0;
PIN5_led6=0;
PIN10_led9=0;
Dewpoint_Switch=1;
PIN12_led10=0;
}
void led_set2(void)
{
PIN3_led2=0;
PIN2_led1=1;
PIN5_led6=0;
PIN10_led9=1; //PIN10(INLET VLAVE) changed from 0 to 1.on 15/12/2010 by vignesh due to programm for UL controller model DS31-200
Dewpoint_Switch=0;
PIN12_led10=1;
}
void led_set3(void)
{
PIN3_led2=1;
PIN2_led1=0;
PIN5_led6=0;
PIN10_led9=1; //PIN10(INLET VLAVE) changed from 0 to 1.on 28/12/2010 by vignesh due to programm for UL controller model DS31-200
Dewpoint_Switch=0;
PIN12_led10=1;
}
void led_set4(void)
{
PIN3_led2=0;
PIN2_led1=0;
PIN5_led6=1;
PIN10_led9=0;
Dewpoint_Switch=0;
PIN12_led10=0;
}
void led_set5(void)
{
PIN3_led2=0;
PIN2_led1=0;
PIN5_led6=0;
PIN10_led9=0; //PIN10(INLET VLAVE) changed from 1 to 0.on 28/12/2010 by vignesh due to programm for UL controller model DS31-200
Dewpoint_Switch=1;
PIN12_led10=0;
}
void interrupt isr(void)
{
if(TMR1IF)
{
TMR1IF=0;
preload_tmr1();
if(sec_count++>21) //20
{
sec_count=0;
if(!dew_flag) //If dew_flag is true it means dew point is good and timing will not be incremented. stretch
min_count++; // Dew point poor and timing incremented
if(min_count>=240)
min_count=0;
}
if(!switch1)
count++;
if(switch1)
count=0;
tensec_count--;
if(tensec_count==0)
{
sec_7_flag=0;
count=0;
}
if(count>=70)
{
sec_7_flag=1;
tensec_count=200;
count=0;
}
switch(sw_count)
{
case 1:
PIN6_40_percent_led3=1;
PIN9_100_percent_led7=0;
if(min_count<=2)
led_set5();
else if(min_count>2 && min_count<84)
led_set1();
else if(min_count==84)
{led_set1();
if(dew_input) {dew_flag=0;}
else {dew_flag=1;}
}
else if(min_count>=85 && min_count<=120)
led_set2();
else if(min_count>121 && min_count<204)
led_set3();
else if(min_count==204)
{
led_set3();
if(dew_input) {dew_flag=0;}
else {dew_flag=1;}
}
else if(min_count>205 && min_count<=240 )
led_set4();
break;
case 2:
PIN7_60_percent_led4=1;
PIN6_40_percent_led3=0;
if(min_count<=2)
led_set5();
else if(min_count>2 && min_count<66)
led_set1();
else if(min_count==66)
{
led_set1();
if(dew_input) {dew_flag=0;}
else {dew_flag=1;}
}
else if(min_count>=67 && min_count<=120)
led_set2();
else if(min_count>121 && min_count<186)
led_set3();
else if(min_count==186)
{
led_set3();
if(dew_input) {dew_flag=0;}
else {dew_flag=1;}
}
else if(min_count>187 && min_count<=240 )
led_set4();
break;
case 3:
PIN8_80_percent_led5=1;
PIN7_60_percent_led4=0;
if(min_count<=2)
led_set5();
else if(min_count>2 && min_count<48)
led_set1();
else if(min_count==48)
{
led_set1();
if(dew_input) {dew_flag=0;}
else {dew_flag=1;}
}
else if(min_count>=49 && min_count<=120)
led_set2();
else if(min_count>121 && min_count<168)
led_set3();
else if(min_count==168)
{
led_set3();
if(dew_input) {dew_flag=0;}
else {dew_flag=1;}
}
else if(min_count>169 && min_count<=240 )
led_set4();
break;
case 4:
PIN9_100_percent_led7=1;
PIN8_80_percent_led5=0;
if(min_count<=2)
led_set5();
else if(min_count>2 && min_count<30)
led_set1();
else if(min_count==30)
{
led_set1();
if(dew_input) {dew_flag=0;}
else {dew_flag=1;}
}
else if(min_count>=31 && min_count<=120)
led_set2();
else if(min_count>121 && min_count<150)
led_set3();
else if(min_count==150)
{
led_set3();
if(dew_input) {dew_flag=0;}
else {dew_flag=1;}
}
else if(min_count>151 && min_count<=240 )
led_set4();
break;
} //end of switch
}
}
void main(void)
{
gen_init();
init_tmr1();
GIE=1;
PIN3_led2=0;
PIN2_led1=0;
PIN5_led6=0;
dew_flag=0;
sec_7_flag=0;
PIN10_led9=0;
//Dewpoint_Switch=0;
PIN12_led10=0;
PIN6_40_percent_led3=0;
PIN7_60_percent_led4=0;
PIN8_80_percent_led5=0;
PIN9_100_percent_led7=0;
preload_tmr1();
min_5_count=0;
sw_count=4;
init_flag=1;
min_5_count=0;
eeprom_read1();
if(data==0xff)
sw_count=4;
else
sw_count=data;
enable_tmr1;
while(1)
{
if(sec_7_flag||init_flag)
{
while(tensec_count||init_flag)
{
init_flag=0;
if(!switch1)
{
while(!switch1);
sw_count++;
if(sw_count>=5)
sw_count=1;
min_count=0;
eeprom_write1();
tensec_count=200;
}
}
}
}
}