pic12f2580 jump table

Status
Not open for further replies.

RASH

New Member
I'm new to the 18F2580, I'm having a problem in updating the PC (PCLAT) on time while performing the instruction ADDWF PCL,F.

How can I predict the correct PCL value and add my variable to hit the desires GOTO or BRA instruction.

Thank you all for the help
 
This is what I use on the 18F series.
There needs to be a register called "index", and this code will cause a jump to option_[index]

If index is too big for the lookup table, the code will jump to fail_code.

This can be used for any number of options up to 255

Code:
	movlw	high (lookup_start)
	movwf	pclath
	movlw	(lookup_end - lookup_start)/2
	subwf	index, w
	bc	fail_code
	rlncf	index, w
	addlw	low (lookup_start)
	btfsc	status, carry
	incf	pclath, f
	movwf	pcl
lookup_start
	bra	option_0
	bra	option_1
	bra	option_2
	bra	option_3
	bra	option_4
	bra	option_5
.
.
.
.
	bra	option_last
lookup_end


fail_code
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…