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
So, are you _really_ sure your code is correct?
unsigned char c[10]; <= 10 elements
c[10]=chr; <= assigning to the 11th, element...
i=1; <= ignoring first character (zero) and start with second character (index 1). if(a[j][i]==c[i])
for(i=1;i<9;i++) { ... } if (i==10) { ... } <= how would i reach the value 10, when the loop ends if i reaches 9?
lcd_printxy(2,1,"NO"); <= printing "NO" even if you just printed "yes".
So - exactly how much did you verify your code? What was the result of the debugging? Did you really step through the code and check the values of the variables and how the execution jumped? Or did you just _assume_ what it would do?
Next thing - guess how much simpler your code would have been if you had stored the keys as strings:
char key[] = "00016221826"; char input_key[12] = ""; ... if (!strcmp(input_key,key)) { lcd_printxy(2,1,"yes"); }
Any special reason why you decided to ignore the suggestion to look at strcmp()?
the reason is-the data receiving through rs232 is not a string its a character. if u help me how to receive the string then I can follow ur method
the reason why i am starting the loop for i=1 is i dont want to compare the 1st character because when read it on hyper terminal it is showing $0062...... the rfreader is automatically including $, but $ is not present in the id-card. so I have taken an array of 11. I tried to take $ in the array of 11 numbers but it is giving syntax error. so i have replaced $ with 0 in the array i,e a[5][11]={{$,0,0,6,2.....},{$,0,4,6,7,8,.,.},.,.} is replaced with a[5][11]={{0,0,0,6,2,....},{0,0,4,6,7....},.,.,}. This is the reason I am taking i=1 in skipping 0($) as it is common for every no.
I am sorry for all other mistakes..
Yes; but a string is just a sequence of chatacters (plus a NUL terminator) - isn't it...?
BTW: Note how you've messed-up the thread by using the pre tags incorrectly...
"a[5][11]={{$,0,0,6,2.....},{$,0,4,6,7,8,.,.},.,.}"
Of course the above gives a syntax error.
Don't you realize the difference between characters and numbers?
0 is a number with value zero. You write it using a single digit. '0' is the ASCII character zero. It does not have the numeric value 0. It has the numeric value 0x30 = 48.
If you can see the codes on the hyperterminal, then the codes are sent out as printable text. So each character you receive on the serial port is a '0', '1', '2', ...
You really have to keep track of the difference betweeen 0 and '0' because you can't perform the comparison unless you have the same format on both sides of the comparison operator.
And you have to understand that the compiler can handle an array of numbers (as long as the numbers are within the range of the data type for the array) but numbers can't contain any $. And your arrays can just as well be filled with the characters '0', '1', '2', ...
C strings like "123" is an array of characters { '1', '2', '3', '\0' } which indicates what strcmp() would do when comparing a printable string of code digits as received from your RFID receiver with the strings you have stored as known keys.
Have you invested in a good book about C? Have you read it? Have you worked yourself through the exercises in the book?
C is not a language suitable for people who just try random code constructs.