ASM table lookups

Status
Not open for further replies.

ChriX

Member
Good evening all. I wonder if anyone can see anything immediately wrong with my code excerpt below. I have spent a LONG time debugging this and I cannot get it to work as intended.

I put together a quick 64x16 LED matrix panel using shift registers, and am trying to drive it using a 16F870. I am driving it such that the rows are cycled top to bottom, and for each new row, the 64 bits are shifted in from right to left.

I have had no problem in putting together code to shift it, but the problem comes when I want to try and read a bitmap from a table.

Code:
	org 0x200
SCREENLOOKUP
	movlw	high(SCREENDATA)
	movwf	PCLATH
	movlw	low(SCREENDATA)
	addwf	OFFSET,W
	btfsc	STATUS,C
	incf	PCLATH,F
	movwf	PCL

SCREENDATA
	dt b'11111111', .... (128 bytes organised as 16 lines each with 8 bytes)

SCREENLOOKUP is called with a value from 0 to 127 held in OFFSET. I have tested this by returning the value of OFFSET directly after SCREENLOOKUP is called, and I correctly get the binary values for 0 to 127 displayed via my LED matrix (see photo - it counts from L-R, T-B). This confirms that the offset value is normal, and that my SR routines are working correctly.

When I try to return the data from the table the chip seems to crash, and when using ICD will occasionally break at 0x00 when it hasn't been asked to, so I guess it's jumping somewhere it shouldn't. The OFFSET is generated as below, the code shows what is executed per row of the display.

Code:
	movf CURRENT_ROWG,w
	clrf CURRENT_ROWT
	movwf CURRENT_ROWT
	bcf STATUS,C
	rlf CURRENT_ROWT,1
	rlf CURRENT_ROWT,1
	rlf CURRENT_ROWT,1

; shift the 64 cols of data
	movlw b'00000000'
	iorwf CURRENT_ROWT,W
	movwf OFFSET
	call SCREENLOOKUP
	call SHIFTCOLS

	movlw b'00000001'
	iorwf CURRENT_ROWT,W
	movwf OFFSET
	call SCREENLOOKUP
	call SHIFTCOLS

	movlw b'00000010'
	iorwf CURRENT_ROWT,W
	movwf OFFSET
	call SCREENLOOKUP
	call SHIFTCOLS

	movlw b'00000011'
	iorwf CURRENT_ROWT,W
	movwf OFFSET
	call SCREENLOOKUP
	call SHIFTCOLS

	movlw b'00000100'
	iorwf CURRENT_ROWT,W
	movwf OFFSET
	call SCREENLOOKUP
	call SHIFTCOLS

	movlw b'00000101'
	iorwf CURRENT_ROWT,W
	movwf OFFSET
	call SCREENLOOKUP
	call SHIFTCOLS

	movlw b'00000110'
	iorwf CURRENT_ROWT,W
	call SCREENLOOKUP
	call SHIFTCOLS

	movlw b'00000111'
	iorwf CURRENT_ROWT,W
	movwf OFFSET
	call SCREENLOOKUP
	call SHIFTCOLS

	bcf PIN_COL_TR
	nop
	bsf PIN_COL_TR
	bcf PIN_ROW_EN

	decf CURRENT_ROWG,f

	bcf STATUS,C
	rlf CURRENT_ROWL,f
	btfsc STATUS,C
	goto MOVEUPL

	bcf STATUS,C
	rlf CURRENT_ROWH,f
	btfsc STATUS,C
	goto MOVEDOWNL

	goto ENDLOOP

MOVEUPL
	movlw 1
	movwf CURRENT_ROWH
	movlw 0
	movwf CURRENT_ROWL
	goto ENDLOOP

MOVEDOWNL
	movlw 1
	movwf CURRENT_ROWL
	movlw 0
	movwf CURRENT_ROWH

	; start from zero again on G
	movlw b'00001111'
	movwf CURRENT_ROWG

ENDLOOP
	DELAY_MICRO 250

	goto LOOP_BEGIN

Any help appreciated as I have now pretty much destroyed my code trying to work out what is wrong!
 

Attachments

  • ledmatrix.jpg
    126.4 KB · Views: 188
Thanks for the reply. I hadn't, but I have just added a clrf PCLATH after each call to SCREENLOOKUP with no difference in the result - same strange behaviour etc.
 
Infact, playing with ICD now, it seems to reliably break at 0x00 every time I run it. It will however get through a few loops as you see the bitmap flash up on the screen occasionally.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…