ATmega 2560 Datasheet Main features are listed

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

Dr. Rabie A. Ramadan Al-Azhar University Lecture 3
Computer Organization and Architecture
Processor System Architecture
9.0 EMBEDDED SOFTWARE DEVELOPMENT TOOLS 9.1 Introduction Application programs are typically developed, compiled, and run on host system Embedded programs.
General information Course web page: html Office hours:- Prof. Eyal.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
Assembly Language for Intel-Based Computers Chapter 2: IA-32 Processor Architecture Kip Irvine.
Chapter 4 Processor Technology and Architecture. Chapter goals Describe CPU instruction and execution cycles Explain how primitive CPU instructions are.
Recap – Our First Computer WR System Bus 8 ALU Carry output A B S C OUT F 8 8 To registers’ input/output and clock inputs Sequence of control signal combinations.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Software Development and Software Loading in Embedded Systems.
CEG 320/520: Computer Organization and Assembly Language Programming1 CEG 320/520 Computer Organization and Assembly Language Programming.
 C is general-purpose structured programming language or high level language.  It was developed by Dennis Ritchie in 1970s at Bell laboratories. 
Atmega32 Architectural Overview
System Calls 1.
Machine Instruction Characteristics
MICROPROCESSOR INPUT/OUTPUT
Programmer's view on Computer Architecture by Istvan Haller.
Computer Systems Organization CS 1428 Foundations of Computer Science.
Fall 2012 Chapter 2: x86 Processor Architecture. Irvine, Kip R. Assembly Language for x86 Processors 6/e, Chapter Overview General Concepts IA-32.
Languages and the Machine Chapter 5 CS221. Topics The Compilation Process The Assembly Process Linking and Loading Macros We will skip –Case Study: Extensions.
Topic 2d High-Level languages and Systems Software
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Computer Architecture Lecture 2 System Buses. Program Concept Hardwired systems are inflexible General purpose hardware can do different tasks, given.
Execution of an instruction
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
Slides created by: Professor Ian G. Harris Typical Embedded C Program #include main() { // initialization code while (1) { // main code }  #include is.
ECEG-3202 Computer Architecture and Organization Chapter 3 Top Level View of Computer Function and Interconnection.
Overview of Super-Harvard Architecture (SHARC) Daniel GlickDaniel Glick – May 15, 2002 for V (Dewar)
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Slides created by: Professor Ian G. Harris Hello World #include main() { printf(“Hello, world.\n”); }  #include is a compiler directive to include (concatenate)
80386DX functional Block Diagram PIN Description Register set Flags Physical address space Data types.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Microcontrollers, Microcomputers, and Microprocessors
Computer Architecture Lecture 4 by Engineer A. Lecturer Aymen Hasan AlAwady 17/11/2013 University of Kufa - Informatics Center for Research and Rehabilitation.
بسم الله الرحمن الرحيم MEMORY AND I/O.
MICROPROCESSOR DETAILS 1 Updated April 2011 ©Paul R. Godin prgodin gmail.com.
The 8085 Microprocessor Architecture. What 8085 meant for? 80 - year of invention bit processor 5 - uses +5V for power.
1 Basic Processor Architecture. 2 Building Blocks of Processor Systems CPU.
Chapter Microcontroller
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
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.
Operating Systems A Biswas, Dept. of Information Technology.
Lecture 3 Translation.
Embedded Systems Programming
Basic Computer Organization and Design
PROGRAMMABLE LOGIC CONTROLLERS SINGLE CHIP COMPUTER
AVR ATMEGA 8 MICRO-CONTROLLER
Control Unit Lecture 6.
System Programming and administration
An Embedded Software Primer
The Arduino Microcontroller: Atmel AVR Atmega 328
Variable Names Names are a sequence of visible characters
Introduction to Microprocessors and Microcontrollers
Memories.
Chapter 14 - Advanced C Topics
Computer Architecture Assembly Language
Computer Operation 6/22/2019.
SPL – PS1 Introduction to C++.
Chapter 10 Instruction Sets: Characteristics and Functions
Presentation transcript:

ATmega 2560 Datasheet Main features are listed Multiple similar parts described in one datasheet Slides created by: Professor Ian G. Harris

ATmega 2560 Pins Fixed-Use pins VCC, GND, RESET XTAL1, XTAL2 - input/output for crystal oscillator AVCC - power for ADC, connect to VCC AREF - analog reference pin for ADC General-Purpose ports Ports A-E, G, H, J, L Ports F and K are for analog inputs All ports are 8-bits, except G (6 bits) Slides created by: Professor Ian G. Harris

ATmega 2560 Pin Positions Pin positions are always in the datasheet Many pins have multiple functions/names Slides created by: Professor Ian G. Harris

IC Packages Package determines IC dimensions, pin size/spacing Thin quad flat pack (TQFP) Ceramic ball grid array (CBGA) Package determines IC dimensions, pin size/spacing Surface mount packages are very small ICs are often available in multiple packages Slides created by: Professor Ian G. Harris

ATmega 2560 Architecture Shows connectivity between peripherals, memory, I/O, bus CPU core is in the center, executes instructions Slides created by: Professor Ian G. Harris

Pin Descriptions Function of each pin is described Descriptions are brief, assuming an understanding of the part Almost all pins can be accessed on the STK 600 Slides created by: Professor Ian G. Harris

AVR CPU Core Common CPU for all AVR parts Ex. add $r1, $r2, $r3 Read instruction from program memory Load instr. into instr. Register Get source register numbers from instruction Fetch source data from register file Pass sources to ALU, add Pass result to register file Slides created by: Professor Ian G. Harris

AVR Status Register Records “interesting events” which must be handled Sign bit, carry flag, overflow flag, negative flag, zero flag, etc. May be used as branch conditions or to trigger interrupts Slides created by: Professor Ian G. Harris

General Purpose Registers 32 8-bit registers Used by the compiler X, Y, and Z registers are 16-bits long XH, XL, etc. Used to address memory (64K) Slides created by: Professor Ian G. Harris

Instruction Execution Timing Two-stage pipeline, fetch, and execute Register fetch, execute, and write back, all in one clock cycle Slides created by: Professor Ian G. Harris

SRAM Organization 64K addressable memory Registers mapped to beginning addresses Internal SRAM mapped in the middle External SRAM mapped at the end Slides created by: Professor Ian G. Harris

I/O Pins, Output Path DDRx PORTx Slides created by: Professor Ian G. Harris

I/O Pins, Input Path PINx Slides created by: Professor Ian G. Harris

I/O Control Registers DDRx – Controls the output tristate for port x DDRx bit = 1 makes the port x an output pin DDRx bit = 0 makes the port x an input pin Ex. DDRA = 0b11001100, outputs are bits 7, 6, 3, and 2 PORTx – Control the value driven on port x Only meaningful if port x is an output Ex. PORTA = 0b00110011 assigns pin values as shown PINx – Contains value on port x Ex. Q = PINC; Slides created by: Professor Ian G. Harris

Typical Embedded C Program #include <stdio.h> main() { // initialization code while (1) { // main code } #include is a compiler directive to include (concatenate) another file main is the function where execution starts Slides created by: Professor Ian G. Harris

C Syntax Basics Comments: single line //, multiline /* … */ Semicolon used to terminate all statements # indicates a compiler directive (include, define, etc.) Brackets { … } group lines of code for execution Blankspace between lines is not important in C Still need to separate tokens int a, b, c; a = b + c; int a,b,c;a=b+c; inta,b,c;a=b+c; correct correct incorrect (inta) Slides created by: Professor Ian G. Harris

Variables All variables’ types must be declared Memory space requirements known statically Type checking can be performed at compile-time Numerical Types: int, float, double Other types: char, void Type qualifiers: short, long, unsigned, signed, const Specify alternate sizes, constrain use modes Slides created by: Professor Ian G. Harris

Variable Declaration Static allocation vs. Dynamic allocation Static dedicates fixed space on the stack int i; Dynamic (malloc) allocates from the heap at runtime ptr = malloc(32); Type sizes depend on the architecture On x86, int is 32 bits On ATmega2560, int is 16 bits char is always 8 bits Slides created by: Professor Ian G. Harris

Volatile Variables The value of a volatile variable may change at any time, not just at an explicit assignment Also, may be read at any time Compiler optimizations are not applied to volatile variables for (i=0; i<10000; i++); An optimizing compiler would delete this loop i is not used anywhere in the code i = 1; … i = 1; If i is not modified in between, the second assignment is removed Slides created by: Professor Ian G. Harris

Volatile Variables When can variables be used without an explicit assignment? 1. Memory-mapped peripheral registers 2. Global variables modified by an interrupt service routine 3. Global variables accessed by other processors Slides created by: Professor Ian G. Harris

Volatile Example periph is the mapped address of the peripheral status info *periph is assigned by peripheral directly . while (*periph != 1); // wait until data transfer . // is complete Compiled code will move memory contents to a register Memory will only be moved once because *periph does not change Slides created by: Professor Ian G. Harris

Base Representation Base 10 is default Base can be specified with a prefix before the number Binary is 0b, Hexadecimal is 0x Ex. char x = 0b00110011; char x = 0x33; Binary is useful to show each bit value Hex is compact and easy to convert to binary 1 hex digit = 4 binary digits Slides created by: Professor Ian G. Harris

Types of Statements Assignment – = Relational - <, >, ==, != Control Flow – if, for, while, do, switch Arithmetic Operations - +, -, *, /, % Logical Operations - &&, ||, ! Bitwise Logical Operations - &, |, ^ Slides created by: Professor Ian G. Harris

Logical Operators These operators accept binary input and produce binary output &&, ||, ! Non-binary inputs are cast to binary values int a=1, b=0; c=56; d=-1, res; res = a && b; // res = 0 res = a || b; // res = 1 res = c && d; // res = 1 Slides created by: Professor Ian G. Harris

Bitwise Operations Treat the value as an array of bits Bitwise operations are performed on pairs of corresponding bits X = 0b0011, Y = 0b0110 Z = X | Y = 0b0111 Z = X & Y = 0b0001 Z = X ^ Y = 0b0101 Z = ~X = 0b1100 Z = X << 1 = 0b0110 Z = x >> 1 = 0b0001 Slides created by: Professor Ian G. Harris

Bit Masks Need to access a subset of the bits in a variable Write or read Masks are bit sequences which identify the important bits with a ‘1’ value Ex. Set bits 2 and 4 in X, don’t change other bits X = 01010101, mask = 0010100 X = X | mask Ex. Clear bits 2 and 4 mask = 11101011 X = X & mask Slides created by: Professor Ian G. Harris

Bit Assignment Macros #define SET_BIT(p,n) ((p) |= (1 << (n))) #define CLR_BIT(p,n) ((p) &= (~(1) << (n))) 1 << (n) and ~(1) << (n) create the mask Single 1 (0) shifted n times Macro doesn’t require memory access (on stack) Slides created by: Professor Ian G. Harris

Header Files Files included at the top of a code file Traditionally named with .h suffix Include information to be shared between files Function prototypes externs of global variables Global #defines Needed to refer to libraries Slides created by: Professor Ian G. Harris

Function Calls Functions enable simple code reuse Control moves to function, returns on completion Functions return only 1 value main() { int x; x = foo( 3, 4); printf(“%i\n”, x); } int foo(int x, int y) { return (x+y*3); } Slides created by: Professor Ian G. Harris

Function Call Overhead Program counter value needs to be restored after call Local variables are stored on the stack Function calls place arguments and return address on the stack main() { int x; x = foo(2); printf(“%i\n”, x); } 20: 21: 22: 103: 3 local var 102: 2 argument 101: 21 return addr 100: int foo(int x) { int y=3; return (x+y*3); } 30: 31: Slides created by: Professor Ian G. Harris

Embedded Toolchain A toolchain is the set of software tools which allow a program to run on an embedded system Host machine is the machine running the toolchain Target machine is the embedded system where the program will execute Host has more computational power then target We are using the GNU toolchain Free, open source, many features Slides created by: Professor Ian G. Harris

Cross-Compiler A compiler which generates code for a platform different from the one it executes on Executes on host, generates code for target Generates an object file (.o) Contains machine instructions References are virtual Absolute addresses are not yet available Labels are used instead Slides created by: Professor Ian G. Harris

Cross-Compiler Example ABBOTT.c int idunno; … whosonfirst(idunno) COSTELLO.c int whosonfirst(int x) { … } Cross- compiler Cross- compiler ABBOTT.o … MOVE R1, (idunno) CALL whosonfirst COSTELLO.o … whosonfirst: Idunno, whosonfirst Unknown addresses Slides created by: Professor Ian G. Harris

Linker Combines multiple object files References are relative to the start of the executable Executable is relocatable Typically need an operating system to handle relocation Slides created by: Professor Ian G. Harris

Linker Example Functions are merged Relative addresses used ABBOTT.o … MOVE R1, (idunno) CALL whosonfirst COSTELLO.o whosonfirst: MOVE R5, R1 HAHA.exe MOVE R1, 2388 CALL 1547 (value of idunno) 1547 2388 Linker Functions are merged Relative addresses used Slides created by: Professor Ian G. Harris

Linker/Locator Links executables and identifies absolute physical addresses on the target Locating obviates the need for an operating system Needs memory map information Select type of memory to be used (Flash, SRAM, …) Select location in memory to avoid important data (stack, etc.) Often provided manually Slides created by: Professor Ian G. Harris

Segments Data in an executable is typically divided into segments Type of memory is determined by the segment Instruction Segment - non-volatile storage Constant Strings – non-volatile storage Uninitialized Data – volatile storage Initialized Data – non-volatile and volatile Need to record initial values and allow for changes Slides created by: Professor Ian G. Harris

AVR GNU Toolchain Cross-Compiler: avr-gcc Linker/Locator: avr-ld Cross-Assembler: avr-as Programmer: avrdude All can be invoked via Atmel Studio 6 Slides created by: Professor Ian G. Harris

Controlling Pins int main (void) { DDRA = 0xFF; // Set pins to OUTPUT while (1) { PORTA = 0xFF; } Slides created by: Professor Ian G. Harris