
Originally Posted by
elec_mech
I haven't played with interrupts yet, but I'll be starting with those next week if not today. When you say poll the interrupt bit, bare with me, you mean set portb.2, for example, as an interrupt, read in the character when one is detected into a byte of my array (in this case RX[#]) and continue doing so until I get the last character? Also, I presume I can use another interrupt and hopefully set one as a higher priority than the other?
Thats not quite what I mean. A pic has a few different interrupts. Things like timer0, received character, and portb.0 are all things that can interrupt the processor. Portb.0 is an external interrupt.
Now on the 16F devices when an interrupt occurs the program jumps to a set mem location (this is in assembly...not PBP) if you have enabled the interrupt (ie it is not masked). It is up to the programmer to test which interrupt caused the program to jump to the interrupt vector. The programmer also needs to save a bunch of stuff (context saving) upon entering the ISR and then needs to restore it all when leaving the ISR. I am only a little familiar with the 18F parts but I know that they have even more registers associated with interrupts. Now this sounds like alot of work. But there is a trick.
You see interrupt bits toggle regardless of if you have set up any interrupt registers! This means that if you start a timer and it overflows the timer overflow (TMRIF) bit gets set. So if you where to find out what register and bit will toggle when your event occurs then you poll that bit by doing a compare inside of your loop. Something like :
Code:
loop:
'do some stuff here
'and some more here
if TMRIF = 1 then 'now check to see if the timer over flowed
TMRIF = 0 'it did so reset the bit
My_counter = My_counter + 1 'increment the counter
endif
goto loop
For this to work you would create an alias to the timers interrupt flag and call it TMRIF. You would also need to start the harware timer by setting the appropriate bit in the appropriate register.
Now if you where to use the UART you would get a bit set (RCIF, received character interrupt flag) whenever a character came in! And all you would need to do would be to load the character into a variable to reset the bit. This would look something like this:
Code:
loop:
'do some stuff here
'and some more here
if RCIF = 1 then char_in = RCV_IN
goto loop
For this example to work you would need to create an alias for the received character interrupt flag and name it RCIF and an alias for the buffer that holds the received character and name it RCV_IN. Also you would need to set up the comms parameters.
Hope this helps.
Joe.
Edit....You REALLY need the data sheet for your PIC!
Bookmarks