Programming the ATmega16

Slides:



Advertisements
Similar presentations
AVR ATMega32 Elementary Input / Output
Advertisements

3-1 Peripherals & I/O lines All the on-chip peripherals are configured and controlled through Special Function Registers (SFR) Many of the SFR’s are bit.
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.
Microcontroller Fundamentals
EXTERNAL COMMUNICATIONS DESIGNING AN EXTERNAL 3 BYTE INTERFACE Mark Neil - Microprocessor Course 1 External Memory & I/O.
TK2633 Introduction to Parallel Data Interfacing DR MASRI AYOB.
Input/Output (I/O) Ports and Interfacing
Input/Output Ports and Interfacing ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
MICRO-CONTROLLER: A microcontroller is the brain of the robot: These are: 1. Integrated Circuits (ICs) 2. Programmable.
Programming Microcontrollers B. Furman 19MAR2011.
 | bit OR & bit AND ~ bit NOT ^ bit EXLUSIVE OR (XOR) > bit RIGHT SHIFT.
Mark Neil - Microprocessor Course 1 Decoding and Using a 4x4 Keyboard.
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.
Sensors And Micro-Controllers
Railway Foundation Electronic, Electrical and Processor Engineering.
Essentials of motors and motor driver
Digital I/O Connecting to the Outside World
Robotics Research Laboratory Louisiana State University.
Parallel Ports of PC Methods of interfacing Examples.
You must be knowing about Digital Integrated Circuits (ICs) right ? For example 7404: Hex Inverter 7408: Quad 2-input AND gate 7410: Triple 3-input NAND.
Introduction to Microcontrollers Shivendu Bhushan Summer Camp ‘13.
 C is general-purpose structured programming language or high level language.  It was developed by Dennis Ritchie in 1970s at Bell laboratories. 
Bit Masking To access or affect only the bits we want, we need to construct a byte with bits set in the locations of interest – This byte is called a ‘bit.
1 EKT 225 MICROCONTROLLER I CHAPTER 3 I/O PORT PROGRAMMING.
RC Filters B. Furman 02SEP2014. Mechatronics Concept Map System to Control Sensor Signal Conditioning Controller (Hardware & Software) Power Interface.
I/O Ports CS-280 Dr. Mark L. Hornick 1. CS-280 Dr. Mark L. Hornick 2 Ports are channels from the CPU to external hardware and software Atmega32 has: 4.
© AJH 2013, V2.0 Computer Programming Embedded Systems Programming Stand-alone code, system initialisation, operating systems. Low-level operations; port.
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.
Parallel Ports, Power Supply and the Clock Oscillator Material to be covered  Parallel I/O ports  Interfacing external switches and LEDs  Clock Oscillator.
Input/Output Ports and Interfacing
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
Teachers Name : Suman Sarker Telecommunication Technology Subject Name : Microcontroller & Embedded System Subject Code : 6871 Semester : 7th Department.
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
Robotics Research Laboratory Louisiana State University.
ECS642U Embedded Systems Digital I/O William Marsh.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
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.
Programmable Peripheral Interface Parallel port Interface 8255
Robotics Research Laboratory Louisiana State University.
Module 11 Adapted By and Prepared James Tan © 2001.
Department of Electronic & Electrical Engineering Lecture 2 ● Introduction to IO ● Using a subroutine ● Driving a 7seg display.
Arduino Mega Arduino Mega 2560 Arduino Mega 2560.
F28HS2 Hardware-Software Interface Lecture 6 - Programming in C 6.
Mark Neil - Microprocessor Course 1 Decoding and Using a 4x4 Keyboard.
Bit Manipulation in 'C' 'C' bit operators
Embedded Systems Lecture 4 January 20, 2016.
Introduction to AVR Name : 1) Abhishek Yadav ) Prakash Giri ) Kheni Niral ) Bhadresh Langadiya Branch.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
INTERFACING HARDWARE WITH MICROCONTROLLER GUIDED BY: Prof. ASIF SIR 1. AKSHAY KIRAN 2. DEEP PARIKH 3. JIGAR PATEL 4. TILAK PATEL ,05,D2D06,09.
Embedded Systems Programming (What they do and when / how to use them)
AVR I/O Port Programming
8255: Programmable Peripheral Interface (PPI)
Fundamentals of Computer Engineering
AVR ATMEGA 8 MICRO-CONTROLLER
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
General Purpose I/O.
COMP2121: Microprocessors and Interfacing
Overview Register Transfer Language Register Transfer
The Arduino Microcontroller: Atmel AVR Atmega 328
Interfacing Memory Interfacing.
I/O Ports in AVR Sepehr Naimi
I/O Ports in AVR Sepehr Naimi
Programmable Peripheral Interface
Decoding and Using a 4x4 Keyboard
CS 206D Computer Organization
Decoding and Using a 4x4 Keyboard
Presentation transcript:

Programming the ATmega16 B. Furman 14SEP2010

Mechatronics Concept Map User Interface ME 106 ME 120 Power Source Controller (Hardware & Software) ME 106 ME 190 ME 187 Power Interface ME 106 Signal Conditioning ME 106 ME 120 Actuator ME 106 ME 154 ME 157 ME 195 Sensor ME 120 ME 297A System to Control ME 110 ME 136 ME 154 ME 157 ME 182 ME 189 ME 195 BJ Furman 26JAN06

Audience participation required! Recap Last Lecture Audience participation required! Binary and hex numbers Digital pins as inputs or outputs Pins are bidirectional for digital I/O DDRx (x=A, B, C, or D) register determines direction 8-bit register a ‘1’ means a ‘0’ means main_RC.c Programmer’s block #include Initialization function, init(); DDRA, DDRB, and uart_init() 1 2 3 4 5 6 7 Ask students regarding what the ‘big ideas’ were for each of the bullet items. I mentioned that the lectures will highlight the important things to know in the class. Yes, try to read all the reading assignments.

Test Your Comprehension Write a statement that will make all pins of PORTC to be outputs DDRC = DDRC = 0b11111111; DDRC = 255; Write a statement that will make pins 5, 3, and 1 of PORTC to be outputs, and the rest inputs DDRC = 0b00101010; 0xFF;

Structure of main() Look again at main_RC.c init() printf_example() Declaration of variables char, string, uint8_t, uint16_t, uint32_t, double printf() format string while(1) Why? PORTB = PINA; Explain what is going on as a result of this statement

ATmega16 Port Pin Details See the ATmega 16 data sheet, p. 50 - 67 Port pins consist of three register (special memory location) bits: DDRx Data Direction bit in DDRx register (read/write) PORTxn PORTxn bit in PORTx data register (read/write) PINxn PINxn bit in PINx register (read only)

PORT Pin Schematic

ATmega16 Internal Architecture http://www.atmel.com/dyn/resources/prod_documents/doc2466.pdf

ATmega16 Features http://www.atmel.com/dyn/resources/prod_documents/doc2467.pdf

Make bits 5 and 3 of PORTB high and the rest low Bit Manipulations Examples of how to work with Port pins Setting bits Clearing bits Toggling bits Make bits 5 and 3 of PORTB high and the rest low Challenge: Work up the example on the board, so you can sketch out the bit positions, and talk about the operators, such as left shift ( << ) and logical OR

Summary of Bit Manipulation Setting a bit (making it a ‘1’) Bitwise OR the PORTx register with the corresponding bit mask Ex. PORTB | = _BV(3); Clearing a bit (making it a ‘0’) Bitwise AND the PORTx register with the corresponding complemented bit mask Ex. PORTB & = ~( _BV(3) ); Toggling a bit (making it flip) Bitwise XOR the PORTx register with the corresponding bit mask Ex. PORTB ^ = _BV(3);

Pull-up Resistors Pins configured as INPUTS can be ‘pulled up’ to VTG Why is this useful? Puts an input pin in a known state (logic high) if no external influence has pulled it down (to logic low) Example of a switch connected between a pin and ground How is it done? When the pin is configured as an input, SET the corresponding bit in PORTxn Undone by clearing the bit

Recap ATmega16 Digital I/O Pins are bi-directional. Can configure as: Inputs – _______ determines the pin voltage Outputs – ______ determines the pin voltage Direction determined by bits in DDRx register Where x is A – D (and corresponds to all 8 pins associated with the port) If configured as output: Program can specify a pin to be high (VTG) or low (GND) by writing a corresponding 1 or 0 (respectively) to PORTx register Ex. To make Port C pins 7, 3, and 4 low, and the rest high PORTC=___________; (write in binary, then in hex)

Recap ATmega16 Digital I/O, cont. If pins configured as input, this means: External device can pull pin voltage high or low i.e. take up to VTG or take down to GND You can determine the state of the port pins by reading the PINx register Grabs all eight logic levels at the same time Ex. PORTA configured as inputs PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7 VTG unsigned char a_pins; a_pins=PINA; What is the content of a_pins: binary:__________ hex:_____

Recap ATmega16 Digital I/O, cont. If pins configured as input, cont.: Can turn pull-up resistors on or off by writing a 1 or 0 to corresponding pins in PORTx A pull-up resistor internally connects a pin to VTG to give it a defined state (logic high, i.e., 1) Ex. Write the code that will: Make Port A pins inputs Turn on pull-up resistors Read the voltages on the pins and store them in a variable, testA What is the value of testA in binary and hex? PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7 VTG

Reading PORTA Pins Example unsigned char testA; DDRA=0; testA=PINA; What is the content of testA? binary: 11111001 hex: F9 PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7 VTG