Arduino Atmega Manual Book
Arduino Atmega Manual Book
5 Combinational Logic 5
; 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
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
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
. 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
”
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
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