PHXSYS wrote: > > Hi > > I am fairly new to programming PICs and I have some code I am trying to > understand. It uses a MOVLW where the literal is a label for a routine. Can > you help me understand? > > movlw Ckstrt ; then make sure start bit persists > > Is this a method of addressing? Is the code run for that label and the final > value stored in W? No. The instruction above just moves the LSB of 'Ckstrt' in the W register. If Ckstrt is a label the instruction simply loads the W register with the low byte of the address that the label refers. > I've never used this before. Hre's an example of a serial routine. > > Idle btfss SERIN ; skip if serial input is space > goto idl15 > movlw BITTIME/2 ; delay 1/2 bit time > movwf STime > 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 > goto w15 > btfss SERIN ; skip if start bit was valid > goto idl13 > movlw BITTIME ; delay 1 bit time > movwf STime > movlw Getbit ; then receive data > movwf SState > movlw 8 > movwf SCount ; for 8 bits > goto w6 I would have look at the rest of the code but it seems to me that this implements a (sort of) state machine in which the 'SState' holds the address of the routine to be called when the next event occurs. I don't know what the 'w10' and 'w6' routines do, but I suppose that they do a jump based on the value in SState like in: movf SState, W ;Load next routine address movwf PCL ;Set program counter to the routine Please note that since PCL (as W) is an 8 bit register the code must be located in the same 256 word segment. If this is not the segment starting from address 0 you need to set the PCLATH register accordingly. Hope this helps Ciao Marco