Tim Sumner, Imperial College, Rm: 1009, x47552

Slides:



Advertisements
Similar presentations
Accessing Atmega32 SRAM data memory
Advertisements

EXTERNAL COMMUNICATIONS DESIGNING AN EXTERNAL 3 BYTE INTERFACE Mark Neil - Microprocessor Course 1 External Memory & I/O.
DAT2343 Comparison of The LMC and General Computer Models © Alan T. Pinck / Algonquin College; 2003.
COMP3221: Microprocessors and Embedded Systems--Lecture 7 1 COMP3221: Microprocessors and Embedded Systems Lecture 7: Arithmetic and logic Instructions.
COMP3221: Microprocessors and Embedded Systems--Lecture 7 1 COMP3221: Microprocessors and Embedded Systems Lecture 7: Arithmetic and logic Instructions.
Mark Neil - Microprocessor Course 1 Timers and Interrupts.
COMP3221: Microprocessors and Embedded Systems--Lecture 8 1 COMP3221: Microprocessors and Embedded Systems Lecture 8: Program Control Instructions
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
COMP3221: Microprocessors and Embedded Systems--Lecture 9 1 COMP3221: Microprocessors and Embedded Systems Lecture 9: Data Transfer Instructions
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Parul Polytechnic Institute Parul Polytechnic Institute Subject Code : Name Of Subject : Microprocessor and assembly language programming Name.
Rabel Talpur:12BME#025.  40-pin chip  Developed by Motorola in 1975  16 address lines and 8 data lines  Used only +5V.
Storing data in Program Memory
Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 7.
Introduction to AVR Chapter 1
Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing.
Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8.
Timers and Interrupts Mark Neil - Microprocessor Course.
Picoblaze Overview EENG Introduction 8-bit microcontroller for Xilinx devices Soft Core – Soft Processor 5% of the resources of spartan 3 (3S200.
Assembly Language Programming of 8085 BY Prof. U. V. THETE Dept. of Computer Science YMA.
BRANCHES SUBROUTINES AND MEMORY USAGE AVR Assembler M. Neil - Microprocessor Course 1.
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
Datapath and control Dr. ir. A.B.J. Kokkeler 1. What is programming ? “Programming is instructing a computer to do something for you with the help of.
“ INSTRUCTIONS SET OF AVR MICROCONTROLLER ” SIGMA INSTITUTE OF ENGINEERING Prepared By: SR.NO NAME OF STUDENT ENROLLMENT 1 Abhishek Lakhara
Unit Microprocessor.
Gursharan Singh Tatla INSTRUCTION SET OF 8085 Gursharan Singh Tatla Gursharan Singh Tatla
Unit 1 Instruction set M.Brindha AP/EIE
COURSE OUTCOMES OF Microprocessor and programming
COMP2121: Microprocessors and Interfacing
BLOCK DIAGRAM OF INTEL 8085.
Introduction to Smart Systems
Atmega32 Architectural Overview
C. K. Pithawalla College of Engineering and Technology, Surat
Control Unit Lecture 6.
Overview of Architecture Assembly Programming Concepts
Gunjeet Kaur Dronacharya Group of institutions
Assembly Language Programming of 8085
Microprocessor T. Y. B. Sc..
3.Instruction Set of 8085 Consists of 74 operation codes, e.g. MOV
COMP2121: Microprocessors and Interfacing
Introduction of microprocessor
Subroutines and the Stack
TAO1221 COMPUTER ARCHITECTURE AND ORGANIZATION LAB 3 & 4 Part 2
An Introduction to Microprocessors
ATmega103 Timer0 and Interrupts
Symbolic Instruction and Addressing
Introduction to Assembly Chapter 2
Serial versus Parallel Data Transfers
Tim Sumner, Imperial College, Rm: 1009, x47552
Chapter 1 Introduction.
Chapter 8 Central Processing Unit
Microprocessors And Microcontrollers
Addressing Modes Register Direct, with 1 and 2 registers I/O Direct
COMP2121: Microprocessors and Interfacing
And conditional branching
COMP3221: Microprocessors and Embedded Systems
Introduction to Assembly Chapter 2
Symbolic Instruction and Addressing
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Advanced Assembly Chapter 6
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Computer Architecture
Subroutines and the Stack
COMP3221: Microprocessors and Embedded Systems
An Introduction to Microprocessors
Costas Foudas, Imperial College, Rm: 508, x47590
Computer Operation 6/22/2019.
Embedded Systems- Instruct set
Presentation transcript:

Tim Sumner, Imperial College, Rm: 1009, x47552 ATmega103 Assembler II 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Outline: The ATmega103 Status Register Pointer Registers Branch instructions Defining Tables in the Program memory Structured Programming Elementary example program 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

The ATmega103 Status register SREG monitors the ALU activity SREG is used by branch, compare and arithmetic instructions 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Status Register bit definitions: H S V N Z C  S=NV 2’s Complement Overflow NEG. ZERO CARRY SREG is treated as another ‘port’ in the I/O region and can be accessed via IN/OUT commands  The higher bits are subject of more advanced discussions reserved for later. 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Exercising the Status register Write this program to read the Status Register and output its contents to the PORTB LEDs: Change this number and see how the SREG bits change Main: LDI r16, $55 CLR r17 CPI r16, $54 IN r17, SREG OUT PORTB, r17 rjmp Main CPI Rd, K Means Rd – K and adjust SR flags Z,N,V,C,H as appropriate 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Exercising the Status register Exercise: Try to set the various status register bits using commands (like CPI) that would set them. Hint: Check the documentation of the ATmega103 assembler commands and find commands that can set the various flags. 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Pointer Registers I The three pairs of registers: r31:r30 (≡Z), r29:r28 (≡Y), r27:r26 (≡X) are special pointer registers and can be used to access memory via : LD Rd, X or LD Rd, Y or LD Rd, Z Meaning: Load the contents of memory address X or Y or Z into register Rd 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Pointer Registers II We can chose to increment memory address after the operation is finished: or decrement before the operation : LD Rd, X+ LD Rd, Y+ LD Rd, Z+ LD Rd, -X LD Rd, -Y LD Rd, -Z 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Pointer Registers III To store the register contents to the memory use : ST X, Rx ST Y, Rx ST Z, Rx ST X+, Rx ST Y+, Rx ST Z+, Rx ST -X, Rx ST -Y, Rx ST -Z, Rx 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Pointer Registers IV Hence data can be moved from the data SRAM to the register file and the reverse using LD and ST commands ST, LD Data can be moved from the program flash memory to the register file ONLY via the Z- register and by using the LPM command. LPM 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Pointer Registers V A special command which moves data from the program memory at address Z to register r0 : LPM 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Structured Programming Design your programme into a main control segment, which calls sub-routines (marks will be given) Subroutines should perform specific tasks/repeated functions Comments galore! Delay0: INC r16 BREQ finito rjmp Delay0 finito: ret Within your main program you can call subroutines by: rcall delay0 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Top Down Modular Programming complexity Calculator time Initialise Get command Calculate Output C C Load values Prompt message Input Interpret command Select/run routine Format output Display Reset C C Output character Input character Output character Output character …. …. …. 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Top Down Modular Programming complexity Alarm Clock time You have 10mins to have a go at TDM for this 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Branch Instructions In the previous example: Delay0: ;subroutine to introduce a delay INC r16 ;add 1 to r16 BREQ finito ;if zero then end rjmp Delay0 ;if not then loop finito: ret The command BREQ inspects SREG after the INC command has been executed. If the ZERO bit is set it will instruct the processor to jump to ‘finito’ 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Exercises: Exercise 1 : Last time you made a counter. Now use a subroutine to delay the speed of the counter. Exercise 2 : You can delay further by cascading delay subroutines. Exercise 3 : Write a program that writes incrementing numbers to the SRAM. Read them back, compare with what you expect to see and if (use a branch) it is not correct send a pattern of lights to PORTB (memory test program). What happens if you do not start writing from address $0060? 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Memory Map Reminder 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tables in the Program Memory A convenient way to store a data pattern in the program memory: MyTable: .DW $0100, $0302, $0504, $0706, $0908 ;Table loading with 16 bit words .DW $0B0A, $0D0C, $0F0E, $1110, $1312 ;Next 5 16-bit words in the table .DW $1514, $1617, $1918, $1B1A, $1D1C ;Next 5 16-bit words in the table .DW $1F1E ;Last word in the table 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Accessing Program Memory I Access the table : Need to find out the address of this table in the microprocessors program memory ! MyTable: .DW $0100, $0302, $0504, $0706, $0908 ;Table loading with 16 bit words .DW $0B0A, $0D0C, $0F0E, $1110, $1312 ;Next 5 16-bit words in the table .DW $1514, $1617, $1918, $1B1A, $1D1C ;Next 5 16-bit words in the table .DW $1F1E ;Last word in the table 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Accessing Program Memory II To calculate the address use: Start: ldi ZH, HIGH(MyTable*2) ; load the Table address to Z (High Byte) ldi ZL, LOW(MyTable*2) ; load the Table address to Z (Low Byte) SUBI ZL, $01 rjmp EndStart EndStart: ret 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Accessing Program Memory III Use then LPM to bring the contains of Z to r0 : ADIW ZL, 01 ; point to the table address LPM ; bring the low byte to r0 MOV r24, r0 ; move the result to register 24 ADIW ZL, 01 ; now increment the address by one ;to get the high byte LPM ;bring high byte to r0 MOV r25, r0 ; put it in register 25 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552

Tim Sumner, Imperial College, Rm: 1009, x47552 Exercise Write a program that puts the contents of a table into program memory and then reads the contents back sequentially and outputs them to PORTB. Use subroutines to organize your program. Use delays to see the different patterns flashing as they light the LEDS of PORTB. 12/8/2018 Tim Sumner, Imperial College, Rm: 1009, x47552