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.
#include<reg51.h> void boud_rate() { SCON = 0x50; TMOD = 0x20; /* timer 1, mode 2, 8-bit reload */ TH1 = 0xFD; /* reload value for 2400 baud */ TR1 = 1; TI = 1; } char serial_receive() { char chr; /* variable to hold the new character */ while (RI != 1) {;} chr = SBUF; RI = 0; return(chr); } void main(void) { boud_rate(); unsigned char rx_data; for(;;) { rx_data = serial_receive(); switch(rx_data) { // case '1': open_door(); case 0067892341 : open_door(); break; // case '9': open_door(); case 0045780034 : open_door(); break; default: dont_open(); } proper_delay(); } }
errors
'rx_data':undefined identifier illigal octal digit
please tell me how to overcum these errors
Sorry, but no. You haven't debugged your code. It does not work when you step through it either.
You don't need to step through in a debugger - enough to follow the flow with pen and paper and try three different alternatives. Code matching first acceptable key. Code matching second acceptable key. Code not matching any key.
for (i = 0; i < ACCEPTABLE_INPUT_COUNT; i++) { j = strcmp(acceptable_inputs[i],input); if (j==0) { lcd_printxy(1,8,"yes"); input_pos=0; } else { lcd_printxy(1,1,"no"); input_pos=0; } }
How did you decide that if your input fails the test against the first code, it's a failure? Don't you think you need to iterate through the full array and first when all known codes mismatches, it's a fail?
Did't you notice that when you did your stepping through the code?
Why are you in such a hurry? The logic is simple. But to get something to work, you need to have the patience to work out all acceptable and unacceptable paths and verify that they they happen as expected. Any time you take a shortcut, you cut yourself. It is costing _you_ a lot of time, that you don't work a bit slower and really try to follow the logic of your code.
for (i = 0; i < ACCEPTABLE_INPUT_COUNT; i++) { j = strcmp(acceptable_inputs[i],input); if(j==0) break; } if (j==0) { lcd_printxy(1,8,"yes"); input_pos=0; } else { lcd_printxy(1,1,"no"); input_pos=0; }
as you said i am getting problem in this part of code. it is receiving all the characters but not able to compare, it is printing "no" on the lcd.. i am not able find out why it is happening so, Sir please help me out. which step of the above code should be corrected.
@Andrew Neil
Why don't you write a bit of the code at a time and test it before doing the next bit. You stand a chance of creating a whole project that works properly.
I thought the strings from the RFID reader ended with a newline. If so - how do you handle the line breaks?
And what is the result of your debugging? Soon one month later. Own time debugging the individual parts of the program would have made you finish this project about three weeks ago. Of course, that would have required you to take regular looks in a book about the C language, when the debugger showed you that a statement didn't do what you thought it would do.
Own time debugging the individual parts of the program ... take regular looks in a book about the C language if you need to do that then what are fora for?
Of course, I AM being Ironic.
Erik