Introduction to Smart Systems

Slides:



Advertisements
Similar presentations
Accessing Atmega32 SRAM data memory
Advertisements

Week10 Boolean Instructions on the Boolean Instructions  Boolean (or Bit) addressable capability is unique to the 8051  Enables efficient handling.
Introduction to Micro-controllers Anurag Dwivedi.
MICRO-CONTROLLER: A microcontroller is the brain of the robot: These are: 1. Integrated Circuits (ICs) 2. Programmable.
The Little man computer
Lab6 – Debug Assembly Language Lab
68HC11 Polling and Interrupts
TK 2633 Microprocessor & Interfacing
COMP3221: Microprocessors and Embedded Systems--Lecture 8 1 COMP3221: Microprocessors and Embedded Systems Lecture 8: Program Control Instructions
ECE 353 WinAVR and C Debugging Tutorial By Adam Bailin ECE 353 Fall ‘06.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Room: Timbalan Pengarah Pusat Komputer Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 4: Introduction.
TK 2633 Microprocessor & Interfacing
Butterfly I/O Ports CS-212 Dick Steflik. I/O for our labs To get data into and out of our Butterfly its a little trickier than using printf and scanf.
Railway Foundation Electronic, Electrical and Processor Engineering.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Railway Foundation Electronic, Electrical and Processor Engineering.
Introduction to Microcontrollers Shivendu Bhushan Summer Camp ‘13.
Atmega32 Architectural Overview
Writing an Assembly-language program Atmel assembly language CS-280 Dr. Mark L. Hornick 1.
Embedded Systems 7763B Mt Druitt College of TAFE
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1.
CS-280 Dr. Mark L. Hornick 1 Calling subroutines in assembly And using the Stack.
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.
RM2D Let’s write our FIRST basic SPIN program!. The Labs that follow in this Module are designed to teach the following; Turn an LED on – assigning I/O.
Introduction to AVR Chapter 1
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
The 8051 Microcontroller and Embedded Systems
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
Discussion 2 STATE MACHINES AND AVR ASSEMBLY CMPE 311 / FALL 2015 DR. MOHSENIN & MR. SMITH GTAS: RUTHVIK KUKKAPALLI, AMEY KULKARNI UTAS: JASON KLIMEK,
BRANCHES SUBROUTINES AND MEMORY USAGE AVR Assembler M. Neil - Microprocessor Course 1.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Introduction Purpose  This training course demonstrates the Project Generator function.
Introduction to AVR Name : 1) Abhishek Yadav ) Prakash Giri ) Kheni Niral ) Bhadresh Langadiya Branch.
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.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
“ INSTRUCTIONS SET OF AVR MICROCONTROLLER ” SIGMA INSTITUTE OF ENGINEERING Prepared By: SR.NO NAME OF STUDENT ENROLLMENT 1 Abhishek Lakhara
EET 2261 Unit 6 The Stack; Subroutines
Embedded Systems Programming (What they do and when / how to use them)
The Little man computer
Embedded Systems Programming
Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values.
Programming and Debugging with the Dragon and JTAG
Lab 1: Using NIOS II processor for code execution on FPGA
Fundamentals of Computer Engineering
The first change to your project files that is needed is to change the device to the correct FPGA. This is done by going to the Assignments tab on the.
Embedded Systems Programming Examples and Comparison
Getting Started with ATMEL Studio 6
Atmega32 Architectural Overview
AVR ATMEGA 8 MICRO-CONTROLLER
Overview of Architecture Assembly Programming Concepts
UNIT – Microcontroller.
Microprocessor Systems Design I
COMP2121: Microprocessors and Interfacing
COMP2121: Microprocessors and Interfacing
Chapter 4 Addressing modes
An Introduction to Microprocessor Architecture using intel 8085 as a classic processor
Roller Coaster Design Project
ECET 330 Innovative Education--snaptutorial.com
I/O Ports in AVR Sepehr Naimi
Tim Sumner, Imperial College, Rm: 1009, x47552
COMP2121: Microprocessors and Interfacing
Tim Sumner, Imperial College, Rm: 1009, x47552
EECE.3170 Microprocessor Systems Design I
EET 2261 Unit 6 The Stack; Subroutines
COMP3221: Microprocessors and Embedded Systems
Some Assembly (Part 2) set.html.
Computer Operation 6/22/2019.
Presentation transcript:

Introduction to Smart Systems (COMP 1659) Introduction to AVR Instruction Set and the ATmega1281 microcontroller This tutorial illustrates the use of a small subset of AVR instructions and provides some example code to illustrate their use with the ATmega1281 microcontroller on the STK300 development board. There is also some guidance on the use of AVR Studio. Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

Compiler Directives .include Tells the compiler to substitute this line in the program with the content of the file specified. For example the file m1281def.inc contains useful definitions of registers and ports and memory address details such as the highest usable memory address, for the ATmega1281 Microcontroller. The include file "m1281def.inc“ is automatically included by Atmel Studio (it knows which microcontroller you are using because you select it when you set up the project). .def Allows the programmer to define a meaningful name for a register etc. .def CountRegister=r16 ;usage example .cseg Tells the compiler this is the code segment .cseg ;usage example .org Allows the programmer to specify where in the memory the code should be located (its ‘origin’). .org 0x0D0 ;usage example Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

AVR Instruction subset (1) This is a very basic subset, sufficient for the first laboratory exercise Ldi Load an ‘immediate’ value (a constant) into a specified register Example: ldi r16, 0x05 In Read an I/O port data value into a register Example: in r17, PINA Out Set a port output value, from the contents of a specified register Example: out PORTA, r18 Rjmp Jump to a specific location in the code defined by a label e.g. Main: Example: rjmp Main Rcall Call a subroutine Example: rcall DisplayPatternOnLEDs Ret Return from a subroutine Example: ret Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

AVR Instruction subset (2) Inc Increment the value in the named register Example: inc r17 Dec Decrement the value in the named register Example: dec r18 Com One’s Complement Example: com r19 Cp Compare a pair of registers. Sets all flags as appropriate Example: cp r17,r18 Sub Subtract without carry (Subc subtract with carry) Example: sub r19,r20 Brne Branch if not equal (i.e. if the Z flag is not set) Example: dec r19 ;This will set the Z flag if the value in r19 was 0x01 and is now 0x00 brne RepeatLoop ;branch to RepeatLoop only if Z flag is NOT set, otherwise continue Other branch instructions follow the same pattern, all make their branch / not branch decision based on either one or two of the flags, see the AVR instruction set documentation for details. 4 Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

Parallel Ports ATmega1281 has six 8-bit parallel I/O ports (A, B, C, D, E, F) and one 6-bit port (G). Each port can be configured for input or output and each bit can be controlled separately. There are three I/O registers for each port: Data Direction Register (DDRn) – sets direction of the port (0 = input, 1 = output) ldi r16, 0xFF out DDRA, r16 ;Usage example, set all port A pins as outputs PORTn – the port output register. When configured for output, the data value on the PORT appears on the port pins. When configured for input, a ‘1’ (‘0’) turns on (off) the corresponding pull-up resistor out PORTA, r17 ;Usage example, place value of register r17 onto port A PINn – the port input register in r18,PINA ;Usage example, read port A data value into register r18 Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

Standard definitions ATMEL provide a header/include file m1281def.inc which contains standard register and bit-level definitions for the ATmega1281 microprocessor. For example the three registers for Port A are accessed at I/O addresses 0x00 – 0x02. The header file provides the following definitions: .equ PORTA = 0x02 .equ DDRA = 0x01 .equ PINA = 0x00 So by using the header file, the programmer does not have to remember the address mapping of all of the I/O registers. Another very important definition is that of the highest available RAM location: .equ RAMEND = 0x21ff There is 8KB of general-purpose RAM plus 512 bytes of registers The registers start from address 0x0000 to 0x01ff (see port A example above) The general-purpose RAM starts from address 0x0200 to 0x21ff Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

Useful Code Snippets (1) Configuring a port for output (port A in this example) ldi temp, 0xFF ;All ‘1’s sets the direction of all bits to output out DDRA, temp ;Output the value to the port’s Data Direction Register Writing data to an output port ldi temp, 0x35 ;The value to be written to the port out PORTA, temp ;Output the value to the port pins Configuring a port for input (port A in this example) ldi temp, 0x00 ;All ‘0’s sets the direction of all bits to input Reading data in from a port in temp, PINA ;Read the value on port A into the temp register Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

Useful Code Snippets (2) A short delay (busy wait) Delay_Subroutine : Enter ;A label so we can refer to it (e.g. rjmp) ldi r31,0xFF ;Place the value 0xFF in register r31 delay_loop: dec r31 ;Decrement the value brne delay_loop ;If not yet 0, go round the loop again ret Exit The delay subroutine above has only a single loop, and as the processor runs at between 1Mhz and 16MHz, it only takes a very small fraction of a second to execute. The code can be used ‘in-line’ (instead of as a subroutine), by not including the parts shown in green. 8 Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

Useful Code Snippets (3) A longer delay can be achieved by nesting loops inside one another (a short delay is repeated a lot of times, making a larger delay) Longer_Delay_Subroutine: ldi r30,0xFF ; place the value 0xFF in register r30 outer_loop: ldi r31,0xFF ; place the value 0xFF in register r31 inner_loop: dec r31 ; decrement the value in register r31 brne inner_loop ; if not yet 0, go round inner loop again dec r30 ; decrement the value in register r30 brne outer_loop ; if not yet 0, go round outer loop again ret The delay subroutine above has two loops, the inside loop is the same as in the previous example. However, here it is repeated 255 times (0xFF). So this loop takes 255 times as long as the simpler delay example. More layers of loop nesting can be added to make even longer delays. 9 Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

Useful Code Snippets (4) A basic configuration skeleton (asm) .def TEMP=r16 // Map variable names onto registers .cseg // CODE segment .org 0x0000 // Interrupt Vectors base address rjmp INIT // Reset (and power-on reset) handler .org 0x0080 // Program Code base address INIT: ldi TEMP,0xFF // Set Stack Pointer to top of SRAM out SPL,TEMP ldi TEMP,0x21 out SPH,TEMP sei // Set Global Interrupt Enable ldi TEMP,0xFF // Set port B direction as output (connected to LEDs) out DDRB,TEMP out PORTB,TEMP // Ensure LEDs are initially off ldi TEMP,0x00 // Set portD direction as input (connected to switches) out DDRD,TEMP // Place additional one-off initialisation code here MAIN: // Place your main-loop code here rjmp MAIN // Repeat continuously (the 'main-loop' of the program) Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich 10

Working with Atmel Studio 6 (getting started) The AVR Studio development environment is available in the hardware lab (KW116) Login to the CMS Domain Start → Atmel → Atmel Studio 6 Once you have started Atmel Studio, you can either OPEN an existing project or create a NEW PROJECT To create a new assembly code project: 1 select NEW PROJECT 2 select project type = C or Assembler 3 fill in the project name and location details (click OK when done) 4 select ATmega1281 from the scroll list 5 click OK This will create a project for you and will automatically set the device type – this is important because based on this the assembler / compiler automatically includes the various definition files / headers for the specific microcontroller. 11 Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

Working with Atmel Studio (Build->Build) This example shows the ‘Switches And Lights’ Project loaded in Atmel Studio 6 The code has been built, and the results are shown in the Output window. Note that it reports ‘Build Succeeded’ – you must get to this stage before the code can be loaded onto the microcontroller. Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

Debugging with Atmel Studio 6 using the Dragon When you click on the Debug tab a selection box will appear to ask if you want to use the Dragon, or the simulator – select Dragon. Debugging is far superior to simulation: - When you are debugging you are actually running the code on the microcontroller. - You can step through the code one command at a time, or run it until it hits a pre-defined breakpoint. - You can see the values in registers, as well as actually see output on the real LEDs and see the input value from the actual switches. 13 Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

This is an alternative to using the Dragon. AVR-ISP (In-System Programmer) Setup This is an alternative to using the Dragon. Generally we shall use the Dragon, but the ISP is documented here for completeness. The ISP is a separate tool, not part of Atmel Studio 6, it is available from Start → Electronics 14 Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

AVR-ISP Auto-program options 15 Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

AVR-ISP After programming and successful verify – all bytes show green 16 Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

Simple Example Program ‘Switches and Lights’ Assembly version

Memory Image ‘Switches and Lights’ Assembly version Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

Simple Example Program ‘Switches and Lights’ Embedded ‘C’ version Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich

Memory Image ‘Switches and Lights’ Embedded ‘C’ version Introduction to Smart Systems Richard Anthony, Smart Systems Technologies, The University of Greenwich