PHXSYS wrote: > > Hi everyone > > In my program I am using the program counter to sequence several routines. I > am using it like this: > > MOVF SSTATE,W > MOVWF PCL > > SSTATE is the address of the specific routine. My problem is SSTATE is an 8 > bit value and my routine length goes over 255 addresses. When it goes over 255 > it goes to the beginning of the program. I use the PAGE command before and > after routines, but it must be larger than a page. Yes, as I wrote in an answer to previous question you posted, if you want to use this technique and your code extends over 256 memory locations you have to play with PCLATH. > I have to keep the code efficient because of the serial timing, I don't have > much room for additional code. > > What are my options? > > Is there an efficient way to make SSTATE a 16bit number and will that even > work? For example if SSTATE was at 355 would the program counter no where to > go? You can use two register for the SState value (i.e. SStateL and SStateH) to hold a 16 bit number. So, using the code fragment you posted in "MOVLW where the literal is a label", the sequence: > movlw Ckstrt ; then make sure start bit persists**** LOOK H ERE > movwf SState > goto w10 > ; > Ckstrt decfsz STime,F ; verify start bit by sampling at center **** LOOK HE RE becomes: movlw high Ckstrt ; Get the high addr of the 'Ckstrt' routine movwf SStateH ; Store in high register movlw low Ckstrt ; Get the low address byte movwf SStateL ; Store in low register goto w10 ; Ckstrt decfsz STime,F ; verify start bit by sampling at center **** LOOK HERE Then, when your state machine has to call the appropriate routine use: movf SStateH, W ;Load the high byte of address movwf PCLATH ;Set the PCLATH register movf SStateL, W ;Load the low byte of the routine address movwf PCL ;Jump to the routine at SStateH:SStateL > Can I use a lookup table to provide any additional options? For example > offset the counter to GOTO's. I don't think I can do that. > > Is there a way to utilize a lookdown table? Yes, you can also build a jump table and use an index rather than the routine address for SState in a form like this: movlw 0 ; 0 stands for 'Ckstrt' (you can also use #define's movwf SState ; to make your code more readable) goto w10 Then to dispatch to the proper routine: movlw high table ; Make sure PCLATH points to the current code page movwf PCLATH movf SState,W ; Get the index in the table addwf PCL, F ; Jump to the proper entry table goto SState ; Index 0 goto Getbit ; Index 1 goto ... ; Index ... Ciao Marco ---- Marco DI LEO email: m.dileo@sistinf.it Sistemi Informativi S.p.A. tel: +39 6 50292 300 V. Elio Vittorini, 129 fax: +39 6 5015991 I-00144 Roma web: http://members.tripod.com/~mdileo/ Italy