keeth18
Newbie level 3
i am using pic16f877a, 20 mhz oscillator, mikroCPRO for PIC - compiler, 2x16 LCD, 4x4 keypad and a USB pic PLUS programmer.
the main menu is displayed on the LCd screen initialy. when the user presses the key using keypad, it should display the sub menu and again it must get the user input and ask for the quantity required. after pressing the key it must multiply and display the total cash and then ask for placing the order or cancel. on getting the user input as order - it must display thankz and then go to the main menu. if cancel then it must go to main menu with out placing the order.
The problem in the below program is - it does not return to the main menu after displaying thankz but instead it goes to quantity.
please help me out.. what is the mistake here
int kp,kp9,kp1,kp2,itno,kp3,kp4,kp5,kp6,k;
unsigned short cost = 0;
int c3,y3;
char txt[20],txt1[5],txt2[5],tot[3],txt4[5]="1A1";
int i;
int L1,L3,L4,L5;
char *txt3,*txt5,uart_rd;
char keypadPort at PORTD;
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
void Move_Delay();
void lftshftdly();
void clroff();
void start();
void L2();
void Move_Delay() {
Delay_ms(100);
}
void lftshftdly()
{
for(i=0; i<2; i++) {
Lcd_Cmd(_LCD_SHIFT_LEFT);
Move_Delay();
}
}
void clroff()
{
Lcd_Cmd(_LCD_CLEAR);
}
void main() {
TRISB=0;
Keypad_Init();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
UART1_Init(9600);
Delay_ms(100);
start();
}
void start()
{
L1:clroff();
Lcd_Chr(1, 1, '1');
Lcd_Chr(1, 2, '-');
Lcd_Chr(1, 3, 'D');
Lcd_Chr(1, 4, 'R');
Lcd_Chr(1, 5, 'i');
Lcd_Chr(1, 6, 'n');
Lcd_Chr(1, 7, 'k');
Lcd_Chr(1, 8, 's');
Lcd_Chr(2, 1, '2');
Lcd_Chr(2, 2, '-');
Lcd_Chr(2, 3, 'S');
Lcd_Chr(2, 4, 'n');
Lcd_Chr(2, 5, 'a');
Lcd_Chr(2, 6, 'c');
Lcd_Chr(2, 7, 'k');
Lcd_Chr(2, 8, 's');
do {
kp=0;
do
{
kp = Keypad_Key_Press();
}while (!kp);
switch (kp) {
case 1: //kp = 49;
clroff();
delay_ms(200);
Lcd_Chr(1, 1, '1');
Lcd_Chr(1, 2, '-');
Lcd_Chr(1, 3, 'T');
Lcd_Chr(1, 4, 'e');
Lcd_Chr(1, 5, 'a');
Lcd_Chr(1, 6, '(');
Lcd_Chr(1, 7, 'R');
Lcd_Chr(1, 8, 's');
Lcd_Chr(1, 9, '1');
Lcd_Chr(1, 10, '0');
Lcd_Chr(1,11, ')');
Lcd_Chr(2, 1, '2');
Lcd_Chr(2, 2, '-');
Lcd_Chr(2, 3, 'C');
Lcd_Chr(2, 4, 'o');
Lcd_Chr(2,5, 'f');
Lcd_Chr(2, 6, 'f');
Lcd_Chr(2, 7, 'e');
Lcd_Chr(2, 8, 'e');
Lcd_Chr(2, 9, '(');
Lcd_Chr(2, 10, 'R');
Lcd_Chr(2,11, 's');
Lcd_Chr(2, 12, '2');
Lcd_Chr(2, 13, '0');
Lcd_Chr(2, 14, ')');
do{
kp1=0;
do {
kp1 = Keypad_Key_Press();
}while (!kp1);
clroff();
switch(kp1)
{
case 1:
c3=10;
itno=101;
L2();
break;
case 2:
c3=20;
itno=102;
L2();
break;
case 4:goto L3;
break;
case 8:goto L4;
break;
case 14:goto L1;
break;
default: Lcd_Chr(1,1,'i');
goto L1;
break;
}
}while(1);
break;
case 2:
clroff();
delay_ms(200);
Lcd_Chr(1, 1, '1');
Lcd_Chr(1, 2, '-');
Lcd_Chr(1, 3, 'P');
Lcd_Chr(1, 4, 'u');
Lcd_Chr(1, 5, 'f');
Lcd_Chr(1, 6, 'f');
Lcd_Chr(1, 7, ' ');
Lcd_Chr(1, 8, ':');
Lcd_Chr(1, 9, ' ');
Lcd_Chr(1, 10, 'R');
Lcd_Chr(1, 11, 's');
Lcd_Chr(1, 12, '1');
Lcd_Chr(1,13, '5');
Lcd_Chr(2, 1, '2');
Lcd_Chr(2, 2, '-');
Lcd_Chr(2, 3, 'P');
Lcd_Chr(2, 4, 'o');
Lcd_Chr(2, 5, 'p');
Lcd_Chr(2, 6, 'c');
Lcd_Chr(2, 7, 'o');
Lcd_Chr(2, 8, 'r');
Lcd_Chr(2, 9, 'n');
Lcd_Chr(2, 10, '(');
Lcd_Chr(2,11, 'R');
Lcd_Chr(2, 12, 's');
Lcd_Chr(2, 13, '4');
Lcd_Chr(2, 14, '0');
Lcd_Chr(2, 15, ')');
do{
kp2=0;
do {
kp2 = Keypad_Key_Press();
}while (!kp2);
clroff();
switch(kp2)
{
case 1:
c3=15;
itno=201;
L2();
break;
case 2:
c3=40;
itno=202;
L2();
break;
case 4:goto L3;
break;
case 8:goto L4;
break;
case 14:goto L1;
break;
default:
Lcd_Chr(1,1,'i');
goto L1;
break;
}
}while(1);
break;
case 4:goto L3;
break;
case 8:goto L4;
break;
case 14:goto L1;
break;
default: Lcd_Chr(1,1,'i');
delay_ms(200);
goto L1;
break;
}
} while (1);
L3: clroff();
uart_rd=0x46;
UART1_Write(uart_rd);
Lcd_Chr(1, 1, 's');
Lcd_Chr(1, 2, 'e');
Lcd_Chr(1, 3, 'n');
Lcd_Chr(1, 4, 't');
delay_ms(500);
goto L1;
L4: clroff();
uart_rd=0x4D;
UART1_Write(uart_rd);
Lcd_Chr(1, 1, 's');
Lcd_Chr(1, 2, 'e');
Lcd_Chr(1, 3, 'n');
Lcd_Chr(1, 4, 't');
delay_ms(200);
goto L1;
}
void L2()
{
clroff();
Lcd_Chr(1, 1, 'Q');
Lcd_Chr(1, 2, 'u');
Lcd_Chr(1, 3, 'a');
Lcd_Chr(1, 4, 'n');
Lcd_Chr(1, 5, 't');
Lcd_Chr(1, 6, 'i');
Lcd_Chr(1, 7, 't');
Lcd_Chr(1, 8, 'y');
do {
kp3 = 0; // Reset key code variable
// Wait for key to be pressed and released
do
{ kp3 = Keypad_Key_Press();
} while (!kp3);
switch (kp3) {
case 1: kp3 = 49;
y3=1;
break; // 1
case 2: kp3 = 50;
y3=2;
break; // 2
case 3: kp3 = 51;
y3=3;
break; // 3
case 5: kp3 = 52;
y3=4;
break; // 4
case 6: kp3 = 53;
y3=5;
break; // 5
case 7: kp3 = 54;
y3=6;
break; // 6
case 9: kp3 = 55;
y3=7;
break; // 7
case 10: kp3 = 56;
y3=8;
break; // 8
case 11: kp3 = 57;
y3=9;
break; // 9
case 14:goto L1;
break;
default: Lcd_Chr(1,1,'i');
goto L1;
break;
}
Lcd_Chr(2,1,kp3);
do
{ kp9 = Keypad_Key_Press();
} while (!kp9);
if(kp9==16)
{
cost=y3*c3;
IntToStr(cost,tot);
clroff();
Lcd_Chr(1, 1, 'c');
Lcd_Chr(1, 2, 'a');
Lcd_Chr(1, 3, 's');
Lcd_Chr(1, 4, 'h');
Lcd_Chr(1, 5, ' ');
Lcd_Chr(1, 6, ' ');
Lcd_Chr(1, 7, ':');
Lcd_Chr(1, 8, ' ');
Lcd_Chr(1, 9, ' ');
Lcd_Chr(1, 10, ' ');
Lcd_Out(1, 11, tot);
delay_ms(1000);
Lcd_Chr(2, 1, '1');
Lcd_Chr(2, 2, '-');
Lcd_Chr(2,3, 'O');
Lcd_Chr(2, 4, 'r');
Lcd_Chr(2, 5, 'd');
Lcd_Chr(2, 6, 'e');
Lcd_Chr(2, 7, 'r');
Lcd_Chr(2, 8, ' ');
Lcd_Chr(2, 9, '2');
Lcd_Chr(2, 10, '-');
Lcd_Chr(2, 11, 'C');
Lcd_Chr(2, 12, 'a');
Lcd_Chr(2, 13, 'n');
Lcd_Chr(2, 14, 'c');
Lcd_Chr(2, 15, 'e');
Lcd_Chr(2, 16, 'l');
delay_ms(500);
do{
kp4=0;
do {
kp4 = Keypad_Key_Press();
}while (!kp4);
clroff();
switch(kp4)
{
case 1:
Lcd_Chr(1,1,'T');
Lcd_Chr(1,2,'h');
Lcd_Chr(1,3,'a');
Lcd_Chr(1,4,'n');
Lcd_Chr(1,5,'k');
Lcd_Chr(1,6,'s');
delay_ms(500);
goto L1;
break;
case 2:goto L1;
break;
case 14:goto L1;
break;
case 4:goto L3;
break;
case 8:goto L4;
break;
default:
Lcd_Chr(1,1,'i');
goto L1;
break;
}
}while(1);
}
} while(1);
}
[/code]
the main menu is displayed on the LCd screen initialy. when the user presses the key using keypad, it should display the sub menu and again it must get the user input and ask for the quantity required. after pressing the key it must multiply and display the total cash and then ask for placing the order or cancel. on getting the user input as order - it must display thankz and then go to the main menu. if cancel then it must go to main menu with out placing the order.
The problem in the below program is - it does not return to the main menu after displaying thankz but instead it goes to quantity.
please help me out.. what is the mistake here
int kp,kp9,kp1,kp2,itno,kp3,kp4,kp5,kp6,k;
unsigned short cost = 0;
int c3,y3;
char txt[20],txt1[5],txt2[5],tot[3],txt4[5]="1A1";
int i;
int L1,L3,L4,L5;
char *txt3,*txt5,uart_rd;
char keypadPort at PORTD;
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
void Move_Delay();
void lftshftdly();
void clroff();
void start();
void L2();
void Move_Delay() {
Delay_ms(100);
}
void lftshftdly()
{
for(i=0; i<2; i++) {
Lcd_Cmd(_LCD_SHIFT_LEFT);
Move_Delay();
}
}
void clroff()
{
Lcd_Cmd(_LCD_CLEAR);
}
void main() {
TRISB=0;
Keypad_Init();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
UART1_Init(9600);
Delay_ms(100);
start();
}
void start()
{
L1:clroff();
Lcd_Chr(1, 1, '1');
Lcd_Chr(1, 2, '-');
Lcd_Chr(1, 3, 'D');
Lcd_Chr(1, 4, 'R');
Lcd_Chr(1, 5, 'i');
Lcd_Chr(1, 6, 'n');
Lcd_Chr(1, 7, 'k');
Lcd_Chr(1, 8, 's');
Lcd_Chr(2, 1, '2');
Lcd_Chr(2, 2, '-');
Lcd_Chr(2, 3, 'S');
Lcd_Chr(2, 4, 'n');
Lcd_Chr(2, 5, 'a');
Lcd_Chr(2, 6, 'c');
Lcd_Chr(2, 7, 'k');
Lcd_Chr(2, 8, 's');
do {
kp=0;
do
{
kp = Keypad_Key_Press();
}while (!kp);
switch (kp) {
case 1: //kp = 49;
clroff();
delay_ms(200);
Lcd_Chr(1, 1, '1');
Lcd_Chr(1, 2, '-');
Lcd_Chr(1, 3, 'T');
Lcd_Chr(1, 4, 'e');
Lcd_Chr(1, 5, 'a');
Lcd_Chr(1, 6, '(');
Lcd_Chr(1, 7, 'R');
Lcd_Chr(1, 8, 's');
Lcd_Chr(1, 9, '1');
Lcd_Chr(1, 10, '0');
Lcd_Chr(1,11, ')');
Lcd_Chr(2, 1, '2');
Lcd_Chr(2, 2, '-');
Lcd_Chr(2, 3, 'C');
Lcd_Chr(2, 4, 'o');
Lcd_Chr(2,5, 'f');
Lcd_Chr(2, 6, 'f');
Lcd_Chr(2, 7, 'e');
Lcd_Chr(2, 8, 'e');
Lcd_Chr(2, 9, '(');
Lcd_Chr(2, 10, 'R');
Lcd_Chr(2,11, 's');
Lcd_Chr(2, 12, '2');
Lcd_Chr(2, 13, '0');
Lcd_Chr(2, 14, ')');
do{
kp1=0;
do {
kp1 = Keypad_Key_Press();
}while (!kp1);
clroff();
switch(kp1)
{
case 1:
c3=10;
itno=101;
L2();
break;
case 2:
c3=20;
itno=102;
L2();
break;
case 4:goto L3;
break;
case 8:goto L4;
break;
case 14:goto L1;
break;
default: Lcd_Chr(1,1,'i');
goto L1;
break;
}
}while(1);
break;
case 2:
clroff();
delay_ms(200);
Lcd_Chr(1, 1, '1');
Lcd_Chr(1, 2, '-');
Lcd_Chr(1, 3, 'P');
Lcd_Chr(1, 4, 'u');
Lcd_Chr(1, 5, 'f');
Lcd_Chr(1, 6, 'f');
Lcd_Chr(1, 7, ' ');
Lcd_Chr(1, 8, ':');
Lcd_Chr(1, 9, ' ');
Lcd_Chr(1, 10, 'R');
Lcd_Chr(1, 11, 's');
Lcd_Chr(1, 12, '1');
Lcd_Chr(1,13, '5');
Lcd_Chr(2, 1, '2');
Lcd_Chr(2, 2, '-');
Lcd_Chr(2, 3, 'P');
Lcd_Chr(2, 4, 'o');
Lcd_Chr(2, 5, 'p');
Lcd_Chr(2, 6, 'c');
Lcd_Chr(2, 7, 'o');
Lcd_Chr(2, 8, 'r');
Lcd_Chr(2, 9, 'n');
Lcd_Chr(2, 10, '(');
Lcd_Chr(2,11, 'R');
Lcd_Chr(2, 12, 's');
Lcd_Chr(2, 13, '4');
Lcd_Chr(2, 14, '0');
Lcd_Chr(2, 15, ')');
do{
kp2=0;
do {
kp2 = Keypad_Key_Press();
}while (!kp2);
clroff();
switch(kp2)
{
case 1:
c3=15;
itno=201;
L2();
break;
case 2:
c3=40;
itno=202;
L2();
break;
case 4:goto L3;
break;
case 8:goto L4;
break;
case 14:goto L1;
break;
default:
Lcd_Chr(1,1,'i');
goto L1;
break;
}
}while(1);
break;
case 4:goto L3;
break;
case 8:goto L4;
break;
case 14:goto L1;
break;
default: Lcd_Chr(1,1,'i');
delay_ms(200);
goto L1;
break;
}
} while (1);
L3: clroff();
uart_rd=0x46;
UART1_Write(uart_rd);
Lcd_Chr(1, 1, 's');
Lcd_Chr(1, 2, 'e');
Lcd_Chr(1, 3, 'n');
Lcd_Chr(1, 4, 't');
delay_ms(500);
goto L1;
L4: clroff();
uart_rd=0x4D;
UART1_Write(uart_rd);
Lcd_Chr(1, 1, 's');
Lcd_Chr(1, 2, 'e');
Lcd_Chr(1, 3, 'n');
Lcd_Chr(1, 4, 't');
delay_ms(200);
goto L1;
}
void L2()
{
clroff();
Lcd_Chr(1, 1, 'Q');
Lcd_Chr(1, 2, 'u');
Lcd_Chr(1, 3, 'a');
Lcd_Chr(1, 4, 'n');
Lcd_Chr(1, 5, 't');
Lcd_Chr(1, 6, 'i');
Lcd_Chr(1, 7, 't');
Lcd_Chr(1, 8, 'y');
do {
kp3 = 0; // Reset key code variable
// Wait for key to be pressed and released
do
{ kp3 = Keypad_Key_Press();
} while (!kp3);
switch (kp3) {
case 1: kp3 = 49;
y3=1;
break; // 1
case 2: kp3 = 50;
y3=2;
break; // 2
case 3: kp3 = 51;
y3=3;
break; // 3
case 5: kp3 = 52;
y3=4;
break; // 4
case 6: kp3 = 53;
y3=5;
break; // 5
case 7: kp3 = 54;
y3=6;
break; // 6
case 9: kp3 = 55;
y3=7;
break; // 7
case 10: kp3 = 56;
y3=8;
break; // 8
case 11: kp3 = 57;
y3=9;
break; // 9
case 14:goto L1;
break;
default: Lcd_Chr(1,1,'i');
goto L1;
break;
}
Lcd_Chr(2,1,kp3);
do
{ kp9 = Keypad_Key_Press();
} while (!kp9);
if(kp9==16)
{
cost=y3*c3;
IntToStr(cost,tot);
clroff();
Lcd_Chr(1, 1, 'c');
Lcd_Chr(1, 2, 'a');
Lcd_Chr(1, 3, 's');
Lcd_Chr(1, 4, 'h');
Lcd_Chr(1, 5, ' ');
Lcd_Chr(1, 6, ' ');
Lcd_Chr(1, 7, ':');
Lcd_Chr(1, 8, ' ');
Lcd_Chr(1, 9, ' ');
Lcd_Chr(1, 10, ' ');
Lcd_Out(1, 11, tot);
delay_ms(1000);
Lcd_Chr(2, 1, '1');
Lcd_Chr(2, 2, '-');
Lcd_Chr(2,3, 'O');
Lcd_Chr(2, 4, 'r');
Lcd_Chr(2, 5, 'd');
Lcd_Chr(2, 6, 'e');
Lcd_Chr(2, 7, 'r');
Lcd_Chr(2, 8, ' ');
Lcd_Chr(2, 9, '2');
Lcd_Chr(2, 10, '-');
Lcd_Chr(2, 11, 'C');
Lcd_Chr(2, 12, 'a');
Lcd_Chr(2, 13, 'n');
Lcd_Chr(2, 14, 'c');
Lcd_Chr(2, 15, 'e');
Lcd_Chr(2, 16, 'l');
delay_ms(500);
do{
kp4=0;
do {
kp4 = Keypad_Key_Press();
}while (!kp4);
clroff();
switch(kp4)
{
case 1:
Lcd_Chr(1,1,'T');
Lcd_Chr(1,2,'h');
Lcd_Chr(1,3,'a');
Lcd_Chr(1,4,'n');
Lcd_Chr(1,5,'k');
Lcd_Chr(1,6,'s');
delay_ms(500);
goto L1;
break;
case 2:goto L1;
break;
case 14:goto L1;
break;
case 4:goto L3;
break;
case 8:goto L4;
break;
default:
Lcd_Chr(1,1,'i');
goto L1;
break;
}
}while(1);
}
} while(1);
}
[/code]
Code: