Would someone look at this branching code and tell me if there is something wrong.
What I'm trying to do is receive a message from another PIC via USART and then branch accodingly. I have simplified my actual code so you can understand it w/o the whole program. I'm using 18 series chips for both send and receive.
Code:
usart_in
movf rcreg,w ;get info into wreg
cpfslt number ;if number (0xf9) is less than wreg,(I.E. W is greater)
; skip next instruction
bra set_A
sublw 0xfa ;if wreg is 0xfa
btfsc status,z ;
bra Set_B ;yes, Z is set
sublw 0xfb ;if wreg is 0xfb
btfsc status,z ;
bra Set_C ;yes, Z is set
;other tests for 0xfc-0xff
return
I have reserved 0xfa-ff for instructions. Everything below 0xfa will be displayed as a 3 digit decimal. It works until I add the FB test, then seems to reset or go back to the front of program. I have tried both using interrupts and just polling the receive flag RCIF. The USART part works fine.
If you have already subtracted 0xfa from W then to check for 0xfb only requires you to subtract 1 more. Alternatively, reload W before the second subtract.
You know, as I was getting into bed last night, I thought of the fact that W may be changed before the 2nd test, and your reply and my looking at the datasheet this morning confirmed that.
Thanks Mike
Just one more confirmation of my understanding. On the instructions CPFSEQ/GT/LT the contents of the wreg is not changed by these instructions. Am I right?
Just one more confirmation of my understanding. On the instructions CPFSEQ/GT/LT the contents of the wreg is not changed by these instructions. Am I right?
I believe your code and mine accomplish the same, provided I reload W before each test as POMMIE said. Short answer, Yes. That part of my code has been corrected but still have a problem. I will start a new thread as the title of this one doesn't apply. See 'Computed GOTO jumps back one byte"