girgis adly
New Member
dear all
i write a cod for my project which is multilevel inverter equipped with lcd screen but when i check the code on a simulation programe (proteus)it is not work as intended this is the code written in micro c language and i use pic18f452 switches s1&s2 connected to port A gates of mosfets of the inverter connected to port B lcd connected to port c
i want the prog to do that when i run the prog some message appear on the lcd then message appear
menu
s1:5l s2:EX
this message appear and still on the screeen till i press s1 or s2 then if i press s1 prog run and message appear prog of 5l run and still on the screen untill the prog end as we use for loop after the prog end message appear
prog end
s1:menu s2:exit
if press s2 the prog go to exit and message appear
Exit
s1:yes s2:No
if press s1 mesage appear
prog end
good bye
now the problems in my code is the programe run without i press any switch and still run regardless of for loop
this is my code:
void main()
{
int (x) ;
lcd_init(&portc);
lcd_cmd(LCD_CURSOR_OFF);
lcd_out(1,1,"project of :");
delay_ms(2000);
lcd_cmd(lcd_clear);
lcd_out(1,4,"Multilevel ");
lcd_out(2,1," Pwm inverter ");
delay_ms(2000);
lcd_cmd(lcd_clear);
Lcd_Out_Cp("supervised by:");
lcd_out(2,1," Dr. Gamal Hashm");
delay_ms(3000);
lcd_cmd(lcd_clear);
lcd_Out_Cp("press s1 for run");
lcd_out(2,1,"press s2 for EX");
delay_ms(2000);
menu:
lcd_cmd(lcd_clear);
lcd_cmd(LCD_CURSOR_OFF);
Lcd_Out_Cp("menu: ");
lcd_out(2,1,"s1:5l s2:EXIT");
TRISB=0;
trisA=00001111;
if(portA.f0==0)
{
lcd_cmd(lcd_clear);
lcd_Out_Cp("prog of 5l run");
//code of project
for(x=0;x,1000;x++)
{
PORTB=0;
Delay_us(337);
PORTB=0B00000101;
Delay_us(2717);
PORTB=0B00001001;
delay_us(3889);
PORTB=0B00000101;
delay_us(2667);
PORTB=0;
delay_us(777);
PORTB=0B00000110;
delay_us(2667);
PORTB=0B00001010;
delay_us(3889);
PORTB=0B00000110;
delay_us(2667);
PORTB=0;
delay_us(388);
}
lcd_cmd(lcd_clear);
Lcd_Out_Cp(" prog end");
lcd_out(2,1,"s1:menu s2:exit");
if(porta.f0==0)
{goto menu;}
if(porta.f1==0)
{goto exit; }}
if(porta.f1==0)
{goto exit;}
exit:
Lcd_Out_Cp(" Exit");
lcd_out(2,1,"s1:yes s2:No");
if(porta.f0==0)
{
lcd_cmd(lcd_clear);
Lcd_Out_Cp(" prog end");
lcd_out(2,4," good bye");
}
if(porta.f1==0)
{goto menu;}}
I think to use keypad I write the code with keypad instead of switches but also the switch not run as intended in the simulation prog may be I connect the keypad in wrong way I try again by connecting switches instead of keypad but there is no use
This the code using keypad
void main()
{
int x;
char m;
keypad_init(&porta);
lcd_init(&portc);
lcd_cmd(LCD_CURSOR_OFF);
lcd_out(1,1,"project of :");
delay_ms(2000);
lcd_cmd(lcd_clear);
lcd_out(1,4,"Multilevel ");
lcd_out(2,1," Pwm inverter ");
delay_ms(2000);
lcd_cmd(lcd_clear);
Lcd_Out_Cp("supervised by:");
lcd_out(2,1," Dr. Gamal Hashm");
delay_ms(3000);
lcd_cmd(lcd_clear);
lcd_Out_Cp("press s1 for run");
lcd_out(2,1,"press s2 for EX");
delay_ms(2000);
menu:
lcd_cmd(lcd_clear);
lcd_cmd(LCD_CURSOR_OFF);
Lcd_Out_Cp("menu: ");
lcd_out(2,1,"s1:5l s2:EXIT");
TRISB=0;
m=keypad_read();
if(m==1)
{
lcd_cmd(lcd_clear);
lcd_Out_Cp("prog of 5l run");
//code of project
for(x=0;x,1000;x++)
{
PORTB=0;
Delay_us(337);
PORTB=0B00000101;
Delay_us(2717);
PORTB=0B00001001;
delay_us(3889);
PORTB=0B00000101;
delay_us(2667);
PORTB=0;
delay_us(777);
PORTB=0B00000110;
delay_us(2667);
PORTB=0B00001010;
delay_us(3889);
PORTB=0B00000110;
delay_us(2667);
PORTB=0;
delay_us(388);
}
lcd_cmd(lcd_clear);
Lcd_Out_Cp(" prog end");
lcd_out(2,1,"s1:menu s2:exit");
m=keypad_read();
if(m==1)
{goto menu;}
if(m==2)
{goto exit; }}
if(m==2)
{goto exit;}
exit:
Lcd_Out_Cp(" Exit");
lcd_out(2,1,"s1:yes s2:No");
m=keypad_read();
if(m==1)
{
lcd_cmd(lcd_clear);
Lcd_Out_Cp(" prog end");
lcd_out(2,4," good bye");
}
if(m==2)
{goto menu;}}
Please help me in correcting the code
Any suggestion will be appreciated
Thanks and regards
i write a cod for my project which is multilevel inverter equipped with lcd screen but when i check the code on a simulation programe (proteus)it is not work as intended this is the code written in micro c language and i use pic18f452 switches s1&s2 connected to port A gates of mosfets of the inverter connected to port B lcd connected to port c
i want the prog to do that when i run the prog some message appear on the lcd then message appear
menu
s1:5l s2:EX
this message appear and still on the screeen till i press s1 or s2 then if i press s1 prog run and message appear prog of 5l run and still on the screen untill the prog end as we use for loop after the prog end message appear
prog end
s1:menu s2:exit
if press s2 the prog go to exit and message appear
Exit
s1:yes s2:No
if press s1 mesage appear
prog end
good bye
now the problems in my code is the programe run without i press any switch and still run regardless of for loop
this is my code:
void main()
{
int (x) ;
lcd_init(&portc);
lcd_cmd(LCD_CURSOR_OFF);
lcd_out(1,1,"project of :");
delay_ms(2000);
lcd_cmd(lcd_clear);
lcd_out(1,4,"Multilevel ");
lcd_out(2,1," Pwm inverter ");
delay_ms(2000);
lcd_cmd(lcd_clear);
Lcd_Out_Cp("supervised by:");
lcd_out(2,1," Dr. Gamal Hashm");
delay_ms(3000);
lcd_cmd(lcd_clear);
lcd_Out_Cp("press s1 for run");
lcd_out(2,1,"press s2 for EX");
delay_ms(2000);
menu:
lcd_cmd(lcd_clear);
lcd_cmd(LCD_CURSOR_OFF);
Lcd_Out_Cp("menu: ");
lcd_out(2,1,"s1:5l s2:EXIT");
TRISB=0;
trisA=00001111;
if(portA.f0==0)
{
lcd_cmd(lcd_clear);
lcd_Out_Cp("prog of 5l run");
//code of project
for(x=0;x,1000;x++)
{
PORTB=0;
Delay_us(337);
PORTB=0B00000101;
Delay_us(2717);
PORTB=0B00001001;
delay_us(3889);
PORTB=0B00000101;
delay_us(2667);
PORTB=0;
delay_us(777);
PORTB=0B00000110;
delay_us(2667);
PORTB=0B00001010;
delay_us(3889);
PORTB=0B00000110;
delay_us(2667);
PORTB=0;
delay_us(388);
}
lcd_cmd(lcd_clear);
Lcd_Out_Cp(" prog end");
lcd_out(2,1,"s1:menu s2:exit");
if(porta.f0==0)
{goto menu;}
if(porta.f1==0)
{goto exit; }}
if(porta.f1==0)
{goto exit;}
exit:
Lcd_Out_Cp(" Exit");
lcd_out(2,1,"s1:yes s2:No");
if(porta.f0==0)
{
lcd_cmd(lcd_clear);
Lcd_Out_Cp(" prog end");
lcd_out(2,4," good bye");
}
if(porta.f1==0)
{goto menu;}}
I think to use keypad I write the code with keypad instead of switches but also the switch not run as intended in the simulation prog may be I connect the keypad in wrong way I try again by connecting switches instead of keypad but there is no use
This the code using keypad
void main()
{
int x;
char m;
keypad_init(&porta);
lcd_init(&portc);
lcd_cmd(LCD_CURSOR_OFF);
lcd_out(1,1,"project of :");
delay_ms(2000);
lcd_cmd(lcd_clear);
lcd_out(1,4,"Multilevel ");
lcd_out(2,1," Pwm inverter ");
delay_ms(2000);
lcd_cmd(lcd_clear);
Lcd_Out_Cp("supervised by:");
lcd_out(2,1," Dr. Gamal Hashm");
delay_ms(3000);
lcd_cmd(lcd_clear);
lcd_Out_Cp("press s1 for run");
lcd_out(2,1,"press s2 for EX");
delay_ms(2000);
menu:
lcd_cmd(lcd_clear);
lcd_cmd(LCD_CURSOR_OFF);
Lcd_Out_Cp("menu: ");
lcd_out(2,1,"s1:5l s2:EXIT");
TRISB=0;
m=keypad_read();
if(m==1)
{
lcd_cmd(lcd_clear);
lcd_Out_Cp("prog of 5l run");
//code of project
for(x=0;x,1000;x++)
{
PORTB=0;
Delay_us(337);
PORTB=0B00000101;
Delay_us(2717);
PORTB=0B00001001;
delay_us(3889);
PORTB=0B00000101;
delay_us(2667);
PORTB=0;
delay_us(777);
PORTB=0B00000110;
delay_us(2667);
PORTB=0B00001010;
delay_us(3889);
PORTB=0B00000110;
delay_us(2667);
PORTB=0;
delay_us(388);
}
lcd_cmd(lcd_clear);
Lcd_Out_Cp(" prog end");
lcd_out(2,1,"s1:menu s2:exit");
m=keypad_read();
if(m==1)
{goto menu;}
if(m==2)
{goto exit; }}
if(m==2)
{goto exit;}
exit:
Lcd_Out_Cp(" Exit");
lcd_out(2,1,"s1:yes s2:No");
m=keypad_read();
if(m==1)
{
lcd_cmd(lcd_clear);
Lcd_Out_Cp(" prog end");
lcd_out(2,4," good bye");
}
if(m==2)
{goto menu;}}
Please help me in correcting the code
Any suggestion will be appreciated
Thanks and regards