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.

Slides:



Advertisements
Similar presentations
Introduction to Micro-controllers Anurag Dwivedi.
Advertisements

Chung-Ta King National Tsing Hua University
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 3 – New instruction recap Tutorial.
Programming Microcontrollers B. Furman 19MAR2011.
68HC11 Polling and Interrupts
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.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Programming the ATmega16
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
Debug Techinques for HW/SW Systems What's broken, the HW or the SW? Some basic thoughts: -assume that its broken -its not working correctly until proven.
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.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Embedded Systems Interrupts C.-Z. Yang Sept.-Dec
Railway Foundation Electronic, Electrical and Processor Engineering.
An Embedded C Program 1 Mainly from textbook: Embedded C Programming and the Atmel AVR 2 nd Edition Barnett, Cox and O’Cull.
Introduction to Microcontrollers Shivendu Bhushan Summer Camp ‘13.
Embedded Systems Programming 1 ETEE 3285 Topic HW3: Coding, Compiling, Simulating.
COMP201 Computer Systems Exceptions and Interrupts.
Revised: Aug 1, ECE 263 Embedded System Design Lessons 23, 24 - Exceptions - Resets and Interrupts.
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
Chapter 8 I/O. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-2 I/O: Connecting to Outside World So far,
Robotics Research Laboratory Louisiana State University.
ECS642U Embedded Systems Digital I/O William Marsh.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM511.
Engineering Computing I Chapter 4 Functions and Program Structure.
Robotics Research Laboratory Louisiana State University.
AVR Programming: Interrupts September 17, What are interrupts? An asynchronous signal indicating the need for an event to be handled A synchronous.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
CSCI 171 Presentation 8 Built-in Functions, Preprocessor Directives, and Macros.
AVR Programming: Digital I/O September 10, What is Digital I/O? Digital – A 1 or 0 Input – Data (a voltage) that the microcontroller is reading.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
CE-2810 Dr. Mark L. Hornick 1 Mixing C and assembly Safety goggles on!
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM415.
Embedded Systems Lecture 4 January 20, 2016.
ARM Embedded Programming Lecture 4 Accessing Memory Mapped Registers.
Introduction to AVR Name : 1) Abhishek Yadav ) Prakash Giri ) Kheni Niral ) Bhadresh Langadiya Branch.
GUIDED BY PROFFESOR NILESH DESAI GROUP NO:-8 CHANDRASHIKHA SINGH( ) KURUP SHUBHAM VALSALAN( ) SAURAV SHUBHAM( )
Presentation By :- Nikhil R. Anande ( ) Electronic & Communication Engineering. 3 nd Year / 5 th Semester FACULTY GUIDE : RAHIUL PATEL SIR MICROCONTROLLER.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
Transmitter Interrupts Review of Receiver Interrupts How to Handle Transmitter Interrupts? Critical Regions Text: Tanenbaum
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Introduction to Smart Systems
Embedded Systems Programming Examples and Comparison
Microprocessor and Assembly Language
Chapter 8 I/O.
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
Chapter 8 Input/Output I/O basics Keyboard input Monitor output
Timer/Counter Modified from Dr. Lam Phung’s Slides.
The slides must be understood in Lecture 5
A Play Core Timer Interrupts
Interrupts in C Programs
Chapter 8 I/O.
Transmitter Interrupts
A Play Lab. 2 Task 8 Core Timer Interrupts
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Embedded System Development Lecture 7 2/21/2007
Chapter 8 I/O.
Blackfin BF533 EZ-KIT Control The O in I/O
COMP3221: Microprocessors and Embedded Systems
Week 2 - Friday CS222.
ECE 3567 Microcontrollers Lab
Presentation transcript:

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 as you did in CS211 Since the Butterfly doesn't have an Operating System we need to write and read data directly to/from the I/O ports Access to the ports is through the Special Function Registers (SFRs) that are defined symbolically in iom169.h which is included in your program by io.h

io.h # include #elif defined (__AVR_ATmega168__)‏ # include #elif defined (__AVR_ATmega168P__)‏ # include #elif defined (__AVR_ATmega169__)‏ # include #elif defined (__AVR_ATmega169P__)‏ # include #elif defined (__AVR_ATmega8HVA__)‏ # include #elif defined (__AVR_ATmega16HVA__)‏

iom169.h /* iom169.h - definitions for ATmega169 */ /* This should be up to date with data sheet version 2514J-AVR-12/03. */ #ifndef _AVR_IOM169_H_ #define _AVR_IOM169_H_ 1 /* This file should only be included from, never directly. */ #ifndef _AVR_IO_H_ # error "Include instead of this file." #endif #ifndef _AVR_IOXXX_H_ # define _AVR_IOXXX_H_ "iom169.h" #else # error "Attempt to include more than one file." #endif /* I/O registers */ /* Port A */ #define PINA _SFR_IO8(0x00)‏ #define DDRA _SFR_IO8(0x01)‏ #define PORTA _SFR_IO8(0x02)‏ /* Port B */ #define PINB _SFR_IO8(0x03)‏ #define DDRB _SFR_IO8(0x04)‏

sfr_defs.h included in every compile via io.h contains macro definitions for accessing Special Function Registers as if they were just c language variables in iom169.h the statement: #define PINA _SFR_IO8(0x00) the symbol PINA is mapped to the SFR at address 0x00 in SFR memory _SFR_IO8( ) is a macro (look in sfr_defs.h )‏

Why this is done in your program you #include io.h and io.h in turn includes iom169.h (because in your project definition you picked the ATmega169 as the processor)‏ pass 1 of the compiler does all includes and macro substitutions ( in our example with PINA all occurrences of the symbol PINA in your program will be replaced with a reference to SFR 0x00)‏ This makes all SFR references look like references to C variables

Memories

Getting Data Into and Out Of Initialize the ports  set the Data Direction Registers (DDRs)‏ use PORTB for input  use the 8 input DIP switch for inputting data don't forget the pull-up resistors use PORTD for showing output  use 8 LEDS don't forget the current limiting, series resistors

Design This warrants 3 subroutines  one to do initialization  one to do input  one to do output These should be written very general purpose as we will use them for many of the labs

daemons a daemon is a program that will sit in memory forever and run until the system loses power since most embedded system run forever (until they lose power) our main() should be written as a never ending loop. processing to be done can be done either in the body of the loop or asynchronously in response to an external or internal event (interrupt)‏

Interrupts How Interrupts are handled Somewhere in your program you define an Interrupt Servicing Subroutine, the compiler will put the address of this routine into the proper location in the interrupt vector (low memory)‏ When the interrupt occurs the system state is saved, a branch to the ISS is made via the interrupt vector The ISS executes and returns the state of the system and you are right where you were before the interrupt occurred

ATmega169 Interrupt Vector

What we want to do use 8 LEDs for output 8 switches for input 1 button to tell when it is OK to read the switches  to do this we should us an interrupt

The way it should work /* Interrupt handler */ { // disable interruptes // read the switches // save the data at the next location in an array // light the lights // enable interrupts } int main ()‏ { // initialize ports B & D // initial Port E for interrupt on PE2 // loop forever – this is our daemon }

volatile keyword the keyword “volatile” should be used to define any variable that may be modified inside of an interrupt handler “volatile” flags a variable to the optimizing compiler to not optimize variables with the “volatile” keyword volatile char switches = 0; volatile uint8_t flags = 0;

char & uint8_t Remember the char data type can be used for ASCII characters or a signed 8 bit integer The AVR header files define another data type that allows an unsigned 8 bit integer, this is convenient for working with gpio ports as they are not usually signed data.

internal pullups for gpio inputs on many MCUs you must add an external pullup resistor on gpio input lines Atmel MCUs have built-in internal pullup resistors  to use the internal pullups write a one to that line after it has been defined as an input line in the DDR // define Port B as all outputs and Port D as all inputs DDRB = 0xFF; DDRD = 0x00; //turn on the internal pullup resistors for Port D PORTD = 0xFF;

Setting up an interrupt handler Signal or ISR  the ISR macro has superceded the Signal macro and is the preferred way of setting up an interrupt handler ISR( name of the int from processor.h file)‏ { } ISR(SIG_PIN_CHANGE1)‏ {.... }

Pin Change Interrupts Input lines on Ports B and E can be set up to generate a pin change interrupt Each port has an associated mask register to enable an interrupt put a 1 into the correct position in the appropriate mask register Port B PCMSK1 Port E PCMSK0

PCINT Mapping PORT E PCINT77SIG_PIN_CHANGE0 PCINT66 PCINT55 PCINT44 PCINT33 PCINT22 PCINT11 PCINT00 PORT B PCINT157 SIG_PIN_CHANGE1 PCINT146 PCINT135 PCINT124 PCINT113 PCINT102 PCINT91 PCINT80

Example //set bit 2 of Port B to cause an interrupt PCMSK1 = 0x04; // set bit 2 of Port B to cause interrupt EIMSK = 0xC0; // Ext Int Mask Reg EIFR = 0xC0; // Ext Int Flag Reg DDRB & = 0xFB; // make bit 2 an input line PORTB | = 0x04; // turn on pullup ISR(SIG_PIN_CHANGE1)‏ { cli( ); // disable interrupts. sei( ); // enable interrupts }