peter002
Member level 3
- Joined
- Mar 18, 2013
- Messages
- 56
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Hindusthaan
- Activity points
- 1,765
You are starting to get there!
You are actually duplicating some of your code, if you move "NO_INT" to above the previous "MOVF PCLATH,W" you can remove everything after the first RETFIE.
However, you still miss the point about what interrupts are for and the first line "GOTO ISR" should not be there as it simply jumps to the next instruction. Unless you are very sure PORTC,5 is going to change faster than TMR1 rolls over, you shouldn't use the loop inside the ISR either.
That is correct. A subroutine is called from within your program, an interrupt is triggered by some hardware event. In your program, that event is TMR1 rolling over. It means that whenever it rolls over, regardless of where the program is running at the time, an immediate call to address 4 is made. Inside the PIC the difference is that a 'call' instruction saves the address of the next instruction to be executed on the stack so that when you 'return', it continues from after the call. An interrupt is similar except that as well as the address being saved to the stack, the interrupts are also disabled. That is because on PIC16 devices you can't interrupt a running interrupt. When you use RETFIE it is like a normal 'return' instruction but it also re-enables any interrupts again.
It might be possible to do it that way, it depends on your program but the safe way is to use that specific code using swap instructions. The reason is that because an ISR can be triggered at any time, it is essential that AFTER the ISR has finished (after the retfie), things carry on as before. If you change W, PCLATH or the STATUS register in the ISR code they will still be different when the main code resumes and that could have bad consequences in your program. Using the swap method rather than movwf does not change any of the bits in the STATUS register so it helps to preserve them before returning.
Brian.
OK, thats awesum, many things clerared in that topic,
now acc. to my code as i m not using any hardware interrupt, to get the cpu execution to the isr address i hav two options only,
1. is that after triggering the ultrasonic sensor i hav to call the timr11 atleast for once so wen ever it rolls over it vl generate tmr1if interrupt
2. is that i hav to enable RB0 interrupt on portb that vl enable the hardware interrupt right after the trigger routine gets over and ultrasonic sensor pulls its echo pin at high state that vl be connected to RB0..?????
if i call timer11 for atleast once then it vl consume 58us without any usefull task, so i must use hardware interrupt by rb0 on portb???
and can i place more isrs at 0x0004?? and by polling to diff interrupt bits i can get to know that which interrupt caused the jump and then select the desired isr to be used and then return to main code after isr has served its purpose????
btw this method totally opened a diff way for the coding and gave many more views to my programming,, many things seems systemetic to me by now,
thanx bro Brian...
Last edited: