Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Table read for pic 18f2420

Status
Not open for further replies.

PicChristmas

New Member
Could someone please help me setup a table read using the 18F series pic. I'm using Pic Basic pro and asm. What i am trying to do is take a value 0 to 127 stored in register vTemp and call a lookup table in program memory and have the value pointed by vTemp returned in vTemp.
I have created the table in asm with the

org LevelTable
da 0x0607 .0x1011 ....

And have 64 two byte groups

I need some help withintializing the pointer and reading the data
 
Look at my code (not complete, too long to publish here):
Code:
fLCD	CLRF	LCDc	;LCD char counter
	CLRF	TBLPTRU	;Device does not have more 64KB of Flash!
	MOVFF	TAB_No,TBLPTRH;Determines Table to proces
	MOVFF	TAB_Pos,TBLPTRL;Determines position in Table
Fl	TBLRD*+
	INCF	LCDc,f	;Increment LCD counter
	MOVLW	H'11'   ;This is char, that is at the end of the string
	CPFSEQ	LCDc	
	GOTO	$+6	;String continues, send to LCD
	RETURN		;End of string
	MOVFF	TABLAT,LCD	;send to LCD
	CALL	LCDd	
	GOTO	Fl	;Send another char

Table	ORG	0x1100
	DW	" Line1              "
	DW	" Line2              "
	DW	" Line1              " 
	DW	" Line4              "
You have to put coordinats to TAB_No and TAB_Pos registers, and have LCDd rutine in your code.
 
PicChristmas said:
Could someone please help me setup a table read using the 18F series pic. I'm using Pic Basic pro and asm. What i am trying to do is take a value 0 to 127 stored in register vTemp and call a lookup table in program memory and have the value pointed by vTemp returned in vTemp.
I have created the table in asm with the

org LevelTable
da 0x0607 .0x1011 ....

And have 64 two byte groups

I need some help withintializing the pointer and reading the data

Here is a code snippet plucked from one of my programs..

Code:
         MOVF     vTemp,W
         ANDLW    B'01111111'
         ADDLW    LOW  LevelTable
         MOVWF    TBLPTRL
;
         MOVLW    HIGH LevelTable
         BTFSC    STATUS,CARRY
         ADDLW    1
         MOVWF    TBLPTRH
         CLRF     TBLPTRU
;
         TBLRD*
         MOVFF    TABLAT,vTemp
 
Thanks for the help. The vTemp value was already in range 0-127 so I didn't have to strip the 7th bit. With this code you just have to make sure the table starts with a low byte address of hex 00

Code:
   movlw	upper _lvlTable
	movwf	TBLPTRU
	movlw	high lvlTable 
	movwf	TBLPTRH
	movf	_vTemp,0               ;Points to value in table
	movwf	TBLPTRL
	TBLRD	*+ 				
	MOVFF       TABLAT, _vTemp
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top