microprocessors and microcontrollers (practical) · avr’s cpu pr ogr am r om os c ports timers...
TRANSCRIPT
Microprocessors And Microcontrollers (Practical)
By: Dr. Attiya Baqai
Semester : 4th , 5th (TL, ES) Assistant Professor,
Course Code : ES256 , ES313 Department of
Electronics, MUET.
Introduction to Programming and AVR Microcontroller
3
By: Dr. Attiya Baqai
Semester : 4th , 5th (TL, ES) Assistant Professor,
Course Code : ES256 , ES313 Department of
Electronics, MUET.
AVR’s CPU
PROGRAM
ROM
PortsOSC
Timers
Other
Peripherals
Program
BusData
Bus
RAM
I/O
PINS
EEPROM
Interrupt
Unit
General
Purpose
Registers
CPU
data busaddress bus
control busData
Bus
Available Microcontrollers
◉ Altera ◉ Analog Devices ◉ Atmel ◉ Cypress Semiconductor ◉ Dallas Semiconductor ◉ELAN Microelectronics Corp. ◉ Energy Micro ◉ EPSON Semiconductor ◉ Freescale Semiconductor ◉ Parallax ◉ NXP Semiconductors ◉ Texas Instruments
◉ Fujitsu ◉ Holtek ◉Infineon ◉Intel ◉Lattice Semiconductor ◉Maxim Integrated ◉Microchip Technology ◉National Semiconductor ◉NEC ◉Panasonic ◉Rabbit Semiconductor ◉Silicon Laboratories
ATMEGA 8 Microcontroller
◉ 8-bit Atmel with 8KB in-System Programmable Flash ◉32 × 8 General Purpose Working Registers ◉Up to 16MIPS Throughput at 16MHz ◉512 B EEPROM ◉1KB Internal SRAM ◉Two 8-bit Timer/Counters and One 16-bit Timer/Counter
◉Three PWM Channels ◉Two-wire Serial Interface ◉Programmable Serial USART ◉Master/Slave SPI Serial Interface ◉23 Programmable I/O Lines ◉0 - 8MHz (ATmega8L) ◉0 - 16MHz (ATmega8)
ATMEGA 16L Microcontroller
Programming Methods
◉In System Programming (ISP)
◉JTAG
◉DebugWire (dW)
◉Pre-programmed Bootloader
◉High Voltage Parallel Programming (HVPP)
◉High Voltage Serial Programming (HVSP)
◉Program and Debug Interface (PDI)
◉Tiny Programming Interface (TPI)
◉aWire (aW)
In Circuit System Programming (ICSP)
◉ In System Programming is perhaps the most common method of programming the Flash, EEPROM, fuse and lock bytes of the entire AVR line.
◉ ISP can program AVRs at extremely high clock rates (assuming the target AVR is running at a high frequency and the programmer supports it) and is the method of choice for almost all AVR hobbyists.
◉ There are many, many AVRISP clones and AVR910 programmers on the market in addition to simple do-it-yourself dongles which connect to your computer's parallel port.
◉Recent new dongle designs may use the computer's serial port, however anecdotal evidence has said that this method is *extremely* slow due to technical limitations.
◉ISP requires that the target AVR is running at a clock rate of at least four times that of the ISP clock.
AVR Programming Languages
◉ Programming Language for AVR is Assembly, however C language Compilers for AVRs are also available which convert C language program to Assembly or Machine (HEX) language.
AVR Programming Tools
◉ Simulation: Proteus Simulator v7.9 (Simulation)
AVR Studio 4.18 (Programming)
Win AVR (GCC Compiler)
◉Experiment: USBAsp Programmer
AVR Studio 4.18
Extreme Burner (for Programming through ICSP)
AVR Trainer or AVR ATMEGA 16 Chip
WinAVR
USBAsp Programmer Connection Diagram
ICSP Header
VCC
MOSI MISO
SCK
RST
GND
ATMEGA 16
AVR Microcontroller Trainer
AVR Microcontroller Trainer
LCD
10-segment LED
bargraph display
ICSP header
ATMEGA16
4 Switches
Power Socket
Introduction to AVR Studio 4
Select New Project
Atmel AVR Assembler for Assembly AVR GCC for C-language
Enter details and click NEXT
AVR Simulator > ATmega16
Programming Window Project Files
uC I/O Info
I/O
Status / value Compilation Status
Compile and Build Options
Input & Output Operations
◉ To initialize ports as Input / Output: DDRx = 0xFF; // Output
DDRx = 0x00; // Input
◉ Getting / Writing Data on Ports: PINx // for Input
PORTx // for Output
x is the Port name i.e. A, B, C etc
Program#01: Send Data on Port B
.INCLUDE "M16DEF.INC"
.ORG 0000
LDI R16,0xFF
OUT DDRB,R16 ; making PORT B as output
LDI R17, 0xF0 ; sending data “F0” to PORT B
OUT PORTB,R17
AGAIN: JMP AGAIN
Simulate & Debug Program in AVR Studio
.INCLUDE "M16DEF.INC"
.ORG 0000
LDI R16,0xFF
OUT DDRB,R16 ; making PORT B as output
LDI R17, 0xF0 ; sending data “F0” to PORT B
OUT PORTB,R17
AGAIN: JMP AGAIN
Proteus Output
Proteus Output
Browse Hex File from PC
Run Simulation
Program # 02: Get Data from Port C and Put it on Port B
.INCLUDE "M16DEF.INC"
.ORG 0000 LDI R16,00 OUT DDRC, R16 ; making PORT C as input LDI R17,0xFF OUT DDRB,R17 ; making PORT B as output AGAIN: IN R0,PINC ; Read continuously from PORT C OUT PORTB,R0 ; & send it to PORT B JMP AGAIN
Example # 02: Proteus
Example # 02: Proteus
Khazama AVR Programmer
Exercise Questions
◉ Get Data from Switches connected at Port C and Output complimented data to Port B
◉ Get data from lower nibble of Port C and put it to upper nibble of port B
◉ Count numbers from 0 to 255 on Port B
◉ Write a program to generate these random numbers: 100, 255, 123, 80, 66, 36, 15, 00
Acknowledgement
◉ Originally taken from Practical Lecture slides and handouts by Engr Azam Rafique Memon
◉ Modified by Dr. Attiya Baqai
Any questions ?
Thanks!