Assembly Programming through Arduino

Similar documents
Digital Design through Arduino

Digital Design through Pi

Lab 3 Revisited. Zener diodes IAP 2008 Lecture 4 1

LABORATORY MANUAL MICROPROCESSOR AND MICROCONTROLLER

Exam for Physics 4051, October 31, 2008

S.Y. Diploma : Sem. III [DE/ED/EI/EJ/EN/ET/EV/EX/IC/IE/IS/IU/MU] Principles of Digital Techniques

LOGIC CIRCUITS. Basic Experiment and Design of Electronics. Ho Kyung Kim, Ph.D.

LOGIC CIRCUITS. Basic Experiment and Design of Electronics

10/12/2016. An FSM with No Inputs Moves from State to State. ECE 120: Introduction to Computing. Eventually, the States Form a Loop

Digital Circuits. 1. Inputs & Outputs are quantized at two levels. 2. Binary arithmetic, only digits are 0 & 1. Position indicates power of 2.

Sample Test Paper - I

ECE20B Final Exam, 200 Point Exam Closed Book, Closed Notes, Calculators Not Allowed June 12th, Name

PAST EXAM PAPER & MEMO N3 ABOUT THE QUESTION PAPERS:

CprE 281: Digital Logic

INTEGRATED CIRCUITS. For a complete data sheet, please also download:

CPE100: Digital Logic Design I

3. Complete the following table of equivalent values. Use binary numbers with a sign bit and 7 bits for the value

CHW 261: Logic Design

Design of Sequential Circuits

WORKBOOK. Try Yourself Questions. Electrical Engineering Digital Electronics. Detailed Explanations of

Digital Signal 2 N Most Significant Bit (MSB) Least. Bit (LSB)

Using a Microcontroller to Study the Time Distribution of Counts From a Radioactive Source

King Fahd University of Petroleum and Minerals College of Computer Science and Engineering Computer Engineering Department

Digital Electronic Meters

Preparation of Examination Questions and Exercises: Solutions

Fundamentals of Digital Design

Laboratory II. Exploring Digital Logic

5 8 LED MAX6950/MAX6951 MAX6950/MAX6951 SPI TM QSPI TM MICROWIRE TM 7 LED LED 2.7V MAX LED MAX LED 16 (0-9 A-F) RAM 16 7 LED LED

Lab #10: Design of Finite State Machines

Digital Electronics Final Examination. Part A

04. What is the Mod number of the counter circuit shown below? Assume initially reset.

DE58/DC58 LOGIC DESIGN DEC 2014

Hands-on Lab 3. System Identification with Experimentally Acquired Data

EXPERIMENT Bit Binary Sequential Multiplier

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

ISSP User Guide CY3207ISSP. Revision C

Schedule. ECEN 301 Discussion #25 Final Review 1. Date Day Class No. 1 Dec Mon 25 Final Review. Title Chapters HW Due date. Lab Due date.

INTEGRATED CIRCUITS. For a complete data sheet, please also download:

INTEGRATED CIRCUITS. For a complete data sheet, please also download:

University of Florida EEL 3701 Fall 2014 Dr. Eric. M. Schwartz Department of Electrical & Computer Engineering Wednesday, 15 October 2014

RAO PAHALD SINGH GROUP OF INSTITUTIONS BALANA(MOHINDER GARH)123029

SIR C.R.REDDY COLLEGE OF ENGINEERING ELURU DIGITAL INTEGRATED CIRCUITS (DIC) LABORATORY MANUAL III / IV B.E. (ECE) : I - SEMESTER

Appendix B. Review of Digital Logic. Baback Izadi Division of Engineering Programs

Digital Circuits ECS 371

CHAPTER 7. Exercises 17/ / /2 2 0

Digital Logic. CS211 Computer Architecture. l Topics. l Transistors (Design & Types) l Logic Gates. l Combinational Circuits.

Digital Electronics. Part A

UNSIGNED BINARY NUMBERS DIGITAL ELECTRONICS SYSTEM DESIGN WHAT ABOUT NEGATIVE NUMBERS? BINARY ADDITION 11/9/2018

NTE74176 Integrated Circuit TTL 35Mhz Presettable Decade Counter/Latch

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) State any two Boolean laws. (Any 2 laws 1 mark each)

INTEGRATED CIRCUITS. For a complete data sheet, please also download:

Digital Fundamentals

Counters. We ll look at different kinds of counters and discuss how to build them

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

Digital Circuits, Binary Numbering, and Logic Gates Cornerstone Electronics Technology and Robotics II

Experiment 9 Sequential Circuits

DIGITAL LOGIC CIRCUITS

S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Digital Techniques

Homework 1. Part(a) Due: 15 Mar, 2018, 11:55pm

Digital Electronics Circuits 2017

A crash course in Digital Logic

Binary addition example worked out

COEN 312 DIGITAL SYSTEMS DESIGN - LECTURE NOTES Concordia University

Layout of 7400-series Chips Commonly Used in. CDA 3101: Introduction to Computer Hardware and Organization

NOTE: The Flatpak version has the same pinouts (Connection Diagram) as the Dual In-Line Package. *MR for LS160A and LS161A *SR for LS162A and LS163A

Save from: cs. Logic design 1 st Class أستاذ المادة: د. عماد

Introduction to the Xilinx Spartan-3E

Lab #15: Introduction to Computer Aided Design

ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University

Logic Theory in Designing of Digital Circuit & Microprocessor

SOLUTION. Homework 1. Part(a) Due: 15 Mar, 2018, 11:55pm

Sequential Circuits. Circuits with state. Silvina Hanono Wachman Computer Science & Artificial Intelligence Lab M.I.T. L06-1

ECE 341. Lecture # 3

We are here. Assembly Language. Processors Arithmetic Logic Units. Finite State Machines. Circuits Gates. Transistors

NTE74177 Integrated Circuit TTL 35Mhz Presettable Binary Counter/Latch

EECS150 - Digital Design Lecture 16 Counters. Announcements

INTEGRATED CIRCUITS. For a complete data sheet, please also download:

Design of Combinational Logic

Boolean Logic Continued Prof. James L. Frankel Harvard University

Boolean Logic Prof. James L. Frankel Harvard University. Version of 3:20 PM 29-Aug-2017 Copyright 2017, 2016 James L. Frankel. All rights reserved.

Unit II Chapter 4:- Digital Logic Contents 4.1 Introduction... 4

INTEGRATED CIRCUITS. For a complete data sheet, please also download:

Introduction to Computer Engineering. CS/ECE 252, Spring 2017 Rahul Nayar Computer Sciences Department University of Wisconsin Madison

Menu. Excitation Tables (Bonus Slide) EEL3701 EEL3701. Registers, RALU, Asynch, Synch

Analog & Digital Electronics Laboratory. Code - CS391. Lab Manual

Shift Register Counters

Memorandum. Introduction. Design. Discussion. Contributions. Conclusion

Databases through Python-Flask and MariaDB

( c) Give logic symbol, Truth table and circuit diagram for a clocked SR flip-flop. A combinational circuit is defined by the function

VFD- RoHS Compliant M0116MY-161LSBR2-1. User s Guide. (Vacuum Fluorescent Display Module) For product support, contact

CE1911 LECTURE FSM DESIGN PRACTICE DAY 1

CSCI 2150 Intro to State Machines

EEE Lecture 1 -1-

Z = F(X) Combinational circuit. A combinational circuit can be specified either by a truth table. Truth Table

Boolean Algebra and Digital Logic 2009, University of Colombo School of Computing

Vidyalankar S.E. Sem. III [EXTC] Digital Electronics Prelim Question Paper Solution ABCD ABCD ABCD ABCD ABCD ABCD ABCD ABCD = B

Roger L. Tokheim. Chapter 8 Counters Glencoe/McGraw-Hill

MOSIS REPORT. Spring MOSIS Report 1. MOSIS Report 2. MOSIS Report 3


EECS150 - Digital Design Lecture 18 - Counters

Transcription:

1 Assembly Programming through Arduino G V V Sharma Contents 1 Components 1 2 Seven Segment Display 1 2.1 Hardware Setup....... 1 2.2 Software Setup........ 2 2.3 Controlling the Display... 2 3 Display Decoder 3 3.1 Driving the Segments.... 3 4 Boolean Operations 4 Component Value Quantity Breadboard 1 Resistor 220Ω 1 Arduino Uno 1 Seven Segment Common 1 Display Anode Decoder 7447 1 Flip Flop 7474 2 Jumper Wires 20 TABLE 1.0.1 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 first course on microprocessor architecture. 1 Components The components required for this manual are listed in Table 1.0.1. 2.1 Hardware Setup 2 Seven Segment Display The breadboard can be divided into 5 segments. In each of the green segements, the pins are internally connected so as to have the same voltage. Similarly, in the central segments, the pins in each column are internally connected in the same fashion as the blue columns. Problem 2.1. Plug the display to the breadboard in Fig. 2.1 *The author is with the Department of Electrical Engineering, Indian Institute of Technology, Hyderabad 502285 India e-mail: gadepall@iith.ac.in. Fig. 2.1 The seven segment display in Fig. 2.2 has eight pins, a, b, c, d, e, f, g and dot that take an active LOW input, i.e. the LED will glow only if the input is connected to ground. Each of these pins is connected to an LED segment. The dot pin is reserved for the LED. Problem 2.2. Connect one end of the resistor to the COM pin of the display and the other end to an extreme pin of the breadboard. The Arduino Uno has some ground pins, analog input pins A0-A3 and digital pins D1-D13 that can be used for both input as well as output. It also has two power pins that can generate 3.3V and 5V. In the following exercises, only the GND, 5V and digital pins will be used. Problem 2.3. Connect the 5V pin of the arduino to an extreme pin that is in the same segment as the 1K resistor pin.

2 g f COM a b a Problem 2.9. Open geany and type the following code. Save the file as hello.asm ; h e l l o ; u s i n g assembly l a n g u a g e f o r t u r n i n g LED on f g b. i n c l u d e / home/ alarm/ m328pdef. i n c e d c dot l d i r16, 0 b00100000 o u t DDRB, r16 l d i r17, 0 b00000000 o u t PortB, r17 e d COM c dot Fig. 2.2 Problem 2.4. Connect the GND pin of the arduino to the opposite extreme pin of the breadboard Problem 2.5. Connect the Arduino to the computer. Problem 2.6. Connect the dot pin of the display to a pin in the same segment as the GND pin. What do you observe? 2.2 Software Setup Problem 2.7. Install AVRA and AVRDUDE on your Linux system through the following commands 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 sudo dmesg grep t t y %The o u t p u t w i l l be something l i k e [ 6. 1 5 3 3 6 2 ] cdc acm 1 1. 2 : 1. 0 : ttyacm0 : USB ACM d e v i c e %and your p o r t number i s ttyacm0 Problem 2.8. Download the m328pdef.inc file from h t t p :// t l c. i i t h. ac. i n/ img/m328pdef. i n c and copy into the directory home (/home/user/) directory Problem 2.10. With hello.asm open in geany, go to Build Set Build Commands Compile and enter a v r a %f Then go to Build Set Build Commands Execute and enter avrdude p atmega328p c a r d u i n o P / dev/ ttyacm0 b 115200 U f l a s h :w:%e. hex Problem 2.11. Change/home/linaro/m328Pdef.inc in hello.asm to /home/username/m328pdef.inc, where username is your linux login name. 2.3 Controlling the Display Problem 2.12. Now connect the dot pin of the display to pin 13 of the arduino. Use F8 to compile hello.asm and F5 to execute. Problem 2.13. Turn the LED off by modifying hello.asm. Problem 2.14. Complete Table 2.14.1 for all the digital pins using Fig. 2.14 Port Pin Digital Pin PD2 2 PB5 13 TABLE 2.14.1

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 Fig. 2.14 Problem 2.15. Connect the a g pins of the display to the 2-8 pins of the arduino. Run the following code. ; u s i n g assembly l a n g u a g e f o r ; d i s p l a y i n g number on ; seven segment d i s p l a y. i n c l u d e / home/ l i n a r o/ m328pdef. i n c ; C o n f i g u r i n g p i n s 2 7 of Arduino ; as o u t p u t l d i r16, 0 b11111100 o u t DDRD, r16 ; C o n f i g u r i n g p i n 8 of Arduino ; as o u t p u t l d i r16, 0 b00000001 o u t DDRB, r16 ; W r i t i n g t h e number 2 on t h e ; seven segment d i s p l a y l d i r17, 0 b10010000 o u t PortD, r17 l d i r17, 0 b00000000 o u t PortB, r17 Problem 2.16. The output of Problem 2.15 can be explained by Table 2.16.1 below. Complete Table 2.16.1 for all numbers between 0-9. Use this information to display the numbers from 0-9. 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. V cc should be connected to a 5V power source. The input pins of the decoder are A,B,C and 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 when the A,B,C and D inputs are the following. V CC 16 f 15 D C B A Decimal 0 1 0 1 5 ḡ 14 ā 13 7447 1 2 3 4 5 6 7 8 B C D A GND b 12 Fig. 3.0 Problem 3.1. Connect the 7447 IC decoder ā ḡ pins to the a g pins of the display respectively. Problem 3.2. Connect the V cc and GND pins of the decoder to the 5V supply and GND pins of the breadboard. 3.1 Driving the Segments Problem 3.3. Connect the A-D pins of the 7447 IC to the pins D2-D5 of the Arduino. Problem 3.4. Type the following code and execute. What do you observe? ; d r i v i n g t h e 7447 d e c o d e r c 11 d 10 ē 9

4. i n c l u d e / home/ alarm/ m328pdef. i n c l d i r16, 0 b00111100 ; i d e n t i f y i n g o u t p u t p i n s 2, 3, 4, 5 o u t DDRD, r16 ; d e c l a r i n g p i n s as o u t p u t l d i r16, 0 b00010100 ; l o a d i n g t h e number 5 i n b i n a r y o u t PORTD, r16 ; w r i t i n g o u t p u t t o p i n s 2, 3, 4, 5 rjmp S t a r t Problem 3.5. Now generate the numbers 0-9 by modifying the above program. 4 Boolean Operations Test all the following using the 7447 IC Problem 4.1. Verify the AND,OR and XOR operations in assembly. Solution: ; l o g i c a l AND, OR and XOR o p e r a t i o n s ; 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/ alarm/ m328pdef. i n c l d i r16, 0 b00111100 ; i d e n t i f y i n g o u t p u t p i n s 2, 3, 4, 5 o u t DDRD, r16 ; d e c l a r i n g p i n s as o u t p u t l d i r16, 0 b00000000 ; i n i t i a l i z i n g W l d i r17, 0 b00000001 ; i n i t i a l i z i n g X ; l o g i c a l AND ; and r16, r17 ;W AND X ; l o g i c a l OR ; or r16, r17 ;W OR X ; l o g i c a l XOR e o r r16, r17 ;X XOR X ; f o l l o w i n g code i s f o r d i s p l a y i n g o u t p u t ; s h i f t i n g LSB i n r16 t o 2nd p o s i t i o n l d i r20, 0 b00000010 ; c o u n t e r = 2 r c a l l loopw ; c a l l i n g t h e loopw r o u t i n e o u t PORTD, r16 ; w r i t i n g o u t p u t t o p i n s 2, 3, 4, 5 ; loop f o r b i t s h i f t i n g loopw : l s l r16 ; l e f t s h i f t dec r20 ; c o u n t e r brne loopw ; i f c o u n t e r!= 0 Problem 4.2. Write a routine for finding the complement of a number. Solution: ; program t o complement a b o o l e a n. i n c l u d e / home/ alarm/ m328pdef. i n c l d i r16, 0 b00111100 ; i d e n t i f y i n g o u t p u t p i n s 2, 3, 4, 5 o u t DDRD, r16 ; d e c l a r i n g p i n s as o u t p u t l d i r16, 0 b00000000 ;A=1

5 r c a l l comp ; j u m p t i n g t o comp r o u t i n e below ; f o l l o w i n g code i s f o r d i s p l a y i n g o u t p u t ; s h i f t i n g LSB i n r16 t o 2nd p o s i t i o n l d i r20, 0 b00000010 ; c o u n t e r = 2 r c a l l loopw ; c a l l i n g t h e loopw r o u t i n e o u t PORTD, r16 ; w r i t i n g o u t p u t t o p i n s 2, 3, 4, 5 ; loop f o r b i t s h i f t i n g loopw : l s l r16 ; l e f t s h i f t dec r20 ; c o u n t e r brne loopw ; i f c o u n t e r!= 0 ; comp r o u t i n e b e g i n s comp : mov r0, r16 ; u s i n g r0 f o r c o m p u t a t i o n s l d i r16, 0 b00000001 ; l o a d i n g 1 e o r r16, r0 ;A =A XOR 1 ; u r n i n g from comp 5 Combinational Logic Problem 5.1. In the truth table in Table 5.2.1, W, X, Y, Z are the inputs and A, B, C, D are the outputs. This table represents the system that increments the numbers 0-8 by 1 and resets the number 9 to 0 Using K-maps, write the boolean logic functions for A, B, C in terms of W, X, Y, Z. Z Y X W D C B A 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 1 0 0 1 1 0 1 0 0 0 1 0 0 0 1 0 1 0 1 0 1 0 1 1 0 0 1 1 0 0 1 1 1 0 1 1 1 1 0 0 0 1 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 TABLE 5.2.1 Solution: The desired equations are A=W (5.1.1) B=WX Z + W X (5.1.2) C= WXY + X Y+ W Y (5.1.3) D=WXY+ W Z (5.1.4) Problem 5.2. Write an assembly program for implementing Table 5.2.1 and verify if your logic is correct by observing the output on the seven segment display. 6 Decade Counter through Arduino Problem 6.1. Use the following code for LED blinking. You will have to connect pin 13 to the LED on the seven segment display. The blinking delay that you obtain is 1 second.. i n c l u d e / home/ alarm/ m328pdef. i n c ; works as 1 second d e l a y on a r d u i n o : 16 MHz (16 x10 ˆ 6 ) s b i DDRB, 5 ; s e t p i n 13 as o u t p u t p i n (DDRB p i n 5) l d i r16, 0 b00000101 ; t h e l a s t 3 b i t s d e f i n e t h e p r e s c a l e r, 101 => d i v i s i o n by 1024 o u t TCCR0B, r16 ; p r e s c a l a r used = 1024. So new f r e q. of c l o c k c y c l e = (16 MHz / 1024) = 16 khz

6 c l r r18 ; o u t p u t b i t s. we a r e only i n t e r e s t e d i n b i t 6 from t h e r i g h t. D2-D5 pins as Arduino input. V CC 14 13 D2 12 CLK2 11 10 Q2 9 8 l d i r20, 0 b00100000 ; i n i t i a l i z i n g 7474 loop : e o r r18, r20 ; change t h e o u t p u t of LED o u t PORTB, r18 l d i r19, 0 b01000000 ; t i m e s t o run t h e loop = 64 f o r 1 second d e l a y r c a l l PAUSE ; c a l l t h e PAUSE l a b e l rjmp loop PAUSE : ; t h i s i s d e l a y ( f u n c t i o n ) l p 2 : ; loop r u n s 64 t i m e s IN r16, TIFR0 ; t i f r i s t i m e r i n t e r u p t f l a g (8 b i t t i m e r r u n s 256 t i m e s ) l d i r17, 0 b00000010 AND r16, r17 ; need second b i t BREQ PAUSE OUT TIFR0, r17 ; s e t t i f r f l a g high dec r19 brne l p 2 1 2 3 4 5 6 7 D1 CLK1 Q1 GND Fig. 6.2 Problem 6.3. Connect the Q pins to IC 7447 Decoder as input pins. Connect the 7447 IC to the seven segment display. Problem 6.4. Connect the D6-D9 pins of the arduino to the D input pins of two 7474 ICs. Use the D6-D9 pins as Arduino output. Problem 6.5. Connect pin 13 of the Arduino to the CLK inputs of both the 7474 ICs. Problem 6.6. Using the logic for the counting decoder in assembly in Section 5, implement the decade counter using flip-flops. ; p r e s c a l a r l o o p i t e r a t i o n s t i m e r d u r a t i o n = 16 m i l l i o n c y c l e s ; 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 arduino to the Q pins of the two 7474 ICs. Use the