EE 308: Microcontrollers

Similar documents
EE 308: Microcontrollers

EE 308: Microcontrollers

EE 308: Microcontrollers

EE 308: Microcontrollers

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

Review on Lecture-1. ICT 6641: Advanced Embedded System. Lecture 2 Branch, Call and Delay Loops, AVR I/O port programming

EE 308: Microcontrollers

AVR ISA & AVR Programming (I)

Module 8: Atmega32 Stack & Subroutine. Stack Pointer Subroutine Call function

Module 2: Introduction to AVR ATmega 32 Architecture

EE 308: Microcontrollers

Programming. A. Assembly Language Programming. A.1 Machine Code. Machine Code Example: Motorola ADD

COMP2121: Microprocessors and Interfacing. I/O Devices (II)

COMP2121: Microprocessors and Interfacing

COMP2121: Microprocessors and Interfacing. I/O Devices (I)

ECE 375 Computer Organization and Assembly Language Programming Winter 2018 Solution Set #2

By: Dr. Hamed Saghaei

IAS0430 MICROPROCESSOR SYSTEMS

Programming Microcontroller Assembly and C

Input/Output Devices. Lecturer: Sri Parameswaran Notes by: Annie Guo

8-bit Microcontroller with 8K Bytes Programmable Flash AT90C8534. Preliminary

Objectives. I/O Ports in AVR. Topics. ATmega16/mega32 pinout. AVR pin out The structure of I/O pins I/O programming Bit manipulating 22/09/2017

FIFTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLOGY-MARCH 2014 EMBEDDED SYSTEMS (Common for CT,CM) [Time: 3 hours] (Maximum marks : 100)

AVR Microcontrollers Architecture

Using SRAM in AVR assembler language

CN310 Microprocessor Systems Design

COMP2121 Experiment 4

Lecture 20: AVR Programming, Continued. AVR Program Visible State (ones we care about for now)

Microprocessors & Interfacing

;Compiler Options.NOLIST.INCLUDE "C:\Program Files (x86)\atmel\avr Tools\AvrAssembler2\Appnotes\m8515def.inc"

CHW 469 : Embedded Systems

APPENDIX A FOR SKEE3732 LABORATORY 1 SHEET

Microcontroller VU

Microcontrollers. Microcontroller

EE 308: Microcontrollers

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

AVR Subroutine Basics

Chapter 4: Atmel s AVR 8-bit Microcontroller Part 1 Assembly Programming

EECS 150 Homework 11 Solutions Fall 2008

AT90S Bit Microcontroller with 1K bytes Downloadable Flash AT90S1200. Features. Description. Pin Configuration

TYPES OF INTERRUPTS: -

8-bit Microcontroller with 4K Bytes In-System Programmable Flash. ATtiny40. Preliminary

Today s Menu. >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory

ATmega128 Assembly Language Programming

Gates and flip-flops: glue logic, simple FSMs, registers Two-level PLDs: FSMs, muxes, decoders. Programmable logic devices (CSE370, CSE467)

Buses and Parallel Input/Output

Logic Instructions and Programs READING

Microcontroller Intel [Instruction Set]

EXPERIMENT NO. 1 THE MKT 8085 MICROPROCESSOR TRAINER

Microcomputer Architecture and Programming

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

8-bit Microcontroller with 2/4/8K Bytes In-System Programmable Flash. ATtiny261/V ATtiny461/V ATtiny861/V. Preliminary

ET2640 Microprocessors

University of Florida EEL 4744 Dr. Eric M. Schwartz. Page 1/11 Revision 0 20-Feb-14 Mixed C and Assembly (for Atmel XMEGA)

Architecture & Instruction set of 8085 Microprocessor and 8051 Micro Controller

Mechatronics and Microcomputers. Stipendium Hungaricum 2018/2019 Autumn Semester Szilárd Aradi, PhD

8-bit Microcontroller with 2/4/8K Bytes In-System Programmable Flash. ATtiny261 ATtiny461 ATtiny861. Automotive

COMP3221: Microprocessors and Embedded Systems

8-bit Microcontroller with 2K Bytes of In-System Programmable Flash. ATtiny22 ATtiny22L. Preliminary. Features. Description

Exam I Review February 2017

COMP2121: Microprocessors and Interfacing. Instruction Formats and Addressing Modes

8-bit Microcontroller with 8K Bytes In-System Programmable Flash. ATmega8515 ATmega8515L. Features

8-bit Instruction Set

APPENDIX D FLOWCHARTS AND PSEUDOCODE OVERVIEW

AVR Assembler Examples

8-bit Microcontroller with 2K Bytes of In-System Programmable Flash AT90S2323 AT90LS2323 AT90S2343 AT90S/LS2323. Features.

Grundlagen Microcontroller Processor Core. Günther Gridling Bettina Weiss


Practical Malware Analysis

AVR Control Transfer -AVR Branching

CMPE C Programming & Embedded Systems. Discussion I (Version 2.0) August 31, 2014

AVR. (AVR Assembly Language) Assembler . ก ก

APPENDIX B AVR INSTRUCTIONS EXPLAINED OVERVIEW

Digital Blocks Semiconductor IP

Speed and Size-Optimized Implementations of the PRESENT Cipher for Tiny AVR Devices

8-bit Instruction Set

Embedded Systems and Software

Processor design - MIPS

AVR. 2. (Assembler directives ) 3. ( Instruction field) 5. (Comment field) 1. (Label field) Assembler. 4. ก (Operands field) (AVR Assembly Language)

Example of A Microprogrammed Computer

8-bit Microcontroller with 8K Bytes In-System Programmable Flash AT90S8515

9/25/ Software & Hardware Architecture

COMP2121: Microprocessors and Interfacing. Instruction Set Architecture (ISA)

8-bit Microcontroller with 4K/8K bytes In-System Programmable Flash AT90S4414 AT90S8515. Features. Pin Configurations

8051 Microcontroller Assembly Programming

ECED3204: Microprocessor Part I--Introduction

AVR Instruction Set Encoding

VCC PB2 (SCK/ADC1/T0/PCINT2) PB1 (MISO/AIN1/OC0B/INT0/PCINT1) PB0 (MOSI/AIN0/OC0A/PCINT0)

AE66/AC66/AT66/ AE108/AC108/AT108 MICROPROCESSORS & MICROCONTROLLERS

ENE 334 Microprocessors

8-Bit Microcontroller with 1K bytes In-System Programmable Flash AT90S1200. Features. Description. Pin Configuration

Subject Code: Model Answer Page No: /25

8-bit Microcontroller with 4/8K Bytes In-System Programmable Flash. ATtiny48/88. Preliminary

Register-Level Programming

A First Look at Microprocessors

CPE 323 MSP430 INSTRUCTION SET ARCHITECTURE (ISA)

2. Arithmetic Instructions addition, subtraction, multiplication, divison (HCS12 Core Users Guide, Sections 4.3.4, and ).

Digital Blocks Semiconductor IP

Computer System Architecture

Transcription:

EE 308: Microcontrollers Review Part I Aly El-Osery Electrical Engineering Department New Mexico Institute of Mining and Technology Socorro, New Mexico, USA February 15, 2018 Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 1 / 19

Harvard Architecture overview data bus data bus Code memory control bus CPU control bus Data memory address bus Harvard architecture address bus Separate buses for accessing code and data Faster Less delays Requires more hardware Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 2 / 19

Data, address and control lines Data lines carry information in and out of the CPU. More lines results in faster data transfer but more complex and more expensive. Address lines identifies the devices and memory to be connected to the CPU Control lines control devices signals for read/write as directed by the CPU Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 3 / 19

Memory Register file: embedded in the CPU for fast operations Code memory: ROM typically flash Data memory: RAM typically SRAM Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 4 / 19

Addressing modes Immediate (single-register): operand is a register and may have a constant value as a second operand, e.g., NEG R18 ;negate the content of R18 LDI R19,0 x06 ;load 0x06 into R19 Register: two registers hold the data to be manipulated ADD R20, R23 ;add R23 to R20 and store the result in R20 Direct: operand is a memory location LDS R19,0 x560 ;load R19 with the content of mem loc 0x560 STS 0x40, R19 ;store R19 to data space location 0x40 Register indirect: operand is a register but in points to the memory location LDI XL,0 x30 ;load R26 (low byte of X) with 0x30 LDI XH,0 x01 ;load R27 (high byte of X) with 0x01 LD R18,X ;load R18 with content of memory 0x130 Auto-increment/auto-decrement: content of register is pre- or post- incremented/decremented after/before memory access LD Rn,X+ ;load Rn with content pointed to by X then inc X LD Rn,-X ;decrement X then load Rn by contented pointed to by new X Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 5 / 19

Arithmetic Logic Unit (ALU) A[n 1 : 0] B[n 1 : 0] Takes two inputs Status Performs arithmetic and logic operations Op Code ALU Status Result Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 6 / 19

Memory map Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 7 / 19

I/O space I/Os and peripherals are placed in I/O space I/O addresses are offset from memory address by 0x20 I/O registers in the range 0x00 to 0x1F are directly bit accessible IN and OUT commands must use addresses in the range 0x00 to 0x3F When using LD and ST commands I/O registers are addressed as data space and therefore 0x20 must be added to their addresses Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 8 / 19

Assembly language Assembly language consists of, instructions referred to as mnemonics, directives and labels.. include " m1284def. inc " ldi r16, hi8 ( RAMEND ) out SPH, r16 ldi r16, lo8 ( RAMEND ) 5 out SPL, r16 ;initialize stack pointer sbi DDRC, 0 ;set bit 0 of ddrc here : sbi PORTC, 0 10 call delay ;call delay subroutine cbi PORTC, 0 call delay rjmp here 15 delay : ldi r20, 255 dl1 : dec r20 brne dl1 ret Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 9 / 19

Assembly language Assembly language consists of, instructions referred to as mnemonics, directives and labels.. include " m1284def. inc " ldi r16, hi8 ( RAMEND ) out SPH, r16 ldi r16, lo8 ( RAMEND ) 5 out SPL, r16 ;initialize stack pointer sbi DDRC, 0 ;set bit 0 of ddrc here : sbi PORTC, 0 10 call delay ;call delay subroutine cbi PORTC, 0 call delay rjmp here 15 delay : ldi r20, 255 dl1 : dec r20 brne dl1 ret Directive Label Comment Instruction Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 9 / 19

Manipulating the stack PUSH instruction: stores onto the stack POP instruction: removes content from the stack Data is stored where the SP is pointing and then it is decremented Last-in-first-out Some microcontrollers increment the SP rather than decrement Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 10 / 19

Initializing the stack pointer When the program starts the stack pointer is set to zero and will need to be initialized so that it points to the end of the RAM. As different microcontrollers have different size RAM we use RAMEND to represent the address of the last RAM location Stack pointer is initialized as follows LDI r16, hi8 ( RAMEND ) ;load SPH OUT SPH, r16 LDI r16, lo8 ( RAMEND ) ;load SPL OUT SPL, r16 SP could be decremented up to the point above 0x100 for the ATmega1284 Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 11 / 19

Program memory constant addressing 0x0001 Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 12 / 19

Program memory constant addressing 2-bytes 0x0001 Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 12 / 19

Program memory constant addressing 2-bytes 0x0000 0x0001 0x0001 Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 12 / 19

Program memory constant addressing 2-bytes 0x0000 0x0010 0x0001 0x0011 0x0001 Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 12 / 19

Program memory constant addressing 2-bytes 0x0000 0x0010 0x0001 0x0011 0x0001 The byte address of each location is the program address multiplied by 2 To access the high byte the Z register showed have a zero in the LSB To access the low byte the Z register showed have a one in the LSB GNU Assembler handles this natively In Atmel ASM2 you will have to multiply the desired address by 2 Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 12 / 19

Branching Write an assembly program that implements the following if (T >= 90) F = H ; else if (T > 40) F = N ; else F = C ; Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 13 / 19

Branching Write an assembly program that implements the following if (T >= 90) F = H ; else if (T > 40) F = N ; else F = C ; Assuming that the value of T is loaded into r20 and F is r21 cpi r20,90 brlt elseif ldi r21, H rjmp end elseif : cpi r20,40 brlt else ldi r21, N rjmp end else : ldi r21, C end : Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 13 / 19

Branching Write an assembly program that implements the following for (i =0; i <10; i ++) y = i /2; Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 14 / 19

Branching Write an assembly program that implements the following for (i =0; i <10; i ++) y = i /2; Assuming that the value of i is loaded into r20 and y is r21 for : cpi r20, 10 brge end mov r21, r20 asr r21 inc r20 jmp for end : Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 14 / 19

General digital I/O details Typically there are three main registers that control digital I/O ports Data Direction Register (DDRx): Controls whether each pin of a port x is an output (value of 1) or input (value of 0). Port Register (PORTx): Setting the bit in this register corresponds to sending a high value to the pin. Clearing a bit corresponds to setting the pin to low. Reading the PORTx provides the value that was written to it. Port Input Register (PINx): Generally used for reading the value of a pin that was set as an input. At reset all port are configured as input, i.e., DDRx is set to zero Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 15 / 19

Pull-up resistors What will happen if an input pin is connected to a switch that is connected to ground? Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 16 / 19

Pull-up resistors What will happen if an input pin is connected to a switch that is connected to ground? If the switch is not pressed the input value to the pin is floating Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 16 / 19

Pull-up resistors What will happen if an input pin is connected to a switch that is connected to ground? If the switch is not pressed the input value to the pin is floating If the switch is pressed the pin is shorted and must provide lots of current Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 16 / 19

Pull-up resistors What will happen if an input pin is connected to a switch that is connected to ground? If the switch is not pressed the input value to the pin is floating If the switch is pressed the pin is shorted and must provide lots of current Need a pull-up resistor Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 16 / 19

Using I/O port example Given and alarm system with an indicator if it is armed and indicator if a door is open. If the system is armed turn on an LED. If the system is armed and a door opens sound the alarm. Only pins 0, 1, 6 and 7 of port A are available. Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 17 / 19

Using I/O port example - solution Make pins 0 and 7 an input to represent the status of the system and the door, respectively. Make pins 1 and 6 of port A an output to control the LED and the siren, respectively. Don t change any of the other pins. Keep checking pin 0, if it goes high send a high on pins 1 and check pin 7. If pin 7 goes high output a high on pin 6. Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 18 / 19

Using I/O port example - solution Make pins 0 and 7 an input to represent the status of the system and the door, respectively. Make pins 1 and 6 of port A an output to control the LED and the siren, respectively. Don t change any of the other pins. Keep checking pin 0, if it goes high send a high on pins 1 and check pin 7. If pin 7 goes high output a high on pin 6. in r16, DDRA in r17, PORTA ori r16, (1<< PA1 ) (1 < < PA6 ) andi r16, ~((1 < < PA0 ) (1 < < PA7 )) andi r17, ~((1 < < PA1 ) (1 < < PA6 )) out PORTA, r17 out DDRA, r16 l1: sbis PINA, 0 rjmp l1 sbi PORTA,1 l2: sbis PINA, 7 rjmp l2 sbi PORTA,6 l3: rjmp l3 Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 18 / 19

Generating a square wave example. include " m1284def. inc " ldi r16, hi8 ( RAMEND ) out SPH, r16 ldi r16, lo8 ( RAMEND ) 5 out SPL, r16 ;initialize stack pointer sbi DDRC, 0 ;set bit 0 of ddrc here : sbi PORTC, 0 10 call delay ;call delay subroutine cbi PORTC, 0 call delay rjmp here 15 delay : ldi r20, 255 dl1 : dec r20 brne dl1 ret Aly El-Osery (NMT) EE 308: Microcontrollers February 15, 2018 19 / 19