I have been trying to learn to use PICs with 16F84A. I have written several programs as I go through the books by David Benson and online tutorials. Untill now I have gotten each to work after 2 or more trys. The one I am working with now is a interupt using the INT pin. The main program works fine and the interupt occures as it should but it does not return to the main program after the interupt. One other thing is that no matter what number I put in the FLASH_N file, it flashes 8 times. This was not the case at the beginning. I had d'4 in and it flashed 4 times but something changed. The program is supposed to flash portb bits 7, 4 and 1 at 1/2 second itervals and then upon interupt flash 7-4 at a faster rate then return to main. I have studied and changed the program multiple times to no success. Anyone wish to take a look and give me some guidence? Your time would be greatly appeciated. This is my first time posting an attachment. I am using MPLAB and a PicKit 2 programmer
You need to save the context before you begin the ISR and restore it afterwards. This means you need to store the W and status register and restore them later, look in the PIC datasheet for "Context Saving During Interrupts".
hi,
Running your program in simulation, it fails with a 'Stack Underflow' error.
This means you are 'popping' the Stack more times than you are 'pushing', often caused by calling a subr with a 'Goto' that has a Return at the end.
Taking a quick look at your new file and i see that the delay subroutines you call from within the main program loop and the one you call from within the ISR share the same variables.
If a interrupt occurs while the mainloop is running one of the delay functions (very likely, as it spends most of its time there), the second call to the delay functions from within the interrupt routine messes up the DelayM and DelayH variables.
You should use seperate variables for the delay500 and delay200 routine.
main movlw b'01101101' ;rb7, 4, and 1 lo LEDs on
movwf portb
call delay500
movlw b'10010010' ;change lo bits to compliment
xorwf portb,f ;--all leds off
call delay500
[COLOR="red"]btfsc portb,0 ;test rb0 for interupt lo i.e. clear
goto main ;do again
goto iserv[/COLOR]
goto main ;on return from interupt goto main
Interrupts don't need to be called, the hardware does that automatically. The bit in red should be deleted.
As already pointed out, your delays shouldn't be called from both the main code and the interrupt.
Thanks for the replies! I'll try these corrections later today and post the new results then. Just in reading these repies I have learned vauable information. Thanks again!
Aaron
Wal-la!
I got rid of the problem code per Pommie and made the delay variables different in each delay per Exo with the context saved, and now it works as it's supposed to. I wish I could return the favor!
Aaron