Ok , so I have this project here, that was already finished, but I am trying t o figure out how the calltable works. The thing is just suppose to blink leds in order, and it does do this. My question is with following code below :
Blink
decfsz BLNKCNT,F ;Decrement loop counter and return if not zero
goto BlinkEnd
movlw HalfSec ;Reinitialize BLNKCNT
movwf BLNKCNT
call BlinkTable ;Toggle the LED
movwf PORTC
BlinkEnd
return
NOW when we do a call BlinkTable we get
BlinkTable
1 movf PORTC,W ; copy the present state of the LEDs into W
2 andlw B'00000111' ; keep only the 3 LSBs
3 addwf PCL, F ; change PC
4 retlw B'00000001' ; 000 -> 001
5 retlw B'00000010' ; 001 -> 010
6 retlw B'00000100' ; 010 -> 100
7 nop ; 011
8 retlw B'00000001' ; 100 -> 001
(note that i put the numbers running down the screen to explain my problem).
Ok. What I dont get is how the table works. THe thing is suppose to blink every 5 seconds. So does it execute lines 1-3 then goes onto line 4 ,and does retlw, and loads the w register with following binary, then returns from subroutine ? Then when it goes around the program ( blinks the led on for 5 seconds) then comes back to turn on the 2nd led, how does it know that it should go to line 5? Does it skip or something the previous lines, cause the count was incremented by 3, and we already have one , so then go to line 4 ? I am really confused on this.
Thanks for the help
t
Blink
decfsz BLNKCNT,F ;Decrement loop counter and return if not zero
goto BlinkEnd
movlw HalfSec ;Reinitialize BLNKCNT
movwf BLNKCNT
call BlinkTable ;Toggle the LED
movwf PORTC
BlinkEnd
return
NOW when we do a call BlinkTable we get
BlinkTable
1 movf PORTC,W ; copy the present state of the LEDs into W
2 andlw B'00000111' ; keep only the 3 LSBs
3 addwf PCL, F ; change PC
4 retlw B'00000001' ; 000 -> 001
5 retlw B'00000010' ; 001 -> 010
6 retlw B'00000100' ; 010 -> 100
7 nop ; 011
8 retlw B'00000001' ; 100 -> 001
(note that i put the numbers running down the screen to explain my problem).
Ok. What I dont get is how the table works. THe thing is suppose to blink every 5 seconds. So does it execute lines 1-3 then goes onto line 4 ,and does retlw, and loads the w register with following binary, then returns from subroutine ? Then when it goes around the program ( blinks the led on for 5 seconds) then comes back to turn on the 2nd led, how does it know that it should go to line 5? Does it skip or something the previous lines, cause the count was incremented by 3, and we already have one , so then go to line 4 ? I am really confused on this.
Thanks for the help
t