Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Mplab and pic16 lookup table entries.

Status
Not open for further replies.

dr pepper

Advanced Member level 1
Advanced Member level 1
Joined
Mar 15, 2010
Messages
428
Helped
35
Reputation
70
Reaction score
41
Trophy points
1,308
Location
lancs
Visit site
Activity points
4,171
I currently use retlw 'xxx' for every line on a lookup table, I'd like to use something like this:

retlw

xx ; first entry

xx ; second entry

xx ; third entry

etc

ie not have to put retlw on every line, I'm sure theres an assembler directive for this, how do I do it?
 

Try like this example (incomplete!!!):

Code:
;************************************************************************************
	CBLOCK	0x20
		TEMP
	ENDC
;************************************************************************************
LOOP
	CALL	TESTE
	GOTO	LOOP
;************************************************************************************
TESTE
	MOVF	TEMP,W
	ADDWF	PCL,F
	RETLW	B'00000000'	;0
	RETLW	B'00000001'	;1
	RETLW	B'00000010'	;2
	RETLW	B'00000100'	;3
	RETLW	B'00001000'	;4
	RETLW	B'00010000'	;5
	RETLW	B'00100000'	;6
	RETLW	B'01000000'	;7
	RETLW	B'10000000'	;8
;************************************************************************************
	END
;************************************************************************************
 

Heres how I see it,

dt "hello",0

could be used to display a message, '0' terminating the string

or

dt 0x1,0x2,0x3,0x4,0x5

for a simple 5 byte lookup table.

The ability to store a message say for an lcd is much more tidyer and quicker than having to enter each ascii character on its own line with its own retlw and quotation marks.

How come mplab makes you ugh.
 

The 'ugh' was to Nagkiller's code, not MPLAB which I think is a great program.

The example using the DT directive is quite correct and it actually codes each byte in the table as a 'retlw' instruction but without all the typing!

Warning: be careful if the table crosses a page boundary because the jump into it (adding W to PCL) will not update the PCLATH register. If it goes beyond an address ending in 0xFF it will pick up the instruction at address 0x00 in the same page, not the next one. There are fixes for this, a good discussion on it can be found on the Microchip Forum. Only the PIC 10F, 12F and 16F need to use this method of using look-up tables, the other families have dedicated instructions for table access.

Brian.
 
Thanks,

I have writtena piece of code to setup the value within a ad9850 dds chip last night using the dt directive, and yes it saves time and looks neater.

Yes I'm well aware of the fact that adding to the program counter only affects the lower 8 bits and page boundarys come into effect, I think I have my own way of dealing with this, I assemble the code , then see what page the table is in by looking at the .lst file, then go back to the code and load pclath with the correct page no just before adding to the program counter.
 

An excerpt from my code.

bylkp0a movlw d'1'
movwf pclath
;
movf bycn,w
addwf pcl,f
dt 0x14,0x7a,0xe1,0x48 ;10mc
;
bylkp1a movlw d'1'
movwf pclath
;
movf bycn,w
addwf pcl,f
dt 0x02,0x0c,0x49,0xba ;1mc
;
bylkp2a movlw d'1'
movwf pclath
;
movf bycn,w
addwf pcl,f
dt 0x00,0x34,0x6d,0xc6 ;100kc
;
bylkp3a movlw d'1'
movwf pclath
;
movf bycn,w
addwf pcl,f
dt 0x00,0x05,0x3e,0x2d ;10kc
 

I'm not sure what the code actually does (a frequency synth?) but as each entry has 4 values you *might* be able to adapt the code by multiplying the W value by 4 (shift left twice) to find the entry into the table then extract the following four entries into individual variables. The whole table can then be a single DT statement or if you prefer several lines of DT. It uses at least three extra ram locations but cuts the number of instructions needed.

Incidentally, if you post code on the forum, please do it inside code tags (the # in the menu bar at the top of the window). It tells the forum software not to reformat it so we can see it as you wrote it.

Brian.
 

The code fetches a value to add or subtract to the synth's freq register, the register is 32 bit hence 4 bytes.
I need to call each one independantly, however yes I see what you say I could have just one table, I do have a load of space in the chip thoug so it'll be fine, but I'll remember that.

Yes got that about posting the code.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top