We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am currently making a very simple vending machine project which uses the 8051 microcontoller. the pins im using is
sbit C=P3^3; ////// "C" is for coffee/////// sbit T=P3^4; ////// "T" is for tea/////// sbit H=P3^5; ////// "H" is for hot/////// sbit D=P3^6; ////// "D" is for cold/////// sbit S=P3^7; ////// "S" is for purchasing/////
i have done the coding for lcd initialization and selection.. the problem now is that i need the program to run in sequence for example
sequence one: customer should be able to choose only "C" or "T".. (during this sequence all the other pins should be disabled)
sequence two: customer should be able to choose only "H" or "D"..
sequence three: once the above sequence is completed only then customer can press the push button..
The question is how can i disable the other pins at respective sequences.. my code for the selection part is below..
void main () { TMOD=0x02; TH0=0xA4; IE=0x00; L1= L2= 0; a = 0; lcd_ini(); delay(20); lcd_command(0x01); lcd_string("Select Drink"); delay(200); lcd_command(0x01); lcd_string("1.Coffee 2.Tea"); delay(20); flagset=0; TR1 = 0; while (1) { if (C==0) { delay(30); lcd_command(0x01); lcd_string("Coffee: Hot/Cold"); } if (T==0) { delay(30); lcd_command(0x01); lcd_string("Tea: Hot/Cold"); } if (H==0) { delay(30); lcd_command(0x01); lcd_string("Hot Selected"); } if (D==0) { delay(30); lcd_command(0x01); lcd_string("Cold Selected"); } if (M1==0) { delay(30); b++; switch(b) {case 1: lcd_command(0x01); lcd_string("RM 1.00 Inserted"); delay(20); break; case 2: lcd_command(0x01); lcd_string("RM 2.00 Inserted"); delay(20); break; case 3: lcd_command(0x01); lcd_string("Insert Money"); if (b==3) {b=0;}} } if (S==0) { lcd_command(0x01); lcd_command(0x80); lcd_string("Processing"); delay(100); lcd_command(0x01); lcd_command(0x80); lcd_string("Please wait"); L1 = 1; delay(100); L1 = 0; ///////L1 and L2 is for lights/////// L2 = 1; lcd_command(0x01); lcd_command(0x80); lcd_string("Remove drink"); delay(100); L2 = 0; lcd_command(0x01); lcd_command(0x85); lcd_string("Thankyou"); delay (500); } } }
thank you in advance
i wanted to do so.. but i was not sure how to make my codes to not look at the input.. i mean i dont know what commands to use.. is there any suggestion??
start with this
if (T==0) { State = something indicating where you are
etc
and then when a key is pressed ignore it if 'state' is such that it should be
can u show me an example.. im really bad in C language.. for example can u show me when coffee is selected, i want to ignore the cold and hot selection..
can u show me an example since you are specifically asking micro (u) send him an e-mail
Erik
i'm sorry.. i'm very used to writing in short forms.. wont happen again..
if (T==0) { if (state = whatever_state_allow_T) { State = whatever_state_indicates_what_is_allowed_After_T_is_pressed; .....</pre? whatever_state_allow_T and whatever_state_indicates_what_is_allowed_After_T_is_pressed are both constants; you can even make an enum of the states oddly enough the above will take care of your missing debounce as well This is all you get from me, I will not write your code for you Erik
thank you so much for your help.. i really appreciate it.. i will try do as you have instructed.. thanks again Mr.Erik..
Bad Erik - do you compare or assign in that expression? :p
yeah, busy slapping my hands with a ruler.
'=='
A trick is to write the constant or enumerator to the left and the variable to the right.
Then the compiler will complain about lvalue if you accidentally write an assign. Getting a compilation error instead of a warning is good.
Then the compiler will complain about lvalue if you accidentally write an assign. Getting a compilation error instead of a warning is good. by my philosophy there is no difference between errors and (unintended) warnings.
Intended warning: a warning that is a result of some (later removed) test
by my philosophy there is no difference between errors and (unintended) warnings.
Absolutely. In my book a warning should be treated as an error unless proven otherwise.
But an error has the advantage that it results in a build failure. While a warning may always tempt someone to ignore, or add a one-time excemption or maybe totally turn off one specific message.
Would highly recommend enabling the option "treat warnings as errors". If someone is hell bent on removing an error, they could just swap over the constant and enumerator.
It's always difficult to successfully predict what an idiot programmer is capable of doing.
Unfortunately, I have witnessed such thinking. And at least once from someone who was considered to be competent engineer!
While a warning may always tempt someone to ignore
'someone' may be an idiot 'someone' may not.
I know that a lot of 'modern tools' put a large emphasis towards protecting idiots from doing idiotic things, but the best method still is not to ask an idiot to do the job.