Below is some working code. Note that the branch instruction is two
bytes long, but the goto is four, thus some of the problem. Also, you
need to use the rlncf so you don't accidentally end up on an odd address
(though that might be thrown out when it gets loaded into the pc).
Harold
movlw high(RXJA)
movwf pclath ; Update pc latch for table calls
rlncf RxState,0 ; Get receive state*2 in W since bra instructions are 2
bytes long
andlw 0x07 ; Get rid of invalid states
addlw low(RXJA) ; w now holds low half of address we want to jump to
skpnc
incf pclath,1 ; Add carry into pclath if needed
movwf pcl ; Jump into table
RXJA
bra RxState0 ; Go handle wait for FE (state 0)
bra RxState1 ; Go handle wait for start code (state 1)
bra RxState2 ; Go handle receive data (state 2)
return ; should never be executed (invalid state 3)
On Tue, 13 Aug 2002 11:21:49 -0300 "Edson Brusque (Listas)"
<brusque.listas
KILLspamCITRONICS.COM.BR> writes:
{Quote hidden}> Hello,
>
> I'm porting a software that is running ok on a PIC16F877 to a
> PIC18F452
> and now I'm having problems with the computed goto's.
>
> On the PIC16:
>
> MOVLW 0x01
> MOVWF PCLATH
> MOVF state,W_
> ADDWF PCL,F_
> GOTO case0
> GOTO case1
> GOTO case2
> etc
>
> On the PIC18 strange things happen:
> MOVLW 0x01
> MOVWF PCLATH
> RLCF dkstate, W_
> ADDWF PCL
> GOTO case0
> GOTO case1
> GOTO case2
> etc
>
> Someone have an example code about computed goto's on a PIC18?
>
> I've seen the "Unlimited computed goto (or table lookup)" page
> by Bob
> Ammerman on PICLIST, but it seens overkill. I need very fast code.
>
> Thank you very much,
>
> Brusque
>
> -----------------------------------------------------------------
> Edson Brusque C.I.Tronics Lighting Designers Ltda
> Research and Development Blumenau - SC - Brazil
> Say NO to HTML mail
http://www.citronics.com.br
> -----------------------------------------------------------------
>
> --
>
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
> email
.....listservKILLspam
.....mitvma.mit.edu with SET PICList DIGEST in the body
>
>
FCC Rules Online at http://hallikainen.com/FccRules
Lighting control for theatre and television at http://www.dovesystems.com
Reach broadcasters, engineers, manufacturers, compliance labs, and
attorneys.
Advertise at http://www.hallikainen.com/FccRules/ .
________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today! For your FREE software, visit:
dl.http://www.juno.com/get/web/.
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUT
TakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body