Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

vending machine error in code

Status
Not open for further replies.

jokester4u

Junior Member level 2
Junior Member level 2
Joined
Nov 26, 2013
Messages
20
Helped
1
Reputation
2
Reaction score
0
Trophy points
1
Visit site
Activity points
124
how do i add if inside if to represent if a key press to give a choose to select hot drink and cold drink . and when its hot drink then the hot drink also have menu for tea and coffee. and if tea it should display the cost .... this is what i have done but it stuck at option tea.. and it doesnt go for the cost


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
lcddata("1. HOTT DRINK");
command(0xC0);
lcddata("2. COLDD DRINK");}
 
if(key1==0)
{
command(0x01);
command(0x06);
lcddata("3. TEAA");
 
 
if(key3==0)
{command(0x01);
command(0x06);
lcddata("INSERT 1.55 RM");
command(0xC0);
lcddata(" FOR TEAA "); } }

 
Last edited by a moderator:

The cost text is displayed if you press key1 and key3 simultaneously. I guess that's not what you intend.

The overall code structure doesn't seem to be well considered, something that should be started with pencil and paper method. Presently there's no delay or wait for input which is apparently required for a reasonable execution flow.
 
I wrote this code in a hurry. Not tested...


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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Project:  Vendee
* Author:   Jayanth Devarayanadurga
* Date:     26 Nov 2013
* Time:     7:03 PM
*/
 
unsigned char displayFlag = 0, optionFlag = 0, choiceFlag = 0;
 
 
void main(){
 
 
    //PORT Initialization here...
 
    //LCD Initialization here...
 
 
    command(0x80);
    lcddata("1. HOT DRINK");
    command(0xC0);
    lcddata("2. COLD DRINK");
 
    while(1){
 
        if(displayFlag){
 
            switch(optionFlag){
 
                case 0:
                        command(0x80);
                        lcddata("1. HOT DRINK?   ");
                        command(0xC0);
                        lcddata("2. COLD DRINK?  ");
 
                        displayFlag = 0;
 
                        break;
 
                case 1:
                        command(0x80);
                        lcddata("1. COFFEE?      ");
                        command(0xC0);
                        lcddata("2. TEA?         ");
                    
                        displayFlag = 0;
 
                        break;
                
                case 2:
                        command(0x80);
                        lcddata("1. COLA?        ");
                        command(0xC0); 
                        lcddata("2. XYZ?         ");
 
                        displayFlag = 0;
 
                        break;
 
                case 3:
                        if((optionFlag == 1) && (choiceFlag == 1)){
                            command(0x80);
                            lcddata("INSERT 2.55 RM  ");
                            command(0xC0);
                            lcddata("FOR COFFEE      ");
                        }
                        else if((optionFlag == 1) && (choiceFlag == 2)){
                            command(0x80);
                            lcddata("INSERT 1.55 RM  ");
                            command(0xC0);
                            lcddata("FOR TEA         ");
                        }   
                        else if((optionFlag == 2) && (choiceFlag == 1)){
                            command(0x80);
                            lcddata("INSERT 5.55 RM  ");
                            command(0xC0);
                            lcddata("FOR COLA        ");
                        }
 
                        else if((optionFlag == 2) && (choiceFlag == 2)){
                            command(0x80);
                            lcddata("INSERT 7.55 RM  ");
                            command(0xC0);
                            lcddata("FOR XYZ         ");
                        }                   
 
                        break;
 
                case 4:
                        command(0x80);
                        lcddata("Please Collect");
                        command(0xC0); 
                        lcddata("Your item     ");
 
                        optionFlag = 0
                        choiceFlag = 0;
            
                        displayFlag = 1;
 
                        //Delay of 5 seconds
                        
                        break;
            };                  
 
        }
 
 
        if((!key1) && (key2) && (key3)){    
            //Delay 50 ms
            while((!key1) && (key2) && (key3)); 
            
            if(optionFlag){optionFlag = 3; choiceFlag = 1;}
 
            optionFlag = 1;
            displayFlag = 1;                    
 
        }
        else if((key1) && (!key2) && (key3)){   
            //Delay 50 ms
            while((key1) && (!key2) && (key3)); 
        
            if(optionFlag){optionFlag = 3; choiceFlag = 2;}
 
            optionFlag = 2;
            displayFlag = 1;
        }
        else if((key1) && (key2) && (!key3)){   
            //Delay 50 ms
            while((key1) && (key2) && (!key3));     
            
            optionFlag = 4;
            displayFlag = 1;
        }
    }
}

 
Last edited:
The cost text is displayed if you press key1 and key3 simultaneously. I guess that's not what you intend.

The overall code structure doesn't seem to be well considered, something that should be started with pencil and paper method. Presently there's no delay or wait for input which is apparently required for a reasonable execution flow.

Yes when i press key1 and key3 simultaneously it displays the cost. i dont understand why this happens . can you help me with it ?
 

Yes when i press key1 and key3 simultaneously it displays the cost. i dont understand why this happens . can you help me with it ?
It's the only way to reach the code after if(key3==0) which is also included in the if(key1==0) condition.
 

It's the only way to reach the code after if(key3==0) which is also included in the if(key1==0) condition.

I have pm you can you please check and solve it ?

- - - Updated - - -

I have pm you my simulation and code can youu please fix it


I wrote this code in a hurry. Not tested...


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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Project:  Vendee
* Author:   Jayanth Devarayanadurga
* Date:     26 Nov 2013
* Time:     7:03 PM
*/
 
unsigned char displayFlag = 0, optionFlag = 0, choiceFlag = 0;
 
 
void main(){
 
 
    //PORT Initialization here...
 
    //LCD Initialization here...
 
 
    command(0x80);
    lcddata("1. HOT DRINK");
    command(0xC0);
    lcddata("2. COLD DRINK");
 
    while(1){
 
        if(displayFlag){
 
            switch(optionFlag){
 
                case 0:
                        command(0x80);
                        lcddata("1. HOT DRINK?   ");
                        command(0xC0);
                        lcddata("2. COLD DRINK?  ");
 
                        displayFlag = 0;
 
                        break;
 
                case 1:
                        command(0x80);
                        lcddata("1. COFFEE?      ");
                        command(0xC0);
                        lcddata("2. TEA?         ");
                    
                        displayFlag = 0;
 
                        break;
                
                case 2:
                        command(0x80);
                        lcddata("1. COLA?        ");
                        command(0xC0); 
                        lcddata("2. XYZ?         ");
 
                        displayFlag = 0;
 
                        break;
 
                case 3:
                        if((optionFlag == 1) && (choiceFlag == 1)){
                            command(0x80);
                            lcddata("INSERT 2.55 RM  ");
                            command(0xC0);
                            lcddata("FOR COFFEE      ");
                        }
                        else if((optionFlag == 1) && (choiceFlag == 2)){
                            command(0x80);
                            lcddata("INSERT 1.55 RM  ");
                            command(0xC0);
                            lcddata("FOR TEA         ");
                        }   
                        else if((optionFlag == 2) && (choiceFlag == 1)){
                            command(0x80);
                            lcddata("INSERT 5.55 RM  ");
                            command(0xC0);
                            lcddata("FOR COLA        ");
                        }
 
                        else if((optionFlag == 2) && (choiceFlag == 2)){
                            command(0x80);
                            lcddata("INSERT 7.55 RM  ");
                            command(0xC0);
                            lcddata("FOR XYZ         ");
                        }                   
 
                        break;
 
                case 4:
                        command(0x80);
                        lcddata("Please Collect");
                        command(0xC0); 
                        lcddata("Your item     ");
 
                        optionFlag = 0
                        choiceFlag = 0;
            
                        displayFlag = 1;
 
                        //Delay of 5 seconds
                        
                        break;
            };                  
 
        }
 
 
        if((!key1) && (key2) && (key3)){    
            //Delay 50 ms
            while((!key1) && (key2) && (key3)); 
            
            if(optionFlag){optionFlag = 3; choiceFlag = 1;}
 
            optionFlag = 1;
            displayFlag = 1;                    
 
        }
        else if((key1) && (!key2) && (key3)){   
            //Delay 50 ms
            while((key1) && (!key2) && (key3)); 
        
            if(optionFlag){optionFlag = 3; choiceFlag = 2;}
 
            optionFlag = 2;
            displayFlag = 1;
        }
        else if((key1) && (key2) && (!key3)){   
            //Delay 50 ms
            while((key1) && (key2) && (!key3));     
            
            optionFlag = 4;
            displayFlag = 1;
        }
    }
}

 

I tested my code and there were bugs. I fixed them. I am attaching .hex and Proteus file. Test the simulation (working) throughouly and reply.


Edit: I saw the links related to your Vending Machine project you sent through PM. It has a lot of functions and I am not going to write a free code but I can help you if you provide the texts to be displayed for each menu.

Just provide the menu info as an expanded tree.
 

Attachments

  • Vendee.rar
    14.7 KB · Views: 75
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top