0% found this document useful (0 votes)
78 views

D07 - Intro To AVR Assembly Language Equipment: Watch

This document provides instructions for writing and testing a simple AVR assembly language program using the ATmega328 microcontroller and AVR Studio 4 simulator. It describes setting up a new project, writing code to perform basic arithmetic and logic operations, and using the simulator to step through the program execution and observe register values and output. The code provided performs operations like addition, subtraction, AND, OR, and bit shifting on input values and displays the results on the STK500 board LEDs.

Uploaded by

P_lee
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

D07 - Intro To AVR Assembly Language Equipment: Watch

This document provides instructions for writing and testing a simple AVR assembly language program using the ATmega328 microcontroller and AVR Studio 4 simulator. It describes setting up a new project, writing code to perform basic arithmetic and logic operations, and using the simulator to step through the program execution and observe register values and output. The code provided performs operations like addition, subtraction, AND, OR, and bit shifting on input values and displays the results on the STK500 board LEDs.

Uploaded by

P_lee
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

D07 Intro to AVR Assembly Language

Equipment
PC with AVR Studio 4 installed
The AVR Assembly Language Instruction Set Summary document
STK5 board
Experiment
In this !rac you will write and test a small AVR assembly language !rogram "or
the ATmega#$ microcontroller% This will show how sim!le arithmetic and logic
o!erations are !er"ormed& and how a simulator can be used to "ollow the
e'ecution o" a !rogram%
Procedure
#% (!en AVR Studio 4
)% Create a new !ro*ect +Pro*ect , -ew Pro*ect.
/% Select 0Atmel AVR Assembler1 as the ty!e and enter a name "or the
!ro*ect% Clic2 -e't%
4% Select 0AVR Simulator1 as the !lat"orm and 0ATmega#$1 in the de3ice list%
Clic2 4inish%
5% 5nter the code gi3en below in the o!en AS6 7le%
$% 8ou can now assemble the !rogram and start the simulator to test its
e'ecution% +9uild , 9uild and Run.% 8ou will need to do this e3ery time
you ma2e a change to the !rogram to restart the simulator%
:% In the View menu& turn on the debug windows you will need; <atch&
6emory& Register and the =ebug toolbar%
>% ?sing the simulator you can ste! through the code one line at a time and
monitor the internal state o" the !rocessor% The yellow arrow shows the
ne't line to run%
atc! In this window you can add any 3ariables in the
!rogram to 3iew their current 3alues% Right clic2 "or
o!tions%
"emory This shows the contents o" the controller@s memory&
which is necessary to 3iew 3ariables stored in SRA6
Register This shows the status o" the /) internal CP? registers
Debug
#oolbar
This gi3es you control o3er the !rogram e'ecution%
Ste! In will enter a subroutine +a 0call1
statement.
Ste! (3er will e'ecute the subroutine and ste!
to the ne't line
A% Run the !ro3ided code in the simulator and understand how it wor2s%
#% As you ste! through the code& note the in!uts A and 9& other
internal registers& out!uts and the Condition Code register +SR5B.%
##% Incrementally add the other "unctionality and chec2 that the
o!erations wor2 as intended +3ia the simulator.% Add the "ollowing
"unctions into the s!aces !ro3ided and write down their results;
AC):
AD)5
AC9
AD9
A and 9
A or ####
A or 9
A lsr # !lace
A lsl # !lace
#)% Program your code onto the STK5 board and obser3e the L5=s
+uncomment the EDisplayTempOnLEDs calls.
#/% Answer the "ollowing Fuestions;
<hat is the diGerence between A!lus/4h and A!lus9H
<hat does Low+StartStac2. and Iigh+StartStac2. meanH
<hat does the Ests@ instruction doH
<hat is the signi7cance o" the condition codeJstatus register and
when is it changedH
<hat is the signi7cance o" the IJ( registers
<here is the result o" the Emul@ or Emuls@ instruction storedH
<hat instruction illuminates the L5=s on the STK5H
<hat is being dis!layed on the STK5 L5=sH
<hat logic le3els acti3ate the L5=s on the STK5 +acti3e high or
acti3e low.H Iow can the EDisplayTempOnLEDs call be changed to dis!lay
the o!!osite logic le3elH
;* D07 LABORATORY - Simple Arithmetic and L!ic Operatins
;**********************************************************
"de#ice AT$e!a%&
;$emry $ap
;***********
"e'( Start)lash * +0000 ;,ttm - )LAS. RO$ +0000
"e'( Start/ectrs * Start)lash
"e'( End/ectrs * +000A
"e'( Start1de * End/ectrs
"e'( )lashEnd * +%---
"e'( StartData * +00&0 ;start - (ser RA$
"e'( RA$End * +023)
"e'( StartStac4 * +023) ;tp end - RA$
; 5O Area
;--------
"e'( S6L * +007D ;addr 8here stac4pinter is stred
"e'( S6. * +007E
"e'( SRE9 * +007) ;1nditin 1de :ie"Stat(s; Re!ister
; 5O 6rts
;---------
"e'( 6in1 * +%7 ; inp(t 6rt1
"e'( DDR1 * +%2
"e'( 6rt1 * +%3 ; (tp(t 6rt1
"e'( 6inB * +%& ; inp(t 6rtB
"e'( DDRB * +%7
"e'( 6rtB * +%< ; (tp(t 6rtB
;Set =p Se!ments :i"e" 5nitialise Lcatin 1(nters in Se!ments
;****************
"dse! ;data se!ment
"r! StartData
"cse! ;cde se!ment
"r! Start)lash
; Set =p /ectrs
;---------------
"cse!
"r! Start/ectrs
r>mp Start
"r! End/ectrs
;*****************
;* *
;* $A5? 6RO9RA$ *
;* *
;*****************
;/AR5ABLES
;*********
;Re!ister Data :?te@ prcessr (ses r0Ar% 8ith sme instr(ctins;
;*************
"de- Temp * r%& ;many instr nly 8r4 8ith r%&-Br7%
"de- Temp. * r%7
"de- CL * r0&
"de- C. * r07
;5np(t Data
;---------
"de- A * r%< ; (nsi!ned <-,it n(m,er
"de- B * r%D ; (nsi!ned <-,it n(m,er
;Res(lts in Re!isters
;********************
;Arithmetic Res(lts
;------------------
"de- Apl(s72h * r0 ;<- ,it res(lt
"de- Amin(s07 * r7 ;<-,it si!ned :-#e 8hen A E07;
"de- Am(lt03 * r2 ;%&-,it res(lt
"de- A$(lt03. * r3
"de- Adi#3 * r&
;L!ic Res(lts
;-------------
"de- 1mplementedA * r7
"de- Aand0000%%%% * r<
"de- AandB * rD
"de- Ar00%%00%% * r%0
"de- ArB * r%%
"de- Alsr% * r%0 ;l!ical shi-t ri!ht A ne place
"de- Alsl% * r%7 ;l!ical shi-t le-t A ne place
"de- Alrrl& * r%2 ;rtate ri!ht A & places
;RA$ Data
;********
"dse! ;m#e int the data se!ment
;Other Arithmetic Res(lts
;------------------------
Apl(sB@ ",yte % ;ass(me % ,yte s(--icient
Amin(sB@ ",yte %
Am(ltB@ ",yte 0
"cse! ;m#e ,ac4 t the cde se!ment
;1ODE
;****
"r! Start1de
Start@
ldi TempFL8:StartStac4; ;set (p stac4 pinter
(t S6LFTemp
ldi TempF.i!h:StartStac4;
(t S6.FTemp
; 5nitialisatin
ldi TempF0,%%%%%%%% ;set (p 6rtB -r (tp(ts :0*5nF%*O(t;
(t DDRBFTemp
clr Temp ;set (p 6rt1 -r inp(t
(t DDR1FTemp
; 5nitialise /aria,les :these are t ,e chan!ed later;
;*********************
ldi AF +23 ;A * 23h
ldi BF 7& ;B * 7& * 02h
; 9et Res(lts
;************
call 1learRes(lts
call 9etAndDispArithmeticRes(lts
call 9etAndDispL!icRes(lts
8ait@ r>mp 8ait ;8ait here -re#er :endless lp;
;*******************************
;* S=BRO=T5?E@ 1lear Res(lts *
;*******************************
;pst All arithmetic and l!ic res(lts cleared
1learRes(lts@
;AG72heH
;-------
clr r0
clr r7
clr r2
clr r3
clr r&
clr r7
clr r<
clr rD
clr r%0
clr r%%
clr r%0
clr r%7
clr r%2
clr Temp
sts Apl(sBF Temp
sts Amin(sBF Temp
sts Am(ltBF Temp ; l8 ,yte
sts Am(ltBG%F Temp ; hi!h ,yte
ret
;**************************************************
;* S=BRO=T5?E@ 9et and Display Arithmetic Res(lts *
;**************************************************
;pst All arithmetic res(lts (pdated and displayed cnsec(ti#ely n LEDs
9etAndDispArithmeticRes(lts@
;AG72heH
;-------
m# TempFA ;Apl(s72h * A
s(,i TempF:-+72; ;e'(i# t addin! 72h
m# Apl(s72hFTemp
;call DisplayTempOnLEDs
;A-07
;----
;call DisplayTempOnLEDs
;A*03
;----
;AGB
;---
m# TempFA
add TempFB
sts Apl(sBFTemp ;stre in RA$
;call DisplayTempOnLEDs
;A-B
;---
;A*B :%&-,it res(lt@ display % ,yte at a time n LEDs;
;---
ret
;**********************************************
;* S=BRO=T5?E@ 9et and Display L!ic Res(lts *
;**********************************************
;pst All l!ic res(lts (pdated and displayed
9etAndDispL!icRes(lts@
;1mplemented A
;--------------
m# 1mplementedAFA
cm 1mplementedA
;A and 0000%%%%
;--------------
m# TempFA
andi TempF0,0000%%%%
m# Aand0000%%%%FTemp
;A and B
;-------
;A r 00%%00%%
;-------------
;A r B
;------
;A lsr % place
;-------------
;A lsl % place
;-------------
ret
;****************************
;* S=B@ DisplayTempOnLEDs *
;****************************
; Displays cntents - Temp n O(tp(t 6rtB LEDs -r at least % secnd
; r 8hile 610 p(sh ,(ttn is pressed
DisplayTempOnLEDs@
p(sh Temp
(t 6rtBFTemp ;LEDs are n 6rtB
call Delay%sec
DisTp%@
s,is 6in1F0 ;cntin(e t Display i- 610 pressed
>mp DisTp%
pp Temp
ret
;************************
;* S=B@ Delay%Sec *
;************************
Delay%Sec@
p(sh Temp
ldi TempF 030
call DelayTemp$illiSecs
call DelayTemp$illiSecs
call DelayTemp$illiSecs
call DelayTemp$illiSecs
pp Temp
ret
;****************************
;* S=B@ DelayTemp$illiSecs *
;****************************
; pre @ Temp * n(m,er - msecs t ,e delayed
; ass(min! a cycle time - %I< micrsecs :<$.J clc4;
; pst@ Temp * 0
DelayTemp$illiSecs@
p(sh Temp
p(sh CL
p(sh C.
tst Temp
Delay%@
,re' DelayE ;% cycleF terminate
ldi CLFLOK:<000I7-0; ;% cycleF ass(me <$.J clc4
ldi C.F.59.:<000I7-0; ;% cycle
Delay0@
s,i8 CLF % ;0 cyclesF inner lp
,rne Delay0 ;%
dec Temp ;%
r>mp Delay% ;%
DelayE@
pp C.
pp CL
pp Temp
ret

You might also like