Microprocessors And Microcontrollers (Practical) Semester : 4 th, 5 th (TL, ES) Course Code : ES256, ES313 By: Dr. Attiya Baqai Assistant Professor, Department of Electronics, MUET.
3 Introduction to Programming and AVR Microcontroller Semester : 4 th, 5 th (TL, ES) Course Code : ES256, ES313 By: Dr. Attiya Baqai Assistant Professor, Department of Electronics, MUET.
AVR s CPU PROGRAM ROM General Purpose Registers RAM EEPROM Timers Program Bus CPU Data Bus Data Bus address bus data bus control bus OSC Interrupt Unit Ports Other Peripherals I/O PINS
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 Available Microcontrollers
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.
Simulation: AVR Programming Tools 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 10-segment LED bargraph display LCD 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
Compile and Build Options Project Files Programming Window uc I/O Info Compilation Status I/O Status / value
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 LDI R17,0xFF OUT DDRB,R17 AGAIN: IN R0,PINC OUT PORTB,R0 JMP AGAIN ; making PORT C as input ; making PORT B as output ; Read continuously from PORT C ; & send it to PORT B
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
Thanks! Any questions?