Tim Sumner, Imperial College, Rm: 1009, x47552

Slides:



Advertisements
Similar presentations
Code Composer Department of Electrical and Computer Engineering
Advertisements

EXTERNAL COMMUNICATIONS DESIGNING AN EXTERNAL 3 BYTE INTERFACE Mark Neil - Microprocessor Course 1 External Memory & I/O.
MICRO-CONTROLLER: A microcontroller is the brain of the robot: These are: 1. Integrated Circuits (ICs) 2. Programmable.
Mark Neil - Microprocessor Course 1 Timers and Interrupts.
COMP3221: Microprocessors and Embedded Systems Lecture 2: Instruction Set Architecture (ISA) Lecturer: Hui Wu Session.
Embedded System Design Laboratory September 27, 2002Stanford University - EE281 Lecture #1 Lecture #1 Outline Welcome Back AVR Hardware –Pins and Ports.
328eForth for Arduino Uno C. H. Ting February 16, 2012 SVFIG.
AVR Microcontrollers.
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1.
ADAM46P20 Simulator V User’s Manual ETA Chips, Co., Kr., 2011 By W.S.YOU.
A Few Words From Dilbert
Microcontroller Presented by Hasnain Heickal (07), Sabbir Ahmed(08) and Zakia Afroze Abedin(19)
ADAM2 Single Remocon MCU IDE User’s Manual S/W Integrated Development Environment - Assembler - Simulator - Code Wizard V1.0 Technical Sales Team, ETA.
ECS642U Embedded Systems Digital I/O William Marsh.
Introduction to AVR Chapter 1
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
Timers and Interrupts Mark Neil - Microprocessor Course.
BRANCHES SUBROUTINES AND MEMORY USAGE AVR Assembler M. Neil - Microprocessor Course 1.
1 Basic Processor Architecture. 2 Building Blocks of Processor Systems CPU.
AVR Architecture Prepared By: Avdhesh Soni ( ) Sarthak Patel ( ) Akshay Parekh ( ) Fenil Sachla ( ) Guided.
Introduction to AVR Name : 1) Abhishek Yadav ) Prakash Giri ) Kheni Niral ) Bhadresh Langadiya Branch.
NAM S.B MDLAB. Electronic Engineering, Kangwon National University 1.
Programming and Debugging with the Dragon and JTAG Many thanks to Dr. James Hawthorne for evaluating the Dragon system and providing the core content for.
“ INSTRUCTIONS SET OF AVR MICROCONTROLLER ” SIGMA INSTITUTE OF ENGINEERING Prepared By: SR.NO NAME OF STUDENT ENROLLMENT 1 Abhishek Lakhara
Embedded Microcontroller Systems
INTRODUCTION TO AVRASSEMBLY PROGRAMMING
Embedded Systems Programming
Programming and Debugging with the Dragon and JTAG
HISTORY OF MICROPROCESSORS
COURSE OUTCOMES OF Microprocessor and programming
COMP2121: Microprocessors and Interfacing
Introduction to Smart Systems
Atmega32 Architectural Overview
C. K. Pithawalla College of Engineering and Technology, Surat
AVR ATMEGA 8 MICRO-CONTROLLER
Slides developed in part by Mark Brehob & Prabal Dutta
Overview of Architecture Assembly Programming Concepts
Gunjeet Kaur Dronacharya Group of institutions
Computer Organization & Assembly Language Chapter 3
COMP2121: Microprocessors and Interfacing
Lecture on Microcomputer
Introduction of microprocessor
Atmega32 Serial Programming Basics
The Arduino Microcontroller: Atmel AVR Atmega 328
An Introduction to Microprocessors
ATmega103 Timer0 and Interrupts
ECET 330 Innovative Education--snaptutorial.com
Introduction to Microprocessors and Microcontrollers
Number Representations and Basic Processor Architecture
I/O Ports in AVR Sepehr Naimi
Introduction to Assembly Chapter 2
Architecture & Support Components
Chapter 1 Introduction.
Architectural Overview
Lecturer: Reza Arjmandi Autumn 2015
Introducing the PIC Mid-Range Family and the 16F84A
Tim Sumner, Imperial College, Rm: 1009, x47552
Unit – Microcontroller Tutorial Class - 2 ANITS College
Introduction to Assembly Chapter 2
CSC235 - Visual Studio Tutorial
AVR – ATmega103(ATMEL) Architecture & Summary
Decoding and Using a 4x4 Keyboard
8051 Micro Controller.
Device Drivers – Digital Voltmeter
8051 Development System Details
An Introduction to Microprocessors
Costas Foudas, Imperial College, Rm: 508, x47590
Decoding and Using a 4x4 Keyboard
Presentation transcript:

Tim Sumner, Imperial College, Rm: 1009, x47552 ATmega103 Assembler I 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Outline: ATmega103 architecture AVR assembler language Elementary example program AVR Assembler Using the AVR STUDIO 4 simulator Downloading with PonyProg 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

The ATmega103 Microprocessor In this course you will be using the ATmega103 processor mounted on an ATMEL programming board 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 The ATMEL BOARD Connecting the board with your PC 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 ATmega103 diagram  RISC Architecture  121 Instructions  32x8 Registers  4 MIPS @ 4 MHz  128 Kbytes In-System Prog. Flash Memory  4 Kbytes SRAM  4 Kbytes In-System EEPROM 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 ATmega103 Peripherals I  6 PORTS;  4 Bi-Directional  1 Output  1 Input Port A 8-bit I/O SRAM ADDR/DATA Port C SRAM ADDRESS 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 ATmega103 Peripherals II Interrupt Unit 8-Channel 10 Bit ADC with interrupt On Chip analog Comparator with Interrupt.  Prog. Watchdog Timer  Real Time Counter SPI Interface UART 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

The ATmega103 Architecture I Your Program resides in this 128 Kbytes memory in .hex Intel format (hex numbers ) The Program Counter keeps track of which instruction is to be executed next The PC value at a subroutine call is stored in SRAM and after the subroutine execution (return) it is increased by 1 and loaded back. 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

The ATmega103 Architecture II 32 General Purpose Registers The Arithmetic Logic Unit operates on the 32 registers 8-bit Data Bus 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 The ATmega103 Memory Map 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

AVR Assembler Language Why Assembler?  Direct access to the architecture of the processor Direct use of the machine registers memory and stack Full control of the processor Faster 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Registers There are 32 registers r0-r31 on ATmega103. You may name them in a way that you can remember: Example: .def InPutRegister = r16 You can zero (clear) them by: Example: clr r16 ; This would load $00 on r16 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Registers I You can set them to ones by: Example: ser r16 ; This would load $FF on r16 Remember the D-Flip-Flop ?? 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Registers II Both CLR and SER are Direct Single Register Addressing 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Loading a register You can set the contents of r16 by: ldi InPutRegister, $AA The ldi command will load with the HEX value $AA to register InPutRegister which you have defined to be r16 earlier. 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Two register commands Introduce one more register r15: .def RegisterTwo = r15 The following command: mov RegisterTwo, InPutRegister will transfer the contents of r16 ($AA) to r15 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Direct two register MOV Rd, Rx Note: that the direction goes Against intuition: 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 I/O Direct Addressing To read or write to the ATmega103 ports use the commands: IN Rd, PINX OUT PORTX, Rx ; X is A-F 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Port Example: DDRA : Direction Reg. PORTA : OUTPUT Reg. PINA : INPUT (no Reg.) 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Setting up a port: PORTB : OUTPUT PORT ; ******* Port B Setup Code **** ldi r16, $FF ; out DDRB , r16 ; Port B Direction Register ldi r16, $FF ; Init value out PORTB, r16 ; Port B value ; ******* Port D Setup Code **** ldi r16, $00 ; I/O: out DDRD, r16 ; Port D Direction Register out PORTD, r16 ; Port D value PORTD : INPUT PORT 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Program Header I: ; ** ATmega103(L) Assembly Language File - IAR Assembler Syntax ** .ORG 0 .include “m103def.inc” ; Add required path to IAR Directory RJMP Init ; ** Author : Costas Foudas ; ** Company : Imperial College ; ** Comment : Program Header; PORTB=OUT, PORTD=IN 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Program Header II: Init: ; ************* Stack Pointer Setup Code ldi r16, $0F ; Stack Pointer Setup out SPH,r16 ; Stack Pointer High Byte ldi r16, $FF ; Stack Pointer Setup out SPL,r16 ; Stack Pointer Low Byte ; ******* RAMPZ Setup Code **** ldi r16, $00 ; 1 = EPLM acts on upper 64K out RAMPZ, r16 ; 0 = EPLM acts on lower 64K ; ******* Comparator Setup Code **** ldi r16,$80 ; Comparator Disabled, Input ; Capture Disabled out ACSR, r16 ; Comparator Settings 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Example LED Program: Main: IN r16, PIND OUT PORTB, r16 rjmp Main Read in PortD Write the PortD input to the PortB output register Go back to Main 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Setting up a code directory: Open a directory where you will store you code: Down-load into this directory the files: LEDIO.ASM from the course web page (Lecture 2b): DO NOT DOWNLOAD m103def.inc !!!! Make sure you have : LEDIO.ASM in your code directory 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Getting Started with STUDIO 4: Go to Start  Programs  ATMEL AVR Tools  AVR Studio 4 Select New Project 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Getting Started with STUDIO 4: Create new folder Do not create new file You should be getting now the window: Pick a name for your project Pick Atmel AVR Assembler At the end Click this and navigate to your code directory 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Getting Started with STUDIO 4: You should be getting now the window: Select ATmega 103 (or 128) Select AVR Simulator At the end 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Entering files in STUDIO 4 (I): (1) Right click here and select to ‘Add Files to Project’ (2) Navigate and find LEDIO.ASM 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552 Load file

Entering files in STUDIO 4 (II): Here is list of files attached to project This window is for editing one of the files Change the ‘editing window’ by double clicking on file icon if several files 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Select the output file format : Click on Project/ Assembler Options Select Intel Hex format Change the format of the output file 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Running your Program in Studio 4 : Click on Build/ Build and run 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Running your Program in Studio 4: Program is halted at this instruction Have a look at the included file! The Build process has generated some new files Green means ok; Otherwise click on red and debug 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Open monitoring Windows: View/ Toolbars/ I/O 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Open monitoring Windows: Expand views as required Adjust screen display using Window/… InPut OutPut 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Watch your Program Running: Start here: Everything zeroed Use this to reset Use this to stop Use this to run continuously with active display Use this to run continuously without display Click this once and again Step through the whole program and make sure you understand what is happening 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Exercising the ATmega103 commands: Look at the processor assembly commands in the web page and try writing other programs. Try the commands SER, CLR, MOV, ADD, INC, LSL,… and see what they do…… Write some programs that use these commands and output the results on PORTB so you will be able to see them on the PORTB LEDs when down-load for real to the ATmega103. 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Downloading with Ponyprog I Select from Start : ponyprog2000 Open input Flash File 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Downloading with Ponyprog II Select from *.hex and LEDIO 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Downloading with Ponyprog III This is your machine code to be downloaded to the ATmega103 chip 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Downloading with Ponyprog IV Select your Processor again 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Downloading with Ponyprog V In ponyprog2000: (1) Setup (Parallel, AVR I/O, LP1) (2) Calibrate (3) Select AVR family and ATmega103 (4) Load your flash file LEDIO.hex (5) Erase the Flash memory (6) Write the flash memory 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Programs to write I: Download from the Web Page the program LEDIO.asm, assemble it and run it. What do you see if you press the buttons on PORTD? Do you know why this happens (dark LED  1)? (2) Write a program that adds 2 numbers and outputs the result at PORTB. Read the result using the LEDs. 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Programs to write II: (3) Make a counter from 0 – FF, output the values to PORTB and look with your scope probe at the LSB (PB0). How long does it take to make an addition? Why does the B0 bit toggle with a frequency that is twice that of B1? (check this using two scope probes; one on B0 and another on B1) (4) In the documentation you will find how many clock counts are required to perform an instruction in your program. The ATmega103 has a 4 MHz clock. Predict the time it takes to do an addition and compare with your measurement using the scope. 27 November 2018 Tim Sumner, Imperial College, Rm: 1009, x47552