AVR ATmega128 microcontroller

Slides:



Advertisements
Similar presentations
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Advertisements

8051 Core Specification.
COMP3221: Microprocessors and Embedded Systems Lecture 16: Interrupts II Lecturer: Hui Wu Session 2, 2005.
Mark Neil - Microprocessor Course 1 Timers and Interrupts.
CSC Timers Since this is a microcontroller it mainly finds itself in embedded devices Quite often embedded devices need to synchronize events The.
COMP3221: Microprocessors and Embedded Systems--Lecture 8 1 COMP3221: Microprocessors and Embedded Systems Lecture 8: Program Control Instructions
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
COMP3221: Microprocessors and Embedded Systems--Lecture 9 1 COMP3221: Microprocessors and Embedded Systems Lecture 9: Data Transfer Instructions
Rabel Talpur:12BME#025.  40-pin chip  Developed by Motorola in 1975  16 address lines and 8 data lines  Used only +5V.
Atmega32 Architectural Overview
Writing an Assembly-language program Atmel assembly language CS-280 Dr. Mark L. Hornick 1.
AVR Microcontrollers.
Embedded Systems 7763B Mt Druitt College of TAFE
AVR ATmega128 microcontroller
A Simple Tour of the MSP430. Light LEDs in C LEDs can be connected in two standard ways. Active high circuit, the LED illuminates if the pin is driven.
Introduction to AVR Chapter 1
AVR Programming: Interrupts September 17, What are interrupts? An asynchronous signal indicating the need for an event to be handled A synchronous.
1 © Unitec New Zealand Interrupt Lecture 6 Date: - 20 Sept, 2011 Embedded Hardware ETEC 6416.
Timers and Interrupts Mark Neil - Microprocessor Course.
ECE 447 Fall 2009 Lecture 4: TI MSP430 Architecture and Instruction Set.
COMP3221: Microprocessors and Embedded Systems--Lecture 10 1 COMP3221: Microprocessors and Embedded Systems Lecture 10: Shift and Bit-set Instructions.
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
BRANCHES SUBROUTINES AND MEMORY USAGE AVR Assembler M. Neil - Microprocessor Course 1.
Mark Neil - Microprocessor Course 1 Timers and Interrupts.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
The AVR microcontroller
AVR Architecture Prepared By: Avdhesh Soni ( ) Sarthak Patel ( ) Akshay Parekh ( ) Fenil Sachla ( ) Guided.
Modified Harvard architecture 8-bit RISC single chip microcontroller Complete System-on-a-chip On Board Memory (FLASH, SRAM & EEPROM) On Board Peripherals.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
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
Seminar On 8085 microprocessor
Embedded Systems Programming
COMP2121: Microprocessors and Interfacing
Introduction to Smart Systems
Embedded Systems Programming Examples and Comparison
Atmega32 Architectural Overview
C. K. Pithawalla College of Engineering and Technology, Surat
Microprocessor and Assembly Language
Overview of Architecture Assembly Programming Concepts
Assembly Language Programming of 8085
The Stack.
MCI PPT AVR MICROCONTROLLER Mayuri Patel EC-1 5th sem
3.Instruction Set of 8085 Consists of 74 operation codes, e.g. MOV
BITS EDU. CAMPUS , VARNAMA
ECE 3430 – Intro to Microcomputer Systems
Interrupts In 8085 and 8086.
COMP2121: Microprocessors and Interfacing
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
COMP2121: Microprocessors and Interfacing
Data Processing Instructions
The Arduino Microcontroller: Atmel AVR Atmega 328
Timer/Counter Modified from Dr. Lam Phung’s Slides.
ATmega103 Timer0 and Interrupts
Assembly Programming using MIPS R3000 CPU
Introduction to Assembly Chapter 2
Tim Sumner, Imperial College, Rm: 1009, x47552
Chapter 8 Central Processing Unit
Microprocessors And Microcontrollers
Addressing Modes Register Direct, with 1 and 2 registers I/O Direct
Tim Sumner, Imperial College, Rm: 1009, x47552
COMP3221: Microprocessors and Embedded Systems
Introduction to Assembly Chapter 2
Assembly Programming using MIPS R3000 CPU
COMP3221: Microprocessors and Embedded Systems
Chapter 6 Programming the basic computer
COMP3221: Microprocessors and Embedded Systems
Computer Operation 6/22/2019.
Embedded Systems- Instruct set
Embedded Systems- Micro-controller
Presentation transcript:

AVR ATmega128 microcontroller By: Patel Shirali Mahida Kiran

Topics ATmega128 hardware Assembly Specialties Development tools I/O ports Interrupts Timing Development tools

CPU: Memory: ATmega128 hardware 8 bit, 16 MHz 133 RISC instructions Typically 1 clk/instruction (except branch) Memory: 128K Flash (program) 4K EEPROM + 4K internal SRAM (data) 32 register (16 upper special, 3 register pairs) Harvard-architecture

AVR block diagram Harvard-architektúra

Development tool: AVRStudio ATmega128 programming AVR: Atmel RISC processor family, ATmega128: AVR processor 128K flash memory („Advanced Virtual RISC”) Development tool: AVRStudio Assembly és C language (AVR-GCC, WinAVR) Programming (ISP, In System Programming) and debug (JTAG-ICE, In Circuit Emulation) Simulation environment (mikrocontroller + integrated peripherals)

AVRStudio IDE (IDE: Integrated Development Environment)

Topics ATmega128 hardware Assembly Specialties Development tools I/O ports Interrupts Timing Development tools

Compiling C code Preprocessor C source (makros (#define; #include…) gcc –E prog.c Compiler Assembly code (architecture dependant, optimized) gcc –S prog.c Assembler Object code Libraries Linker Executable (.com, .exe, ELF…)

Assembly introduction Low-level programming language Architecture dependant (pl. x86, PPC, AVR…) Between C and machine code – compact, Application: mainly small embedded systems (pl. PIC, AVR) For large projects: asm is expensive, inflexible, hard to manage; C compilers are well-optimized Low-level routines Computations intensive tasks (mathematics, graphics) reverse engineering

AVR assembly - registers RISC instruction set, load/store architecture: Registers: 32, 8 bit wide (r0…r31) All operations are done through registers Last six serves as register pairs Implement 3 16 bit registers (X, Y, Z)

AVR assembly – special registers Stastus register (SREG) - flags Carry, Zero, Global Interrupt Enable/Disable… Some instructions set the flags (e.g. arithmetic), other allow branching based on flag value mapped to I/O address space, therefore should be save in the IT routine: PUSH temp PUSH SREG helyett IN temp, SREG TODO: interruptrutin miatti mentés

AVR assembly – special registers Stack pointer To store return address of subroutines, or save/restore variables (push, pop) Grows from higher to lower addrress 2 byte register Stack stored in the data SRAM FILO Program Counter Address of the actual instruction During CALL or IT it is save to the heap; RET/RETI loads from heap at the end of a subroutine/IT routine ldi temp, LOW(RAMEND) out SPL, temp ldi temp, HIGH(RAMEND) out SPH, temp

AVR assembly - instructions mnemonic arguments (operands) ldi temp, 0xA5 ; 10100101 out PORTC, temp ; port write comment !!!!!

AVR assembly - instructions arguments ldi temp, 0xA5 ; 10100101 out PORTC, temp ; port write SREG

AVR assembly – instr. types Arithmetic and logic Branch, jump Data movement Bit manipulation, bit test TODO: ellenőrizni hogy helyes-e a felosztás

AVR assembly – instructions Arithmetic and logic Move Bit op., others reg1=reg2 MOV reg=17 LDI reg=mem LDS reg=*mem LD mem=reg STS *mem=reg ST periperal IN peripheral OUT heap PUSH POP … a+b ADD a-b SUB a&b AND a|b OR a++ INC a-- DEC -a NEG a=0 CLR … a<<1 LSL a>>1 LSR, Ø C (not avail. In C) ROL, ROR Status bits SEI, CLI, CLZ... No op. NOP …

AVR assembly - jumps JMP: unconditional jump E.g. forever loop: CALL, RET: subroutine call, return (HEAP) RETI: return from IT Subroutine: Construct in C: M_LOOP: …instructions… jmp M_LOOP while (1) { ...instructions... } M_LOOP: … CALL FV FV:…instructions… RET void fv() { …instructions… return; } void main () {… fv();

AVR assembly – conditional jump Equality test CPSE (compare, skip if equal) skips the next instruction (L2) if the two opernads are equal, otherwise executed normally (L1). Easy to mess up - DRAW A FLOWCHART! M_LOOP: ; compare, CPSE a, b ; skip if eq. JMP L2 L1:… ; a == b JMP M_LOOP L2:… ; a != b if (a==b) { (L1) } else { (L2) }

Note: BREQ can only jump 64 bytes! AVR assembly – branch switch / case M_LOOP: .. CP ch, 65 ; compare->ZeroF BREQ L1 ; branch if eq. CP ch, 66 BREQ L2 ... JMP VEGE L1:… L2:… (JMP VEGE) VEGE: ... switch (ch) { case 'A': (L1) break; case 'B': (L2) } (VEGE) Note: BREQ can only jump 64 bytes!

AVR assembly – „for” Long „for” cycle (more than 1 byte): LDI temp0, 0x20 ; LSW LDI temp1, 0x4E ; MSW LOOP: ... DEC temp0 BRNE LOOP ; branch if !=0 DEC temp1 BRNE LOOP for (int a=0; i<0x4e20; i++) { // == 20000 }; Using 2 byte instructions is also possible (SBIW vagy ADIW).

AVR assembly – directives .include "m128def.inc" ATmega128 registers and bit specification file .def temp = r16 register r16 renamed to temp .equ tconst = 100 Defining a constant value .org $0046 defining the memory adress of the next instruction M_LOOP: Label (e.g. for jumps)

Topics ATmega128 hardware Assembly Specialties Development tools I/O ports Interrupts Timing Development tools

I/O ports 3 I/O registers per port, bitwise configuration DDRx: direction (1: out, 0: in) PORTx: DDR=out: output data DDR=in: pullup resistor or floating PINx: actual value of the PIN! DDR=out: DDRx (with 1 clk latency) DDR=in: input data IN, OUT instructions for I/O addresses, LDS, STSfor memory mapped (PORTG)

I/O ports DDRx PORTx PINx direction DDRx value Output value / pullup PORTx value PINx (out/) input value

Writing output data (e.g. LEDs): I/O ports Writing output data (e.g. LEDs): ldi temp, 0xff ; 8 bit output out DDRC, temp out PORTC, temp ; turn on all LEDs Reading data (PORTG, e.g. switch): ldi temp, 0xFF sts PORTG, temp ; non tri-state ldi temp, 0x00 ; input sts DDRG, temp ; lds temp, PING ; read PIN SW0 PG0 SW1 PG1 SW2 PG4 SW3 L H

Interrupts Single-level IT Incoming IT clears the IT enable bit, RETI re-enables it – DO NOT do these in your IT routine! IT vector table Enable the different interrupt sources Enable global interrupt: SEI In the IT routine: Save the status register Save all used registers Do the IT routine Restore the saved registers Restore status register

IT vector table jmp TIMER_IT; Timer0 Compare Match Handler .org $0000 ; Define start of Code segment jmp RESET ; Reset Handler, jmp is 2 word instruction reti ; INT0 Handler on $0002, dummy nop reti ; INT1 Handler, if INTn used, 'reti' and 'nop' ; will be replaced by 'jmp INTn_Handler_Address' reti ; INT2 Handler ... reti ; Timer1 Compare Match B Handler reti ; Timer1 Overflow Handler reti reti ; Timer0 Overflow Handler .org $0046 ; MAIN program... jmp TIMER_IT; Timer0 Compare Match Handler

IT routine TIMER_IT: ; save status register and temp register into heap push temp in temp, SREG <...IT-handling...> ; restore temp and then status pop temp out SREG, temp reti ; return

Timing Using timer IT Without IT: Prescaler for less-frequent IT „For loop” – delay loop Polling timer counter (peripheral) Easy to debug, realize Imprecise, occupies all CPU time Using timer IT Prescaler for less-frequent IT Enable timer IT SW counter is required for large delays

Timing with IT ; ***** Timer 0 init ***** ; prescaler ldi temp,0b00001111 ; 0....... ; FOC=0 ; .0..1... ; WGM=10 (clear timer on compare match) ; ..00.... ; COM=00 (output disable) ; .....111 ; CS0=111 (CLK/1024) out TCCR0,temp ; Timer 0 TCCR0 register ; compare register ldi temp,108 ; 11059200Hz/1024 = 108*100 out OCR0,temp ; Timer 0 OCR0 register ; Timer 0 IT enabled, others disabled ldi temp,0b00000010 ; 000000.. ; Timer2,1 IT disabled ; ......1. ; OCIE0=1 - match ; .......0 ; TOIE0=0 - overflow out TIMSK,temp ; Timer IT Mask register sei ; global IT enabled