#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
How about:
unsigned char rx_data; boud_rate();
#include<reg51.h> void baud_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) { #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) { baud_rate(); unsigned char rx_data; for(;;) { rx_data = serial_receive(); switch(rx_data) { case 0067892341 : open_door(); break; case 0045780034 : open_door(); break; default: dont_open(); } proper_delay(); } } errors rx_data:undefined identifier illigal octal digit
So #include<reg51.h> inside main()?
And void boud_rate() inside main()?
And then a second main()?
Do you always do your copy/paste without checking what the result is?
I am very sorry for the mistake, plz help me to solve the errors. here in the program I am using decimal no no starting with zero, but it is taking as a octal digit. how to make it as a decimal?
#include<reg51.h> void baud_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) { baud_rate(); unsigned char rx_data; for(;;) { rx_data = serial_receive(); switch(rx_data) { case 0067892341 : open_door(); break; case 0045780034 : open_door(); break; . . . . default: dont_open(); } proper_delay(); } } errors rx_data:undefined identifier illigal octal digit
If you are going to pay someone $100 - do you then specifically write $00100?
If the compiler takes these numbers as octal - have you then taken a look at the language definition (lots and lots of books are available if you haven't access to the languge standard) to see how you in C define decimal, octal or hexadecimal numbers? Any book at least decent about describing the C language would tell you that 0x or 0X is the start of a hexadecimal number, and 0 (but not followed by X or x) is the start of an octal number.
Note that 10-digit decimal numbers spans 0 to 9,999,999,999. Do you think your C51 compiler supports that numeric range? So maybe you should consider using C strings and perform comparisons with strcmp() instead? You will not be able to use a switch statement, but at least you don't need to worry about the number of digits in each code compared to the numeric ranges supported by the target processor.
Another thing - with string comparison based on an array of known codes, you can break out your valid codes from the source code. With a switch statement, you do need to modify that switch statement whenever you need to change, add or remove a code.
OK, I'll lead you by the nose.
the reason that you are getting the rx_data: undefined identifier is that you are defining the variable after the call to baud_rate(). you can't define a variable after code in a code block.
your case statement is not going to work. rx_data is a single character, not a string of characters. You need to receive a number of characters, put them into an array, and then compare that array to your keys. a switch statement will not work for the array comparison.
Most of all, you need to pick up your C textbook.
OK, I'll lead you by the nose
did it hurt when you put the ring in?
... is that he REFUSES to read a C book before "writing" 'C'. His posts smell highly of "writing" 'C' after "studying" a couple of 'C' programs.
answer his most basic questions and he will be back tomorrow with "what is up on a resistor?"
I DO believe in helping posters, but the OPs questions show a fundamental lack of understanding the most basic aspects of programming.
Erik
View all questions in Keil forum