Help with LPM and ATmega8

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone. I'm new to AVR after working with ARM mostly.

I started doing my first AVR project in assembly because it's the best way to learn CPU architecture.

I have a problem with pointers.

Can you PLEASE explain what is wrong with this approach?

example:

***************************
.org 0x0000
rjmp reset
.db "Some text here"

reset:
ldi ZH, 0x00
ldi ZL, 0x02 ;*(0x02)= first character
lpm r16, Z+
....
....
***************************

I get this:
D:\My Documents\Mikrokontroleri\AVR\Projekti\ATmega8\LCD\LCD.asm(161): error: lpm r16, z+: Unsupported instruction on AT90S8515

But why? Datasheet says that instruction is supported by ATmega8. I work in AVR Studio 4

Please help? Is there any way around? What is the best way to store strings, maybe in SRAM. How? (assembler)

Thanks !

Last Edited: Tue. Feb 20, 2007 - 10:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The compiler thinks it needs to use 8515 instructions while you use mega8 instructions. Have you forgotten to say to the compiler you use mega8?

I don't see any

.include "mega8.def"

or anything there.

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You might take a trip to www.avrbeginners.net and see if any of the worked examples apply.

[You can do quite a bit with just that site, a datasheet, and AVRStudio's simulator (free).]

Oh, yeah, and a lot of posted projects on this site. And a wealth of info in the archives, but the search is broken. :(

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello.

Huh...?
I was using this

.include "8515def.inc"

It contains all register addresses right? (like PORTD, SP etc.)

When I started doing my project I chose ATmega8 and in the bottom of AVR Studio it says ATmega8.

Something wrong with this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I was using this

.include "8515def.inc"


Which is for the 8515, not the mega8. Use this instead:

.include "m8def.inc"

When you start an assembly project, you are setting what AVR the simulator will use, not what AVR the program will compile for, that is set with the include file.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Koshchi and the rest.

It work now !

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
.db "Some text here" 

reset: 
ldi ZH, 0x00 
ldi ZL, 0x02 ;*(0x02)= first character 
lpm r16, Z+ 
.... 

A few pointers. Get into the habit of putting any code and data PAST ALL interrupt vectors (0x13 for the M8 ).
Use LABELS instead of hard addresses for data or anything else.
Data is stored in 16 bit spaces in flash, so you will need to multiply the address of the data by 2. Your code could look like this:

org 0x0000 
rjmp reset
 
org 0x0013 ;put everything out of the way of the vectors

text:   ;Use a label to reference your data
.db "Some text here" 

reset: 
ldi ZH,high(text*2)
ldi ZL,low(text*2) ;multiply the address of the data by 2
lpm r16, Z+ 

for older chips like the 90s8515 you can just use lpm whithout reference to registers as it deafults to using r0 as the destination and Z as the pointer, this will work for newer chips also.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just to beef up js's comment: Moving data and code past the interrupt vectors is a good way to remind yourself to keep that space free just in case you ever need to add an interrupt service routine to the application in the future. It also offers you the opportunity to insert a catch-all default interrupt handler just in case an unexpected interrupt starts firing.

But if you don't care about those conditions -- say, you never intend to enable any interrupts at all -- then it's perfectly "legal" to put data, or any arbitrary executable code in the interrupt vector space.

That being said, I would tend to avoid it unless I'm extremely pressed for space and I cannot think of any other possible area for optimization.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you both.
The thing is, that code I wrote was just an example what I wanted to do.
I will do everything with labels from now on.

About interrupt vectors. I always put my code on the lowest address posible. If there in only reset at 0x0000, my code start there.

In project where I use lots of interrupts the idea off putting code after all interrups vectors stands but it is not necessarily.