0% found this document useful (0 votes)
30 views6 pages

Arduino Atmega Manual Book

This document provides instructions for using an Arduino and assembly language to control a seven segment display. It includes a list of required components, instructions for connecting the display and Arduino hardware, and steps for writing and running assembly code to turn on an LED or control the display digits. The assembly code examples control individual pins on the Arduino to light segments on the display.

Uploaded by

Muhammad Rifai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views6 pages

Arduino Atmega Manual Book

This document provides instructions for using an Arduino and assembly language to control a seven segment display. It includes a list of required components, instructions for connecting the display and Arduino hardware, and steps for writing and running assembly code to turn on an LED or control the display digits. The assembly code examples control individual pins on the Arduino to light segments on the display.

Uploaded by

Muhammad Rifai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1

Assembly Programming through Arduino


G V V Sharma∗

Contents Component Value Quantity


Breadboard 1
1 Components 1 Resistor ≥ 220Ω 1
2 Seven Segment Display 1 Arduino Uno 1
2.1 Hardware Setup . . . . . . . 1 Seven Segment Common 1
2.2 Software Setup . . . . . . . . 2 Display Anode
2.3 Controlling the Display . . . 2 Decoder 7447 1
Flip Flop 7474 2
3 Display Decoder 3
Jumper Wires 20
3.1 Driving the Segments . . . . 3
TABLE 1.0.1
4 Boolean Operations 4

5 Combinational Logic 5

6 Decade Counter through Arduino 5

Abstract—This manual is a beginner’s guide to assembly


programming using the arduino. The instruction set of the
ATMEGA328P IC, which is the arduino microcontroller,
is used for building a decade counter by programming in
assembly language. This manual can also be used for a
Fig. 2.1
first course on microprocessor architecture.

The seven segment display in Fig. 2.2 has eight


1 Components pins, a, b, c, d, e, f, g and dot that take an active
The components required for this manual are LOW input, i.e. the LED will glow only if the
listed in Table 1.0.1. input is connected to ground. Each of these pins
is connected to an LED segment. The dot pin is
2 Seven Segment Display reserved for the · LED.
2.1 Hardware Setup Problem 2.2. Connect one end of the resistor to
The breadboard can be divided into 5 segments. the COM pin of the display and the other end to an
In each of the green segements, the pins are in- extreme pin of the breadboard.
ternally connected so as to have the same voltage.
The Arduino Uno has some ground pins, analog
Similarly, in the central segments, the pins in each
input pins A0-A3 and digital pins D1-D13 that can
column are internally connected in the same fashion
be used for both input as well as output. It also
as the blue columns.
has two power pins that can generate 3.3V and 5V.
Problem 2.1. Plug the display to the breadboard in In the following exercises, only the GND, 5V and
Fig. 2.1 digital pins will be used.
Problem 2.3. Connect the 5V pin of the arduino to
*The author is with the Department of Electrical Engineering,
Indian Institute of Technology, Hyderabad 502285 India e-mail: an extreme pin that is in the same segment as the
[email protected]. 1K resistor pin.
2

g f COM a b Problem 2.9. Open geany and type the following


code. Save the file as hello.asm

; hello
a ; using assembly language for
t u r n i n g LED on
f b
. i n c l u d e ” / home / a l a r m / m328Pdef . i n c
g

e c l d i r16 , 0 b00100000
o u t DDRB, r 1 6
d
l d i r17 , 0 b00000000
dot o u t PortB , r 1 7
Start :
rj m p S t a r t

e d COM c dot Problem 2.10. With hello.asm open in geany, go to


Build→Set Build Commands→Compile and enter
Fig. 2.2
a v r a ”%f ”

Problem 2.4. Connect the GND pin of the arduino Then go to Build→Set Build Commands→Execute
to the opposite extreme pin of the breadboard and enter
a v r d u d e −p at m eg a3 2 8 p −c a r d u i n o −
Problem 2.5. Connect the Arduino to the computer.
P / dev / ttyACM0 −b 115200 −U
Problem 2.6. Connect the dot pin of the display to f l a s h :w:% e . hex
a pin in the same segment as the GND pin. What
do you observe? Problem 2.11. Change /home/linaro/m328Pdef.inc
in hello.asm to /home/username/m328Pdef.inc,
where username is your linux login name.
2.2 Software Setup
Problem 2.7. Install AVRA and AVRDUDE on
your Linux system through the following commands 2.3 Controlling the Display
Problem 2.12. Now connect the dot pin of the
sudo apt −g e t i n s t a l l a v r a avrdude
%F i n d i n g t h e p o r t display to pin 13 of the arduino. Use F8 to compile
hello.asm and F5 to execute.
s u d o dmesg | g r e p t t y Problem 2.13. Turn the LED off by modifying
%The o u t p u t w i l l be s o m e t h i n g l i k e hello.asm.
[ 6 . 1 5 3 3 6 2 ] cdc acm 1 − 1 . 2 : 1 . 0 :
ttyACM0 : USB ACM d e v i c e Problem 2.14. Complete Table 2.14.1 for all the
%and y o u r p o r t number i s ttyACM0 digital pins using Fig. 2.14

Problem 2.8. Download the m328Pdef.inc file from Port Pin Digital Pin
PD2 2
h t t p : / / t l c . i i t h . ac . i n / img / m328Pdef
. inc PB5 13
TABLE 2.14.1
and copy into the directory home (/home/user/)
directory
3

PD2 PD3 PD4 PD5 PD6 PD7 PB0


decimal
a b c d e f g
0 0 1 0 0 1 0 2
TABLE 2.16.1

3 Display Decoder
The 7447 IC helps in displaying decimal numbers
on the seven segment display. The ā − f¯, pins of
the 7447 IC are connected to the a − f pins of
the display. Vcc should be connected to a 5V power
source. The input pins of the decoder are A,B,C and
Fig. 2.14 D, with A being the lowest significant bit (LSB)
and D being the most significant bit (MSB). For
example, the number 5 is visible on the display
Problem 2.15. Connect the a −g pins of the display when the A,B,C and D inputs are the following.
to the 2-8 pins of the arduino. Run the following
code. D C B A Decimal
0 1 0 1 5
; using assembly language for
; d i s p l a y i n g number on
; seven segment d i s p l a y VCC f¯ ḡ ā b̄ c̄ d̄ ē
16 15 14 13 12 11 10 9
. i n c l u d e ” / home / l i n a r o / m328Pdef .
inc ”
7447

; C o n f i g u r i n g p i n s 2−7 o f A r d u i n o
; as out put 1 2 3 4 5 6 7 8
B C D A GND
l d i r16 , 0 b11111100
o u t DDRD, r 1 6
Fig. 3.0
; Co n fi g u ri n g pin 8 of Arduino
; as out put
l d i r16 , 0 b00000001 Problem 3.1. Connect the 7447 IC decoder ā − ḡ
o u t DDRB, r 1 6 pins to the a − g pins of the display respectively.
; W r i t i n g t h e number 2 on t h e Problem 3.2. Connect the Vcc and GND pins of
; seven segment d i s p l a y the decoder to the 5V supply and GND pins of the
l d i r17 , 0 b10010000 breadboard.
o u t PortD , r 1 7

l d i r17 , 0 b00000000 3.1 Driving the Segments


o u t PortB , r 1 7
Problem 3.3. Connect the A-D pins of the 7447 IC
Start : to the pins D2-D5 of the Arduino.
rj m p S t a r t
Problem 3.4. Type the following code and execute.
What do you observe?
Problem 2.16. The output of Problem 2.15 can be
explained by Table 2.16.1 below. Complete Table ; d r i v i n g t h e 7447 d e c o d e r
2.16.1 for all numbers between 0-9. Use this infor-
mation to display the numbers from 0-9 .
4

. i n c l u d e ” / home / a l a r m / m328Pdef . i n c ; o r r16 , r 1 7 ;W


” OR X
; l o g i c a l XOR
l d i r16 , 0 b00111100 ; e o r r16 , r 1 7 ;X
identifying output pins XOR X
2 ,3 ,4 ,5
o u t DDRD, r 1 6 ; ; f o l l o w i n g co d e i s f o r d i s p l a y i n g
d e c l a r i n g pi ns as out put output
l d i r16 , 0 b00010100 ; ; s h i f t i n g LSB i n r 1 6 t o 2 nd
l o a d i n g t h e number 5 i n position
binary l d i r20 , 0 b00000010 ; counter =
o u t PORTD , r 1 6 ; 2
writing output to pins
2 ,3 ,4 ,5 r c a l l loopw ; calling
t h e loopw r o u t i n e
Start :
rj m p S t a r t o u t PORTD , r 1 6 ; writing
output to pins 2 ,3 ,4 ,5
Problem 3.5. Now generate the numbers 0-9 by
modifying the above program.
Start :
rj m p S t a r t
4 Boolean Operations
; loop for b i t s h i f t i n g
Test all the following using the 7447 IC
loopw : l s l r16 ;
Problem 4.1. Verify the AND,OR and XOR oper- left shift
ations in assembly. d ec r 2 0 ;
c o u n t e r −−
Solution:
brne loopw ; if
; l o g i c a l AND, OR and XOR c o u n t e r != 0
operations ret
; o u t p u t d i s p l a y e d u s i n g 7447 IC

. i n c l u d e ” / home / a l a r m / m328Pdef . i n c Problem 4.2. Write a routine for finding the com-
” plement of a number.
Solution:
l d i r16 , 0 b00111100 ; i d e n t i f y i n g
output pins 2 ,3 ,4 ,5 ; p ro g ram t o co m p l em en t a b o o l e a n
o u t DDRD, r 1 6 ; declaring
pi ns as out put
. i n c l u d e ” / home / a l a r m / m328Pdef . i n c

l d i r16 , 0 b00000000 ; l d i r16 , 0 b00111100 ; i d e n t i f y i n g


initializing W output pins 2 ,3 ,4 ,5
l d i r17 , 0 b00000001 ; o u t DDRD, r 1 6 ; declaring
initializing X pi ns as out put
; l o g i c a l AND
; and r16 , r 1 7 ;W AND X l d i r16 , 0 b00000000 ; A=1
; l o g i c a l OR
5

r c a l l comp ; j u m p t i n g t o comp Z Y X W D C B A
r o u t i n e below 0 0 0 0 0 0 0 1
0 0 0 1 0 0 1 0
; f o l l o w i n g co d e i s f o r d i s p l a y i n g 0 0 1 0 0 0 1 1
output
0 0 1 1 0 1 0 0
; s h i f t i n g LSB i n r 1 6 t o 2 nd
position 0 1 0 0 0 1 0 1
l d i r20 , 0 b00000010 ; counter = 0 1 0 1 0 1 1 0
2 0 1 1 0 0 1 1 1
0 1 1 1 1 0 0 0
r c a l l loopw ; calling 1 0 0 0 1 0 0 1
t h e loopw r o u t i n e
1 0 0 1 0 0 0 0
o u t PORTD , r 1 6 ; writing TABLE 5.2.1
output to pins 2 ,3 ,4 ,5

Solution: The desired equations are


Start :
rj m p S t a r t A = W′ (5.1.1)
B = WX ′ Z ′ + W ′ X (5.1.2)
; loop for b i t s h i f t i n g C = WXY ′ + X ′ Y + W ′ Y (5.1.3)
loopw : l s l r16 ; D = WXY + W ′ Z (5.1.4)
left shift
d ec r 2 0 ; Problem 5.2. Write an assembly program for im-
c o u n t e r −− plementing Table 5.2.1 and verify if your logic
brne loopw ; if is correct by observing the output on the seven
c o u n t e r != 0 segment display.
ret

; comp r o u t i n e b e g i n s 6 Decade Counter through Arduino


comp : Problem 6.1. Use the following code for LED
mov r0 , r 1 6 blinking. You will have to connect pin 13 to the
; using r0 for LED on the seven segment display. The blinking
computations delay that you obtain is 1 second.
l d i r16 , 0 b00000001 ;
loading 1 . i n c l u d e ” / home / a l a r m / m328Pdef . i n c

e o r r16 , r 0
;A ’=A XOR 1 ; works a s 1 s e c o n d d e l a y on
ret a r d u i n o : 16 MHz ( 1 6 x10 ˆ 6 )
; r e t u r n i n g from comp
s b i DDRB, 5 ; s e t p i n 13 a s o u t p u t
p i n (DDRB p i n 5 )
5 Combinational Logic l d i r16 , 0 b00000101 ; t h e l a s t 3
Problem 5.1. In the truth table in Table 5.2.1, b i t s d e f i n e t h e p r e s c a l e r , 101
W, X, Y, Z are the inputs and A, B, C, D are the out- => d i v i s i o n by 1024
puts. This table represents the system that incre- o u t TCCR0B , r 1 6
ments the numbers 0-8 by 1 and resets the number ; p r e s c a l a r u s e d = 1 0 2 4 . So new
9 to 0 Using K-maps, write the boolean logic f r e q . o f c l o c k c y c l e = ( 1 6 MHz /
functions for A, B, C in terms of W, X, Y, Z. 1 0 2 4 ) = 16 kHz
6

D2-D5 pins as Arduino input.


c l r r 1 8 ; o u t p u t b i t s . we a r e o n l y
i n t e r e s t e d i n b i t 6 from t h e VCC Q2
D2 CLK2
right . 14 13 12 11 10 9 8

l d i r20 , 0 b00100000 ;
initializing 7474

loop :
e o r r18 , r 2 0 ; 1 2 3 4 5 6 7
c h a n g e t h e o u t p u t o f LED D1 CLK1 Q1 GND
o u t PORTB , r 1 8
l d i r19 , 0 b01000000 ; t i m e s Fig. 6.2
t o r u n t h e l o o p = 64
for 1 second delay Problem 6.3. Connect the Q pins to IC 7447
r c a l l PAUSE ; Decoder as input pins. Connect the 7447 IC to the
c a l l t h e PAUSE l a b e l seven segment display.
rj m p l o o p
Problem 6.4. Connect the D6-D9 pins of the ar-
PAUSE : ; t h i s is delay ( function ) duino to the D input pins of two 7474 ICs. Use the
lp2 : ; l o o p r u n s 64 t i m e s D6-D9 pins as Arduino output.
IN r16 , TIFR0 ; Problem 6.5. Connect pin 13 of the Arduino to the
t i f r is timer CLK inputs of both the 7474 ICs.
i n t e r u p t f l a g (8
b i t timer runs Problem 6.6. Using the logic for the counting
256 t i m e s ) decoder in assembly in Section 5, implement the
l d i r17 , 0 decade counter using flip-flops.
b00000010
AND r16 , r 1 7 ; n eed
second b i t
BREQ PAUSE
OUT TIFR0 , r 1 7 ;
set t i f r flag
high
d ec r 1 9
brne lp2
ret

; prescalar ∗ loop iterations ∗


t i m e r d u r a t i o n =˜ 16 m i l l i o n
cycles
; 1 6 m i l l i o n c y c l e s a t 16 MHz = 1
second

The 7474 IC in Fig. 6.2 has two D flip flops. The


D pins denote the input and the Q pins denote the
output. CLK denotes the clock input.
Problem 6.2. Connect the D2-D5 pins of the ar-
duino to the Q pins of the two 7474 ICs. Use the

You might also like