Qaisar Azeemi
Full Member level 5
- Joined
- Feb 11, 2011
- Messages
- 315
- Helped
- 16
- Reputation
- 32
- Reaction score
- 15
- Trophy points
- 1,298
- Location
- Peshawar, Pakistan, Pakistan
- Activity points
- 3,829
#define enter PORTD.F0
AND
TRISD.F0=1;
how to declear port D of pic16f877a as input??? kindly guide me about this.... i have decleard it as :
Code:#define enter PORTD.F0 AND TRISD.F0=1;
IS this a true declearation???
// OUTPUTS
#define gen_cont PORTE.f2
#define led PORTB.f2
#define main_cont PORTC.F0
#define chowk PORTC.F1
#define ignition PORTC.F2
#define self PORTC.F3
// INPUTS
#define genr PORTA.F0
#define mains PORTA.F1
//.........button connections..........
#define enter PORTD.F0
#define reset PORTD.F1
#define up PORTD.F2
#define down PORTD.F3
//CONSTANTS
#define t 100 //DELAYS
#define P 1 //FOR MAIN AND gen INPUTS
#define A 0 //FOR MAIN AND gen INPUTS
#define ms 150 // for button debounce
//============Start LCD Connections========================================
sbit LCD_RS at RD5_bit;
sbit LCD_EN at RD4_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 TRISD5_bit;
sbit LCD_EN_Direction at TRISD4_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 Connections=============================================
//============= START RAM SAVER ===========================================
const char wu[] = "Warming up.....";
const char fv[] = "Frequency Volts";
const char error[] = "< ERROR >";
const char f2s[] = "Fails to start";
const char st[] = "Shenztech";
const char pl[] = "Pvt Ltd";
const char mna[] = "Mains not avail";
const char sg[] = "Starting Genset";
const char mok[] = "Mains OK..";
const char mol[] = "Mains Overload";
const char pw[] = "Please Wait...";
const char gwt[] = "Gen Warm up time";
const char sont[] = "Self ON Time";
const char soft[] = "Self OFF time";
const char ep[] = "Enter Passward";
const char asteric[] = "*";
const char sp[] = "scroll please";
const char sav[] = "Saving.......";
//============= END RAM SAVER ===========================================
int x=0, inc=0, opt=1, gen_wt=10, self_ont=2, self_oft=5;
char string[7]; // to dispaly integers stored in eeprom
char msg[17]; //declare array set 16 bytes of RAM aside for copying into
// copy const to ram string
char *CopyConst2Ram(char * dest, const char * src)
{
char * d ;
d = dest;
for(;*dest++ = *src++;);
return d;
}
unsigned char cnt;
void gen(void);
void start(void);
int scroll_up( int opt, int inc);
int scroll_down( int opt, int inc );
void interrupt()
{
if(TMR0IF_bit)
{ cnt++;
TMR0IF_bit=0;
if(cnt>=10)
{
led=~led;
cnt=0;
}
TMR0=0;
}
}
//-----------------------scroll up ...........................................
scroll_up(int opt ,int inc )
{
int j=1;
inc++;
if(opt==1)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
if(inc==0)
Lcd_Out(1,1,CopyConst2Ram(msg,gwt));
if(inc==1)
Lcd_Out(1,1,CopyConst2Ram(msg,sont));
if(inc==2)
Lcd_Out(1,1,CopyConst2Ram(msg,soft));
} //end if opt = 1
if(opt==0)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
//..................inc=0...gen_wt...............................
if(inc==0)
{
x=gen_wt;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==0) && (down==1) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x++;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
gen_wt=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
} while(j);
}// if inc=0
//....................inc = 1......self_ont..............
if(inc==1)
{
x=self_ont;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==0) && (down==1) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x++;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_ont=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
} while(j);
}// if inc=1
//.....................inc=2................self_oft..................................
if(inc==2)
{
x=self_oft;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==0) && (down==1) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x++;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_oft=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
inc=0;
} while(j);
}// if inc=2
} // if opt = 0
return (inc);
} // end scroll up
//-----------------------scroll Down ...........................................
scroll_down( int opt , int inc )
{
int j=1;
inc--;
if(opt==1)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
if(inc==0)
Lcd_Out(1,1,CopyConst2Ram(msg,gwt));
if(inc==1)
Lcd_Out(1,1,CopyConst2Ram(msg,sont));
if(inc==2)
Lcd_Out(1,1,CopyConst2Ram(msg,soft));
} //end if opt = 1
if(opt==0)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
//..................inc=0....gen_wt......................
if(inc==0)
{
x=gen_wt;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==1) && (down==0) && j==1)//(Button(&PORTD,2,ms,0)&&j) // down pressed
{ Delay_ms(ms); // wait for switch debounce
x--;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
gen_wt=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
} while(j);
}// if inc=0
//....................inc = 1......self_ont..............
if(inc==1)
{
x=self_ont;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==1) && (down==0) && j==1)//(Button(&PORTD,2,ms,0)&&j) // down pressed
{ Delay_ms(ms); // wait for switch debounce
x--;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_ont=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
} while(j);
}// if inc=1
//.................inc=2..........self_oft..................................
if(inc==2)
{
x=self_oft;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==1) && (down==0) && j==1)//(Button(&PORTD,2,ms,0)&&j) // down pressed
{ Delay_ms(ms); // wait for switch debounce
x--;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_oft=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
inc=0;
} while(j);
}// if inc=2
} // if opt = 0
return (inc);
} // end scroll down
//..............generator routine...............................................
gen()
{
int i;
main_cont=0;
ignition=1;
Delay_ms(2000);
chowk=1;
Delay_ms(5000);//chowk on for 5 seconds
chowk=0;
for(i=0; i<3; i++)
{
if(mains==P) //if Main resumes
{
i=3;
gen_cont=0;
ignition=0;
self=0;
Delay_ms(2000); //self on for 2 seconds
main_cont=1;
}
if(i==2)
{
chowk=1;
Delay_ms(5000);//chowk on for 5 seconds
chowk=0;
}
self=1;
Delay_ms(2000); //self on for 2 seconds
self=0;
Delay_ms(4000); //self off for 4 seconds
if(genr==P) //if generator ON
{
i=3;
}
}
if(genr==P && mains==A) // if generator ON
{
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Lcd_Out(1,1,CopyConst2Ram(msg,wu)); // Write text in first row
Delay_ms(5000);
gen_cont=1; // transfer load on genset after warmup
Delay_ms(300);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Lcd_Out(1,1,CopyConst2Ram(msg,fv)); // Write text in first row
Lcd_Out(2,1," . Hz . V");
// lcd_init();
Delay_ms(2000);
}
else
if(genr==A && mains==A) // if generator is still off; i.e; can't start
{
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Lcd_Out(1,2,CopyConst2Ram(msg,error));
Lcd_Out(2,1,CopyConst2Ram(msg,f2s)); // Write text in first row
ignition=0; //Turn off the genset
main_cont=0;
while(mains==A && genr==A); //stuck here untill reset/restart the controller board (IF main and generator both are absent)
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
}
for(;mains==A;) //untill main absent
{
if (mains==A) // if main absent
gen_cont=1; // Turn on generator contactor
main_cont=0; // Turn off main contactor
while(mains==A); // stay here until main resumes
if (mains==P) //if main presents or after main resumes
{
gen_cont=0;
Delay_ms(1000);
ignition=0; //Turn off the genset
Delay_ms(2000);
main_cont=1;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,3,CopyConst2Ram(msg,st)); // Write text in first row
Lcd_Out(2,4,CopyConst2Ram(msg,pl));
}
}
}
void start()
{
gen_cont=0;
main_cont=0;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mok)); // Write text in first row
Lcd_Out(2,1,CopyConst2Ram(msg,pw)); //please wait
Delay_ms(3000);
main_cont=1;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mok)); // Write text in first row
Lcd_Out(2,1,CopyConst2Ram(msg,mol)); //mains overload
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,3,CopyConst2Ram(msg,st)); // Write text in first row
Lcd_Out(2,4,CopyConst2Ram(msg,pl)); //pvt ltd
}
void main()
{
unsigned int i=0, itrue=1; //i=loops ; x=passward ; J=While lock
//..............INITIALIZATIONS............................................
// CONFIGURING SFRs:
cnt=0;
TMR0=0; // loading vlaue of timer0 interrupt
OPTION_REG=0x87; // for timer 0; presscaller 1; 256
ADCON1=0x06; // adc reg initialization
INTCON=0xA0; // for timer0 ; interrupt reg initilization
// OUTPUTS:
TRISB.f2 = 0; //led out put
TRISE.F2=0; // gen cont output
TRISC=0x00; // portC output For LCD
PORTC=0X00; // initilization port c
// INPUTS:
TRISD.F0=1; // ENTER
TRISD.F1=1; // RESET
TRISD.F2=1; // UP
TRISD.F3=1; // DOWN */
TRISA = 0xFF; // port A as input
//TRISD = 0xFF; // port D as input
// TRISD.F4=0XFF; ALREADY DIRECTED AT LCD INITILIZATION
// TRISD.F5=0XFF;
//................................................................................
lcd_init();
Delay_ms(500);
if(mains==P) // if main is Present.
{
start();
}
while(1)
{
if ((enter==0) && (reset==1) && (up==1) && (down==1))// (Button(&PORTD,0,ms,0)) //when Enter is pressed
{
Delay_ms(ms); // wait for switch debounce
itrue=1;
x=0;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,ep)); //enter passward
delay_ms(t);
while ((enter==0) && (reset==1) && (up==1) && (down==1))//(Button(&PORTD,0,ms,0)) // press enter
{ Delay_ms(ms); // wait for switch debounce
x++;
Lcd_Out(2,x,CopyConst2Ram(msg,asteric)); //*
if(x==4)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Lcd_Out(1,1,CopyConst2Ram(msg,pw)); //please wait
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,CopyConst2Ram(msg,gwt)); // Generator warm up time
inc=0; //for selection of variable
itrue=1; // Entring and Exiting main menu
opt=1; // option b/w selection number or variable
while(itrue==1)
{
if ((enter==0) && (reset==1) && (up==1) && (down==1))//(Button(&PORTD,0,ms,0)) // pressing enter to enter time
{
Delay_ms(ms); // wait for switch debounce
opt=0;
Lcd_Out(2,1,CopyConst2Ram(msg,sp));
}
if ((enter==1) && (reset==0) && (up==1) && (down==1))//(Button(&PORTD,1,ms,0)) //press reset to exit
{ Delay_ms(ms); // wait for switch debounce
itrue=0;
}
if ((enter==1) && (reset==1) && (up==0) && (down==1))//(Button(&PORTD,2,ms,0)) //up
{ Delay_ms(ms); // wait for switch debounce
inc=scroll_up(opt,inc);
}
if ((enter==1) && (reset==1) && (up==1) && (down==0))//(Button(&PORTD,3,ms,0)) // down
{
Delay_ms(ms); // wait for switch debounce
inc=scroll_down(opt,inc);
}
}
x++;
} //if
} //while
Delay_ms(1000);
}
if(mains==A) // if main is absent.
{
Delay_ms(4000); // wait for 4 seconds to ensure power failure
if(mains==P) //check again
continue;
//Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mna)); //mains not available
Lcd_Out(2,1,CopyConst2Ram(msg,sg)); //starting genset
Delay_ms(1000);
gen();
}
else // if main is present .........
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mok)); // Write text in first row
Lcd_Out(2,1,CopyConst2Ram(msg,mol)); // mains overload
Delay_ms(2000);
// gen_cont=0; //Turn off generator contactor
//main_cont=1; //Turn on main contactor
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,3,CopyConst2Ram(msg,st)); // Write text in first row
Lcd_Out(2,4,CopyConst2Ram(msg,pl)); // pvt ltd
Delay_ms(1000);
}
for(i=0; i<96; i++)
{
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Delay_ms(t);
if (enter==0)
i=96;
if(mains==A)
{
i=96;
}
}
} // while
} // main
//..............................;;;;;;;.........................................
// OUTPUTS
#define gen_cont PORTE.f2
#define led PORTB.f2
#define main_cont PORTC.F0
#define chowk PORTC.F1
#define ignition PORTC.F2
#define self PORTC.F3
// INPUTS
#define genr PORTA.F0
#define mains PORTA.F1
//.........button connections..........
#define enter PORTD.F0
#define reset PORTD.F1
#define up PORTD.F2
#define down PORTD.F3
//CONSTANTS
#define t 100 //DELAYS
#define P 1 //FOR MAIN AND gen INPUTS
#define A 0 //FOR MAIN AND gen INPUTS
#define ms 150 // for button debounce
//============Start LCD Connections========================================
sbit LCD_RS at RD5_bit;
sbit LCD_EN at RD4_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 TRISD5_bit;
sbit LCD_EN_Direction at TRISD4_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 Connections=============================================
//============= START RAM SAVER ===========================================
const char wu[] = "Warming up.....";
const char fv[] = "Frequency Volts";
const char error[] = "< ERROR >";
const char f2s[] = "Fails to start";
const char st[] = "Shenztech";
const char pl[] = "Pvt Ltd";
const char mna[] = "Mains not avail";
const char sg[] = "Starting Genset";
const char mok[] = "Mains OK..";
const char mol[] = "Mains Overload";
const char pw[] = "Please Wait...";
const char gwt[] = "Gen Warm up time";
const char sont[] = "Self ON Time";
const char soft[] = "Self OFF time";
const char ep[] = "Enter Passward";
const char asteric[] = "*";
const char sp[] = "scroll please";
const char sav[] = "Saving.......";
//============= END RAM SAVER ===========================================
int x=0, inc=0, opt=1, gen_wt=10, self_ont=2, self_oft=5;
char string[7]; // to dispaly integers stored in eeprom
char msg[17]; //declare array set 16 bytes of RAM aside for copying into
// copy const to ram string
char *CopyConst2Ram(char * dest, const char * src)
{
char * d ;
d = dest;
for(;*dest++ = *src++;);
return d;
}
unsigned char cnt;
void gen(void);
void start(void);
int scroll_up( int opt, int inc);
int scroll_down( int opt, int inc );
void interrupt()
{
if(TMR0IF_bit)
{ cnt++;
TMR0IF_bit=0;
if(cnt>=10)
{
led=~led;
cnt=0;
}
TMR0=0;
}
}
//-----------------------scroll up ...........................................
scroll_up(int opt ,int inc )
{
int j=1;
inc++;
if(opt==1)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
if(inc==0)
Lcd_Out(1,1,CopyConst2Ram(msg,gwt));
if(inc==1)
Lcd_Out(1,1,CopyConst2Ram(msg,sont));
if(inc==2)
Lcd_Out(1,1,CopyConst2Ram(msg,soft));
} //end if opt = 1
if(opt==0)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
//..................inc=0...gen_wt...............................
if(inc==0)
{
x=gen_wt;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==0) && (down==1) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x++;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
gen_wt=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
} while(j);
}// if inc=0
//....................inc = 1......self_ont..............
if(inc==1)
{
x=self_ont;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==0) && (down==1) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x++;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_ont=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
} while(j);
}// if inc=1
//.....................inc=2................self_oft..................................
if(inc==2)
{
x=self_oft;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==0) && (down==1) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x++;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_oft=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
inc=0;
} while(j);
}// if inc=2
} // if opt = 0
return (inc);
} // end scroll up
//-----------------------scroll Down ...........................................
scroll_down( int opt , int inc )
{
int j=1;
inc--;
if(opt==1)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
if(inc==0)
Lcd_Out(1,1,CopyConst2Ram(msg,gwt));
if(inc==1)
Lcd_Out(1,1,CopyConst2Ram(msg,sont));
if(inc==2)
Lcd_Out(1,1,CopyConst2Ram(msg,soft));
} //end if opt = 1
if(opt==0)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
//..................inc=0....gen_wt......................
if(inc==0)
{
x=gen_wt;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==1) && (down==0) && j==1)//(Button(&PORTD,2,ms,0)&&j) // down pressed
{ Delay_ms(ms); // wait for switch debounce
x--;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
gen_wt=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
} while(j);
}// if inc=0
//....................inc = 1......self_ont..............
if(inc==1)
{
x=self_ont;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==1) && (down==0) && j==1)//(Button(&PORTD,2,ms,0)&&j) // down pressed
{ Delay_ms(ms); // wait for switch debounce
x--;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_ont=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
} while(j);
}// if inc=1
//.................inc=2..........self_oft..................................
if(inc==2)
{
x=self_oft;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==1) && (down==0) && j==1)//(Button(&PORTD,2,ms,0)&&j) // down pressed
{ Delay_ms(ms); // wait for switch debounce
x--;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_oft=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
inc=0;
} while(j);
}// if inc=2
} // if opt = 0
return (inc);
} // end scroll down
//..............generator routine...............................................
gen()
{
int i;
main_cont=0;
ignition=1;
Delay_ms(2000);
chowk=1;
Delay_ms(5000);//chowk on for 5 seconds
chowk=0;
for(i=0; i<3; i++)
{
if(mains==P) //if Main resumes
{
i=3;
gen_cont=0;
ignition=0;
self=0;
Delay_ms(2000); //self on for 2 seconds
main_cont=1;
}
if(i==2)
{
chowk=1;
Delay_ms(5000);//chowk on for 5 seconds
chowk=0;
}
self=1;
Delay_ms(2000); //self on for 2 seconds
self=0;
Delay_ms(4000); //self off for 4 seconds
if(genr==P) //if generator ON
{
i=3;
}
}
if(genr==P && mains==A) // if generator ON
{
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Lcd_Out(1,1,CopyConst2Ram(msg,wu)); // Write text in first row
Delay_ms(5000);
gen_cont=1; // transfer load on genset after warmup
Delay_ms(300);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Lcd_Out(1,1,CopyConst2Ram(msg,fv)); // Write text in first row
Lcd_Out(2,1," . Hz . V");
// lcd_init();
Delay_ms(2000);
}
else
if(genr==A && mains==A) // if generator is still off; i.e; can't start
{
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Lcd_Out(1,2,CopyConst2Ram(msg,error));
Lcd_Out(2,1,CopyConst2Ram(msg,f2s)); // Write text in first row
ignition=0; //Turn off the genset
main_cont=0;
while(mains==A && genr==A); //stuck here untill reset/restart the controller board (IF main and generator both are absent)
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
}
for(;mains==A;) //untill main absent
{
if (mains==A) // if main absent
gen_cont=1; // Turn on generator contactor
main_cont=0; // Turn off main contactor
while(mains==A); // stay here until main resumes
if (mains==P) //if main presents or after main resumes
{
gen_cont=0;
Delay_ms(1000);
ignition=0; //Turn off the genset
Delay_ms(2000);
main_cont=1;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,3,CopyConst2Ram(msg,st)); // Write text in first row
Lcd_Out(2,4,CopyConst2Ram(msg,pl));
}
}
}
void start()
{
gen_cont=0;
main_cont=0;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mok)); // Write text in first row
Lcd_Out(2,1,CopyConst2Ram(msg,pw)); //please wait
Delay_ms(3000);
main_cont=1;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mok)); // Write text in first row
Lcd_Out(2,1,CopyConst2Ram(msg,mol)); //mains overload
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,3,CopyConst2Ram(msg,st)); // Write text in first row
Lcd_Out(2,4,CopyConst2Ram(msg,pl)); //pvt ltd
}
void main()
{
unsigned int i=0, itrue=1; //i=loops ; x=passward ; J=While lock
//..............INITIALIZATIONS............................................
// CONFIGURING SFRs:
cnt=0;
TMR0=0; // loading vlaue of timer0 interrupt
OPTION_REG=0x87; // for timer 0; presscaller 1; 256
ADCON1=0x06; // adc reg initialization
INTCON=0xA0; // for timer0 ; interrupt reg initilization
// OUTPUTS:
TRISB.f2 = 0; //led out put
TRISE.F2=0; // gen cont output
TRISC=0x00; // portC output For LCD
PORTC=0X00; // initilization port c
// INPUTS:
TRISD.F0=1; // ENTER
TRISD.F1=1; // RESET
TRISD.F2=1; // UP
TRISD.F3=1; // DOWN */
TRISA = 0xFF; // port A as input
//TRISD = 0xFF; // port D as input
// TRISD.F4=0XFF; ALREADY DIRECTED AT LCD INITILIZATION
// TRISD.F5=0XFF;
//................................................................................
lcd_init();
Delay_ms(500);
if(mains==P) // if main is Present.
{
start();
}
while(1)
{
if ((enter==0) && (reset==1) && (up==1) && (down==1))// (Button(&PORTD,0,ms,0)) //when Enter is pressed
{
Delay_ms(ms); // wait for switch debounce
itrue=1;
x=0;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,ep)); //enter passward
delay_ms(t);
while ((enter==0) && (reset==1) && (up==1) && (down==1))//(Button(&PORTD,0,ms,0)) // press enter
{ Delay_ms(ms); // wait for switch debounce
x++;
Lcd_Out(2,x,CopyConst2Ram(msg,asteric)); //*
if(x==4)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Lcd_Out(1,1,CopyConst2Ram(msg,pw)); //please wait
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,CopyConst2Ram(msg,gwt)); // Generator warm up time
inc=0; //for selection of variable
itrue=1; // Entring and Exiting main menu
opt=1; // option b/w selection number or variable
while(itrue==1)
{
if ((enter==0) && (reset==1) && (up==1) && (down==1))//(Button(&PORTD,0,ms,0)) // pressing enter to enter time
{
Delay_ms(ms); // wait for switch debounce
opt=0;
Lcd_Out(2,1,CopyConst2Ram(msg,sp));
}
if ((enter==1) && (reset==0) && (up==1) && (down==1))//(Button(&PORTD,1,ms,0)) //press reset to exit
{ Delay_ms(ms); // wait for switch debounce
itrue=0;
}
if ((enter==1) && (reset==1) && (up==0) && (down==1))//(Button(&PORTD,2,ms,0)) //up
{ Delay_ms(ms); // wait for switch debounce
inc=scroll_up(opt,inc);
}
if ((enter==1) && (reset==1) && (up==1) && (down==0))//(Button(&PORTD,3,ms,0)) // down
{
Delay_ms(ms); // wait for switch debounce
inc=scroll_down(opt,inc);
}
}
x++;
} //if
} //while
Delay_ms(1000);
}
if(mains==A) // if main is absent.
{
Delay_ms(4000); // wait for 4 seconds to ensure power failure
if(mains==P) //check again
continue;
//Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mna)); //mains not available
Lcd_Out(2,1,CopyConst2Ram(msg,sg)); //starting genset
Delay_ms(1000);
gen();
}
else // if main is present .........
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mok)); // Write text in first row
Lcd_Out(2,1,CopyConst2Ram(msg,mol)); // mains overload
Delay_ms(2000);
// gen_cont=0; //Turn off generator contactor
//main_cont=1; //Turn on main contactor
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,3,CopyConst2Ram(msg,st)); // Write text in first row
Lcd_Out(2,4,CopyConst2Ram(msg,pl)); // pvt ltd
Delay_ms(1000);
}
for(i=0; i<96; i++)
{
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Delay_ms(t);
if (enter==0)
i=96;
if(mains==A)
{
i=96;
}
}
} // while
} // main
//..............................;;;;;;;.........................................
// OUTPUTS
#define gen_cont PORTE.f2
#define led PORTB.f2
#define main_cont PORTC.F0
#define chowk PORTC.F1
#define ignition PORTC.F2
#define self PORTC.F3
// INPUTS
#define genr PORTA.F0
#define mains PORTA.F1
//.........button connections..........
#define enter PORTD.F0
#define reset PORTD.F1
#define up PORTD.F2
#define down PORTD.F3
//CONSTANTS
#define t 100 //DELAYS
#define P 1 //FOR MAIN AND gen INPUTS
#define A 0 //FOR MAIN AND gen INPUTS
#define ms 150 // for button debounce
//============Start LCD Connections========================================
sbit LCD_RS at RD5_bit;
sbit LCD_EN at RD4_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 TRISD5_bit;
sbit LCD_EN_Direction at TRISD4_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 Connections=============================================
//============= START RAM SAVER ===========================================
const char wu[] = "Warming up.....";
const char fv[] = "Frequency Volts";
const char error[] = "< ERROR >";
const char f2s[] = "Fails to start";
const char st[] = "Shenztech";
const char pl[] = "Pvt Ltd";
const char mna[] = "Mains not avail";
const char sg[] = "Starting Genset";
const char mok[] = "Mains OK..";
const char mol[] = "Mains Overload";
const char pw[] = "Please Wait...";
const char gwt[] = "Gen Warm up time";
const char sont[] = "Self ON Time";
const char soft[] = "Self OFF time";
const char ep[] = "Enter Passward";
const char asteric[] = "*";
const char sp[] = "scroll please";
const char sav[] = "Saving.......";
//============= END RAM SAVER ===========================================
int x=0, inc=0, opt=1, gen_wt=10, self_ont=2, self_oft=5;
char string[7]; // to dispaly integers stored in eeprom
char msg[17]; //declare array set 16 bytes of RAM aside for copying into
// copy const to ram string
char *CopyConst2Ram(char * dest, const char * src)
{
char * d ;
d = dest;
for(;*dest++ = *src++;);
return d;
}
unsigned char cnt;
void gen(void);
void start(void);
int scroll_up( int opt, int inc);
int scroll_down( int opt, int inc );
void interrupt()
{
if(TMR0IF_bit)
{ cnt++;
TMR0IF_bit=0;
if(cnt>=10)
{
led=~led;
cnt=0;
}
TMR0=0;
}
}
//-----------------------scroll up ...........................................
scroll_up(int opt ,int inc )
{
int j=1;
inc++;
if(opt==1)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
if(inc==0)
Lcd_Out(1,1,CopyConst2Ram(msg,gwt));
if(inc==1)
Lcd_Out(1,1,CopyConst2Ram(msg,sont));
if(inc==2)
Lcd_Out(1,1,CopyConst2Ram(msg,soft));
} //end if opt = 1
if(opt==0)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
//..................inc=0...gen_wt...............................
if(inc==0)
{
x=gen_wt;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==0) && (down==1) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x++;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
gen_wt=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
} while(j);
}// if inc=0
//....................inc = 1......self_ont..............
if(inc==1)
{
x=self_ont;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==0) && (down==1) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x++;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_ont=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
} while(j);
}// if inc=1
//.....................inc=2................self_oft..................................
if(inc==2)
{
x=self_oft;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==0) && (down==1) && j==1)//(Button(&PORTD,2,ms,0)&&j) // up pressed
{ Delay_ms(ms); // wait for switch debounce
x++;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_oft=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
inc=0;
} while(j);
}// if inc=2
} // if opt = 0
return (inc);
} // end scroll up
//-----------------------scroll Down ...........................................
scroll_down( int opt , int inc )
{
int j=1;
inc--;
if(opt==1)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
if(inc==0)
Lcd_Out(1,1,CopyConst2Ram(msg,gwt));
if(inc==1)
Lcd_Out(1,1,CopyConst2Ram(msg,sont));
if(inc==2)
Lcd_Out(1,1,CopyConst2Ram(msg,soft));
} //end if opt = 1
if(opt==0)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
//..................inc=0....gen_wt......................
if(inc==0)
{
x=gen_wt;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==1) && (down==0) && j==1)//(Button(&PORTD,2,ms,0)&&j) // down pressed
{ Delay_ms(ms); // wait for switch debounce
x--;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
gen_wt=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
} while(j);
}// if inc=0
//....................inc = 1......self_ont..............
if(inc==1)
{
x=self_ont;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==1) && (down==0) && j==1)//(Button(&PORTD,2,ms,0)&&j) // down pressed
{ Delay_ms(ms); // wait for switch debounce
x--;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_ont=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
} while(j);
}// if inc=1
//.................inc=2..........self_oft..................................
if(inc==2)
{
x=self_oft;
IntToStr(x, string);
Lcd_Out(2,10,string);
do
{
if((enter==1) && (reset==1) && (up==1) && (down==0) && j==1)//(Button(&PORTD,2,ms,0)&&j) // down pressed
{ Delay_ms(ms); // wait for switch debounce
x--;
IntToStr(x, string);
Lcd_Out(2,10,string);
Delay_ms(500);
}// end if
if((enter==0) && (reset==1) && (up==1) && (down==1))//( Button(&PORTD,0,ms,0)) //Enter pressed to save
{ Delay_ms(ms); // wait for switch debounce
self_oft=x;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Delay_ms(500);
Lcd_Out(1,1,CopyConst2Ram(msg,sav));
Delay_ms(1000);
j=0;
} // end saving
inc=0;
} while(j);
}// if inc=2
} // if opt = 0
return (inc);
} // end scroll down
//..............generator routine...............................................
gen()
{
int i;
main_cont=0;
ignition=1;
Delay_ms(2000);
chowk=1;
Delay_ms(5000);//chowk on for 5 seconds
chowk=0;
for(i=0; i<3; i++)
{
if(mains==P) //if Main resumes
{
i=3;
gen_cont=0;
ignition=0;
self=0;
Delay_ms(2000); //self on for 2 seconds
main_cont=1;
}
if(i==2)
{
chowk=1;
Delay_ms(5000);//chowk on for 5 seconds
chowk=0;
}
self=1;
Delay_ms(2000); //self on for 2 seconds
self=0;
Delay_ms(4000); //self off for 4 seconds
if(genr==P) //if generator ON
{
i=3;
}
}
if(genr==P && mains==A) // if generator ON
{
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Lcd_Out(1,1,CopyConst2Ram(msg,wu)); // Write text in first row
Delay_ms(5000);
gen_cont=1; // transfer load on genset after warmup
Delay_ms(300);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Lcd_Out(1,1,CopyConst2Ram(msg,fv)); // Write text in first row
Lcd_Out(2,1," . Hz . V");
// lcd_init();
Delay_ms(2000);
}
else
if(genr==A && mains==A) // if generator is still off; i.e; can't start
{
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Lcd_Out(1,2,CopyConst2Ram(msg,error));
Lcd_Out(2,1,CopyConst2Ram(msg,f2s)); // Write text in first row
ignition=0; //Turn off the genset
main_cont=0;
while(mains==A && genr==A); //stuck here untill reset/restart the controller board (IF main and generator both are absent)
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
}
for(;mains==A;) //untill main absent
{
if (mains==A) // if main absent
gen_cont=1; // Turn on generator contactor
main_cont=0; // Turn off main contactor
while(mains==A); // stay here until main resumes
if (mains==P) //if main presents or after main resumes
{
gen_cont=0;
Delay_ms(1000);
ignition=0; //Turn off the genset
Delay_ms(2000);
main_cont=1;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,3,CopyConst2Ram(msg,st)); // Write text in first row
Lcd_Out(2,4,CopyConst2Ram(msg,pl));
}
}
}
void start()
{
gen_cont=0;
main_cont=0;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mok)); // Write text in first row
Lcd_Out(2,1,CopyConst2Ram(msg,pw)); //please wait
Delay_ms(3000);
main_cont=1;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mok)); // Write text in first row
Lcd_Out(2,1,CopyConst2Ram(msg,mol)); //mains overload
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,3,CopyConst2Ram(msg,st)); // Write text in first row
Lcd_Out(2,4,CopyConst2Ram(msg,pl)); //pvt ltd
}
void main()
{
unsigned int i=0, itrue=1; //i=loops ; x=passward ; J=While lock
//..............INITIALIZATIONS............................................
// CONFIGURING SFRs:
cnt=0;
TMR0=0; // loading vlaue of timer0 interrupt
OPTION_REG=0x87; // for timer 0; presscaller 1; 256
ADCON1=0x06; // adc reg initialization
INTCON=0xA0; // for timer0 ; interrupt reg initilization
// OUTPUTS:
TRISB.f2 = 0; //led out put
TRISE.F2=0; // gen cont output
TRISC=0x00; // portC output For LCD
PORTC=0X00; // initilization port c
// INPUTS:
TRISD.F0=1; // ENTER
TRISD.F1=1; // RESET
TRISD.F2=1; // UP
TRISD.F3=1; // DOWN */
TRISA = 0xFF; // port A as input
//TRISD = 0xFF; // port D as input
// TRISD.F4=0XFF; ALREADY DIRECTED AT LCD INITILIZATION
// TRISD.F5=0XFF;
//................................................................................
lcd_init();
Delay_ms(500);
if(mains==P) // if main is Present.
{
start();
}
while(1)
{
if ((enter==0) && (reset==1) && (up==1) && (down==1))// (Button(&PORTD,0,ms,0)) //when Enter is pressed
{
Delay_ms(ms); // wait for switch debounce
itrue=1;
x=0;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,ep)); //enter passward
delay_ms(t);
while ((enter==0) && (reset==1) && (up==1) && (down==1))//(Button(&PORTD,0,ms,0)) // press enter
{ Delay_ms(ms); // wait for switch debounce
x++;
Lcd_Out(2,x,CopyConst2Ram(msg,asteric)); //*
if(x==4)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Lcd_Out(1,1,CopyConst2Ram(msg,pw)); //please wait
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,CopyConst2Ram(msg,gwt)); // Generator warm up time
inc=0; //for selection of variable
itrue=1; // Entring and Exiting main menu
opt=1; // option b/w selection number or variable
while(itrue==1)
{
if ((enter==0) && (reset==1) && (up==1) && (down==1))//(Button(&PORTD,0,ms,0)) // pressing enter to enter time
{
Delay_ms(ms); // wait for switch debounce
opt=0;
Lcd_Out(2,1,CopyConst2Ram(msg,sp));
}
if ((enter==1) && (reset==0) && (up==1) && (down==1))//(Button(&PORTD,1,ms,0)) //press reset to exit
{ Delay_ms(ms); // wait for switch debounce
itrue=0;
}
if ((enter==1) && (reset==1) && (up==0) && (down==1))//(Button(&PORTD,2,ms,0)) //up
{ Delay_ms(ms); // wait for switch debounce
inc=scroll_up(opt,inc);
}
if ((enter==1) && (reset==1) && (up==1) && (down==0))//(Button(&PORTD,3,ms,0)) // down
{
Delay_ms(ms); // wait for switch debounce
inc=scroll_down(opt,inc);
}
}
x++;
} //if
} //while
Delay_ms(1000);
}
if(mains==A) // if main is absent.
{
Delay_ms(4000); // wait for 4 seconds to ensure power failure
if(mains==P) //check again
continue;
//Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mna)); //mains not available
Lcd_Out(2,1,CopyConst2Ram(msg,sg)); //starting genset
Delay_ms(1000);
gen();
}
else // if main is present .........
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mok)); // Write text in first row
Lcd_Out(2,1,CopyConst2Ram(msg,mol)); // mains overload
Delay_ms(2000);
// gen_cont=0; //Turn off generator contactor
//main_cont=1; //Turn on main contactor
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,3,CopyConst2Ram(msg,st)); // Write text in first row
Lcd_Out(2,4,CopyConst2Ram(msg,pl)); // pvt ltd
Delay_ms(1000);
}
for(i=0; i<96; i++)
{
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Delay_ms(t);
if (enter==0)
i=96;
if(mains==A)
{
i=96;
}
}
} // while
} // main
//..............................;;;;;;;.........................................
But it is not working for me.
Which version of mikroC are you using?
I am using both mikroC 5.6.0 and 5.6.1. If you need the file which creates the right hex file, PM me your email address. I will send the file.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?