Searching \ for '[AVR:]Look up Table' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/mems.htm?key=table
Search entire site for: 'Look up Table'.

Exact match. Not showing close matches.
PICList Thread
'[AVR:]Look up Table'
2004\06\11@033204 by Hopkins

flavicon
face
How do you program a lookup table in an AVR (ATMega 8) using assembler code?

Thanks in advance.

*************************************************
Roy Hopkins   :-)

Tauranga
New Zealand
*************************************************


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.703 / Virus Database: 459 - Release Date: 10/06/2004

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\11@035732 by David VanHorn

flavicon
face
At 07:32 PM 6/11/2004 +1200, Hopkins wrote:

>How do you program a lookup table in an AVR (ATMega 8) using assembler code?

Assuming two regs named TEMP, TEMP2, and a ram var called Table_Offset with the pointer to the position in the table:

Get_Table_Byte:
       ldi     TEMP,0                  ;For the 16 bit add to follow
       lds     TEMP2,Table_Offset      ;Get the offset
       ldi     ZL,low(Table*2)         ;Point at the table
       ldi     ZH,high(Table*2)        ;
       add     ZL,TEMP2                ;Add the offset as a 16 bit op
       adc     ZH,TEMP                 ;so the table can be anywhere.
       lpm     ;Defaults to R0, some AVRs can put it in other registers.

       ret     ;Byte (Table offset) of TABLE is now in R0

For reading multiple bytes, continue with

adiw    ZL,1
lpm

and so on.

Data is stored in WORDS in the AVR rom, but recalled in BYTES.
Also, the assembler will append an extra null to the end of a .db that is an odd number of bytes long.

TABLE: .db 0x45,0x46,0x47

Ends up in rom as 45,46,47,00 << Extra null added by assembler.

A table that ends in a null, like:

TABLE: .db 0x45,0x46,0x43,0x47,0x00

ends up looking like this: 45,46,43,47,00,00

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\11@042505 by Hopkins

flavicon
face
Thanks for the fast response - will test it out.

----- Original Message -----
From: "David VanHorn" <spam_OUTdvanhornTakeThisOuTspamCEDAR.NET>
To: <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU>
Sent: Friday, June 11, 2004 7:58 PM
Subject: Re: [AVR:]Look up Table


> At 07:32 PM 6/11/2004 +1200, Hopkins wrote:
>
> >How do you program a lookup table in an AVR (ATMega 8) using assembler
code?
>
> Assuming two regs named TEMP, TEMP2, and a ram var called Table_Offset
with the pointer to the position in the table:
{Quote hidden}

an odd number of bytes long.
{Quote hidden}

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.703 / Virus Database: 459 - Release Date: 10/06/2004

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\11@044206 by Hopkins

flavicon
face
Thanks again David

Forgot to mention that I want to be able to store the table in EEPROM as it
will be part of a LCD menu that can be altered by the user.

How do I set the table up to work in EEPROM?

PS as u can tell I am a new to the AVR but have managed to make a couple of
programs work including one that have entered into the circuit cellar
competition. :-)
*************************************************
Roy Hopkins   :-)

Tauranga
New Zealand
*************************************************
> Thanks for the fast response - will test it out.
>
> {Original Message removed}

2004\06\11@103206 by David VanHorn

flavicon
face
At 08:40 PM 6/11/2004 +1200, Hopkins wrote:

>Thanks again David
>
>Forgot to mention that I want to be able to store the table in EEPROM as it
>will be part of a LCD menu that can be altered by the user.
>
>How do I set the table up to work in EEPROM?

Similar approach, except that you'll need to set up the EE address pointer, then do a read, wait till that's done, then pick up the data.

When I'm not actively using the EE, I leave the address pointer looking at location 0000, which I don't use for data.  That way, an accidental write won't overwrite any data that I've stored.

Bear in mind, it's up to you, to assure that you have enough power to execute a write, and that reset, or loss of VCC won't happen before the write completes.  People frequently overlook that point.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\11@170745 by Hopkins

flavicon
face
Thanks again David -

just one point I do not understand and that is how do you know the
Table_Offset value or how do you know just were the table is located in
memory?

*************************************************
Roy Hopkins   :-)

Tauranga
New Zealand
*************************************************
> >How do you program a lookup table in an AVR (ATMega 8) using assembler
code?
>
> Assuming two regs named TEMP, TEMP2, and a ram var called Table_Offset
with the pointer to the position in the table:
{Quote hidden}

an odd number of bytes long.
{Quote hidden}

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.703 / Virus Database: 459 - Release Date: 10/06/2004

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\11@172650 by Randy Ott

flavicon
face
Roy,

Take a look at a program I wrote as a learning exercise that does something
simular to what you are trying to do.  It is a simulation of the old "magic
8 ball" that reads message strings from flash and displays them on an LCD.
The best example is one that outputs to the UART and is named 8BALLSIO.ASM
and is located at http://www.qsl.net/k5hj/avr along with a bunch of other small
programs I did in order to learn about the AVR.  Most are written for the
2313 but should apply to the MEGA parts as well.

Randy Ott

On Sat, 12 Jun 2004 09:07:25 +1200, Hopkins wrote
{Quote hidden}

--
WebMail Provided by sbnweb.com (http://www.sbnweb.com)


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\11@173106 by Shawn Wilton

flavicon
face
For some good docs written by a friend of mine, check out the avr
material on this page:
http://eecs.oregonstate.edu/education/classes/ece375/index.html

It should get you up and running quickly.

-Shawn



Randy Ott wrote:

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...