AVR LPM 1233.pdf
(
41 KB
)
Pobierz
AVR108: Setup and Use of the LPM instruction
Features
•
Use of the LPM (Load Program Memory)
Instruction with the AVR
®
Assembler
•
Load Constants from Program Memory
•
Use of Lookup-tables
Use of the LPM
The LPM instruction is included in the
AVR instruction set to load a data byte
from the FLASH program memory into
the register file.
The flash program memory of the AVR
microcontroller is organized as 16 bits
words. The register file and SRAM data
memory are organized as 8 bits bytes.
Special consideration must therefore be
taken when loading data from program
memory to data meory.
The Z-register in the register file is used
to access the program memory. This 16
bits register pair is used as a 16 bits
pointer to the program memory. The 15
most significant bits selects the word
address in program memory. Because of
this, the word address is multiplied by 2
before it is put in the Z register.
8-bit
Microcontroller
Application
Note
Introduction
This application note describes how to
access constants saved in Flash pro-
gram
memory
of
the
AVR
microcontrollers. The AVR is based on a
Harward architecture, this means that
Address and Data memory use separate
busses. This is necessary to achieve sin-
gle cycle instructions execution speed.
To be able to save constants in Flash
memory the Load Program Memory,
(LPM) instruction is included in the
instruction set.
Figure 1.
Z Address Register
15
8
7
1 0
low/high
byte select
Program word adress
The least significant bit of the Z address
register selects either low byte (0) or
high byte(1) of the program memory
word. To calculate the low (ZL) an high
(ZH) part of the address, use the LOW()
and HIGH() functions.
To load data from random places in pro-
gram memory, the Z register must be set
up with the proper address each time a
new address is accessed.
In program memory the data is orga-
nized with one byte in the low part of a
program word and the next byte in the
high part. Because of this, the message
string will appear as if every pair of char-
acters has been swapped, when viewed
in the memory view in AVR Studio.
The program in this application note
loads a string of bytes from the program
memory, and writes it to Port B. It first
initializes Port B so that all the pins are
output. It loads the starting address of
the string “Hello World” into Z register,
as described above. Then a byte is
loaded from program memory using
LPM. The program checks whether or
not the end of the string is reached (byte
was zero). If the end is not reached yet
the last read byte is put on Port B, a
short delay is made, and the Z register is
increased. The program then jumps
back to load another byte.
Rev. 1233A–08/99
1
;**** A P P L I C A T I O N
;*
;* Title:
;* Version:
;* Target:
;*
N O T E
A V R 1 0 8 ************************
Load Program Memory
1.0
AT90Sxx1x and higher (Devices with SRAM)
;* Last updated: 98.12.17
;* Support E-mail: avr@atmel.com
;*
;* DESCRIPTION
;* This Application note shows how to use the Load Program Memory (LPM)
;* instruction. The App. note loads the string “Hello World” from
;* program memory byte by byte, and puts it onto port B.
;*
;***************************************************************************
.include “8515def.inc”
.device
.def
AT90S8515
temp=r16
; Specify device
; Define temporary variable
start:
ldi
out
ldi
out
ldi
out
out
temp,low(RAMEND)
SPL,temp
temp,high(RAMEND)
SPH,temp
temp,$ff
PORTB,temp
DDRB,temp
; Set all pins at port B high
; Set port B as output
; Set stack pointer to last internal RAM location
; Load the address of ‘message’ into the Z register. Multiplies
; word address with 2 to achieve the byte address, and uses the
; functions high() and low() to calculate high and low address byte.
ldi
ldi
loadbyte:
lpm
tst
breq
out
rcall
adiw
rjmp
r0
quit
PORTB,r0
one_sec_delay
ZL,1
loadbyte
; Load byte from program memory into r0
; Check if we’ve reached the end of the message
; If so, quit
; Put the character onto Port B
; A short delay
; Increase Z registers
ZH,high(2*message)
ZL,low(2*message)
; Load high part of byte address into ZH
; Load low part of byte address into ZL
2
AVR108
AVR108
quit:
rjmp quit
one_sec_delay:
ldi
ldi
ldi
delay:
dec
brne
dec
brne
dec
brne
ret
message:
.db “Hello World”
.db 0
r22
delay
r21
delay
r20
delay
r20, 20
r21, 255
r22, 255
3
Atmel Headquarters
Corporate Headquarters
2325 Orchard Parkway
San Jose, CA 95131
TEL (408) 441-0311
FAX (408) 487-2600
Atmel Operations
Atmel Colorado Springs
1150 E. Cheyenne Mtn. Blvd.
Colorado Springs, CO 80906
TEL (719) 576-3300
FAX (719) 540-1759
Europe
Atmel U.K., Ltd.
Coliseum Business Centre
Riverside Way
Camberley, Surrey GU15 3YL
England
TEL (44) 1276-686-677
FAX (44) 1276-686-697
Atmel Rousset
Zone Industrielle
13106 Rousset Cedex
France
TEL (33) 4-4253-6000
FAX (33) 4-4253-6001
Asia
Atmel Asia, Ltd.
Room 1219
Chinachem Golden Plaza
77 Mody Road Tsimhatsui
East Kowloon
Hong Kong
TEL (852) 2721-9778
FAX (852) 2722-1369
Japan
Atmel Japan K.K.
9F, Tonetsu Shinkawa Bldg.
1-24-8 Shinkawa
Chuo-ku, Tokyo 104-0033
Japan
TEL (81) 3-3523-3551
FAX (81) 3-3523-7581
Fax-on-Demand
North America:
1-(800) 292-8635
International:
1-(408) 441-0732
e-mail
literature@atmel.com
Web Site
http://www.atmel.com
BBS
1-(408) 436-4309
© Atmel Corporation 1999.
Atmel Corporation makes no warranty for the use of its products, other than those expressly contained in the Company’s standard war-
ranty which is detailed in Atmel’s Terms and Conditions located on the Company’s web site. The Company assumes no responsibility for
any errors which may appear in this document, reserves the right to change devices or specifications detailed herein at any time without
notice, and does not make any commitment to update the information contained herein. No licenses to patents or other intellectual prop-
erty of Atmel are granted by the Company in connection with the sale of Atmel products, expressly or by implication. Atmel’s products are
not authorized for use as critical components in life support devices or systems.
Marks bearing
®
and/or
™
are registered trademarks and trademarks of Atmel Corporation.
Printed on recycled paper.
1233A–08/99/xM
Terms and product names in this document may be trademarks of others.
Plik z chomika:
fred1144
Inne pliki z tego folderu:
tiny11_12s_OLD.pdf
(267 KB)
Осваиваем AVR микроконтроллеры - с чего начать.url
(0 KB)
ARM7_Atmel.zip
(23369 KB)
1129173459.rar
(6869 KB)
1.rar
(4548 KB)
Inne foldery tego chomika:
- Разные
! Осциллограф РАДИОПРОГИ РАСЧЁТЫ СПРАВОЧНИКИ
!avr test
!Измерения и константы
# PIC
Zgłoś jeśli
naruszono regulamin