# Matrix lookup table

Status
Not open for further replies.

#### Mosaic

##### Well-Known Member
Hi:
I need an approach to look up data in a x-y matrix based upon x,y coords.

The data on the x-axis is stored as sequential nybbles in sequential bytes....about 6 bytes = 12 nybbles of x -data
The y axis are just bytes.

Asm pls if u have any sample code....16F886 is my chosen mcu.

Thanks!

Last edited:

#### Pommie

##### Well-Known Member
If you x data is only a nibble then use it as an index into a 16 byte table.
Code:
	addwf	PCL,f
dt	5,10,12,16,18,2,28,32
dt	40,50,62,74,86,100,120,160
Or, are you saying it is a 12 by (num y values) matrix. If so how many y values? Also, is memory a problem?

Mike.

#### Mosaic

##### Well-Known Member
We're looking at 12 by 12 matrices. memory is a problem. I need at least need 4 of them.

So i compressed the x range into nybbles to halve the eeprom requirement.
The tables are eprom based, and are mapped to GPR individually as required.User editable so no computed gotos in code space.
Gotta do it with FSR/INDF in GPR space with writes back to eeprom after editing.

The way i look at it is i need to figure a way to address the x,y coords and display/update the individual memory locations.

#### Mike - K8LH

##### Well-Known Member
We're looking at 12 by 12 matrices. memory is a problem. I need at least need 4 of them.

So i compressed the x range into nybbles to halve the eeprom requirement.
The tables are eprom based, and are mapped to GPR individually as required.User editable so no computed gotos in code space.
Gotta do it with FSR/INDF in GPR space with writes back to eeprom after editing.

The way i look at it is i need to figure a way to address the x,y coords and display/update the individual memory locations.
ArrayIndex = (Y * 6) + (X / 2)

where X = 0..11, Y = 0..11, and ArrayIndex = 0..71 (the "byte" index into the array)

the result of X & 1 (bit test X,0) determines which nybble to use.

the formula assumes you're storing arrays in EEPROM in Array[Y][X] format;

Code:
        de      0x21,0x22,0x44,0x33,0x21,0x30    ; Y = 0, X = 0..11 (nybbles)
de      0x31,0x33,0x31,0x22,0x24,0x22    ; Y = 1, X = 0..11 (nybbles)
......
de      0x44,0x31,0x33,0x31,0x41,0x12    ; Y = 11, X = 0..11 (nybbles)
Example Index routine;

Code:
;
;  get EEPROM array 'byte' index, 0..71
;
clrc                    ;
rlf     y,W             ; wreg = Y * 2
movwf   index           ; index = Y * 2
addwf   index,F         ; index = Y * 4 (C=0)
addwf   index,F         ; index = Y * 6 (C=0)
rrf     x,W             ; wreg = (X / 2)
addwf   index,F         ; index = (Y * 6) + (X / 2)

Last edited:

#### Mosaic

##### Well-Known Member
yes, that's it...

#### Mike - K8LH

##### Well-Known Member
yes, that's it...

Have fun... Regards, Mike, K8LH

3v0

#### Mosaic

##### Well-Known Member
Great stuff there Mike....!!!

Status
Not open for further replies.