Hi all, New to this forum in a posting perspective but it's been a great help in a lot of areas from the start of my 8051 classes this year and last year so for that thanks. Im coming near the end of my final year project and I'v come across a slight problem with my interrupt implementation. I have RTFMed about all I can find on interrupts from any number of sources before you tell me to Please read the manual. The problem is that my ISR is triggered fine the first time sets a flag goes back carries out a function ... due to it not being a good idea to have function calls within an ISR ... resets flag and then sits reading the clock again however when I try to interrupt again it will not carry out the ISR this next time.
I have : reset external interrupt flag; reset condition variable flag; even attempted to re-enable external interrupt (even though this is probably not required);
The code is a long one so Id rather not post the entire thing here if anyone wants to take a look at it who has a good idea as to what I'm doing wrong or if anyone wants to suggest a specific part to post to look at the ISR or the menu its being called from please contact me. I will however not be sending this code on to anyone who's just looking for something to copy as I've read the manual to get it this far. I'd also be very happy to have someone look over the code in general for bad programming implementation if they would ... I'm a student in this subject but I've a keen interest in the field.
Also I'm Irish but this website is picking me up in America for some reason ?
Regards Robbie.
Was a little silly to not include any code at all so here is my ISR ... my project is an RFID orienteering tag system and the elements in the array are correct for my usage before anyone points it out to me it is working its just that I cannot get it to retrigger the external interrupt after including (2) which is a small part of (3).
(1) //ISR void enter (void) interrupt 0 { while (1) { receive(); writecmd(0x99); if (card_id[2,3,4,5,6,7,8,9,10,11,12,13] == kite1[0,1,2,3,4,5,6,7,8,9,10,11]) { kite1_f = 1; delay(10000); IE = 0; return; } if (card_id[2,3,4,5,6,7,8,9,10,11,12,13] == kite2[0,1,2,3,4,5,6,7,8,9,10,11]) { kite2_f = 1; delay(10000); IE = 0; return; } if (card_id[2,3,4,5,6,7,8,9,10,11,12,13] == kite3[0,1,2,3,4,5,6,7,8,9,10,11]) { kite3_f = 1; delay(10000); IE = 0; return; } if (card_id[2,3,4,5,6,7,8,9,10,11,12,13] == kitef[0,1,2,3,4,5,6,7,8,9,10,11]) { kitef_f = 1; delay(10000); IE = 0; return; } else { writecmd(0x99); delay(4000000); writedata('R'); writedata('e'); writedata('t'); writedata('r'); writedata('y'); writedata('!'); return; } } } (2) if (kite1_f >= 1) { writecmd(0x99); writeline_lcd("Kite 1 scanned! "); split1[1]=c; split1[2]=e; split1[3]=f; delay(40000000); writecmd(0x99); writeline_lcd("Go To Kite 2 "); delay(10000); kite1_f = 0; }
while (1) it seems you are confusing an ISR as a task drop the while
Thanks for that it was a little redundant I've removed the while but to no avail. It was a leftover from the troubleshooting of single elements of my scanned array would you have a look at my entire code its very hard to get a grasp of what I'm doing with the singular portion of code. shown below is where I am implementing the ISR.
void menu3(void) { ReturnHome(); //Return to top left of LCD disable_interrupt; delay(150); //delay writeline_lcd("Please approach the "); //String of text to prompt user to go to start line of course writecmd(0xC0); //jump to second line of LCD writeline_lcd("Start RFID to begin "); //text string writecmd(0x94); //Jump to next line of LCD writeline_lcd(" "); //Insert blank field here writecmd(0xD4); //Jump to next line of LCD writeline_lcd("00:00:00 "); //Setup clock at 000000 so that the clock function will overwrite this when it starts Rfid_check(); //Starting start RFID checker function IE0 = 0; enable_interrupt; while (1) { while(add<=3) //update real time clock { write_i2c(0xD0,add,clock[add]); //Write to the I2C line the address of device add++; } stop(); while (1) { writecmd(0xD4); c=read_i2c(0xD0,0x02); //read hours register writedata((c/16)+48); //take info recieved by I2C divide by 16 to get hex value and then add 48 to get ascii version of character writedata((c%16)+48); //take info recieved by I2C divide by 16 to get hex value and then add 48 to get ascii version of character writedata(':'); //Write : to screen for between hours and minutes delay(10); e=read_i2c(0xD0,0x01); //read minutes register writedata((e/16)+48); //take info recieved by I2C divide by 16 to get hex value and then add 48 to get ascii version of character writedata((e%16)+48); //take info recieved by I2C divide by 16 to get hex value and then add 48 to get ascii version of character writedata(':'); //Write : to screen for between minutes and seconds delay(10); f=read_i2c(0xD0,0x00); //read seconds register writedata((f/16)+48); //take info recieved by I2C divide by 16 to get hex value and then add 48 to get ascii version of character writedata((f%16)+48); //take info recieved by I2C divide by 16 to get hex value and then add 48 to get ascii version of character writedata(' '); //End with a space delay(100); //delay
contd...
if (kite1_f >= 1) { writecmd(0x99); writeline_lcd("Kite 1 scanned! "); split1[1]=c; split1[2]=e; split1[3]=f; delay(40000000); writecmd(0x99); writeline_lcd("Go To Kite 2 "); delay(10000); kite1_f = 0; } if (kite2_f >= 1) { writecmd(0x99); writeline_lcd("Kite 2 scanned! "); delay(40000000); writecmd(0x99); writeline_lcd("Go To Kite 3 "); delay(10000); kite2_f = 0; } if (kite3_f >= 1) { writecmd(0x99); writeline_lcd("Kite 3 scanned! "); delay(40000000); writecmd(0x94); writeline_lcd("Go To Kite 4 "); delay(10000); kite3_f = 0; } if (kite4_f >= 1) { writecmd(0x99); writeline_lcd("Kite 4 scanned! "); delay(40000000); writecmd(0x94); writeline_lcd("Return to Finish "); delay(10000); kite4_f = 0; } if (kitef_f >= 1) { writecmd(0x99); writeline_lcd("Course complete! "); delay(40000000); writecmd(0x94); writeline_lcd("Return to Finish "); delay(10000); return; } } }
Apologies it seems I missed one of the tabs. Does the enable_interrupt need to be used after resetting the external interrupt flag some say yes and other implementations don't seem to require it. Thanks in advance.
What do you think that does??
What do I think what does ? If you mean the enable_interrupt I have it defined to set EA high which is what I needed to do to enable me to skip the first RFID scanned as intended. Im sorry I'm not sure what you mean ?
The text of my post refers to the title of that post; viz,
card_id[2,3,4,5,6,7,8,9,10,11,12,13] == kitef[0,1,2,3,4,5,6,7,8,9,10,11]
What do you thing that does??
Sorry only saw what you were referring to in the heading there. What I'm doing there is comparing from the 2-13 element of the scanned array to the 0-11 elements of a predefined RFID tag I've debugged this part of my code over a week and it does in fact compare each element to its opposing element and do exactly as intended.
No, in fact - you're not.
The 'C' programming language does not have any such way to compare multiple array elements
Time to revisit the 'C' text book!
Hint: look up the comma operator...
Ah bugger ... Well I'm kind of confused then I'm not sure how the if statement is working then as its able to differentiate between about 15 different tags I'm using. With some tags the first number elements are exactly the same as others and with others they are completely different.
Ah ha ! Thanks for that, that could have been embarrassing. Ok i'll have to rewrite that just a tad :p. Any chance you can see any such silly mistakes in the ISR and my implementation of it taking that the ISR is working for a comparison of the final elements of the listed arrays. I want to get this part working before I tackle the problem of comparing the complete tag ID as it is the more important at the minute.
Thanks again so here is my resolution to the aforementioned error you pointed out:
unsigned char i = 0; receive(); writecmd(0x99); if (card_id[13] == kite1[13]) { for (i=2;i<14;i++) { check=card_id[i]-kite1[i]; errors = errors + check; } if (errors != 0) { writedata('E'); writedata('R'); writedata('R'); writedata('O'); writedata('R'); writedata('!'); } else { kite1_f = 1; delay(10000); IE = 0; } }
Can you see any problems with this ?
And any input on the ISR as a whole problem would be a big help.
Yes:
check=card_id[i]-kite1[i]; errors = errors + check;
'check' could be positive or negative - so errors could "cancel-out"...
You test fails as soon as any mismatch fails - so you just need to flag that a mismatch was found (and there's no need to continue the loop beyond that).
Also, you are checking at the same index in each array - which isn't what your original code intended...
What I mean is, you need to construct a test that will indicate "fail" if any mismatch is found.