SlideShare a Scribd company logo
1 of 2
Configuring the microcontroller before running it the first time:
Fuse bytes : high and low
Program them once before you start using the micro-controller
Disable JTAG to free up PORTC for normal use
Set the correct clock clock option
With the hardware set up, run in Command Prompt :
For 1MHz internal clock:
vrdude -c usbasp -P usb -p m16 -U hfuse:w:0xd9:m -U lfuse:w:0xe1:m
For 16MHz external crystal:
vrdude -c usbasp -P usb -p m16 -U hfuse:w:0xc9:m -U lfuse:w:0xef:m
Refer to datasheet sections on “System clock and clock options” and
“Memory programming” for other clock options and their settings.
Setting the wrong fuse values may render the uC unusable
Led Blink Code AVR Atmega16 Led Blink Code Hello World Led using atmega16 in C
Led Blink CodeCode AVR Atmega16
How We will Program it:
Blink an LED
- Choose a port and a pin
- In the code
1. Set pin direction to output
2. Set pin output to high
3. Wait for 250ms
4. Set pin output to low
5. Wait for 250ms
6. Go to 2
Relevant registers :
DDR – set pin data direction
PORT – set pin output
PIN – read pin input
Blink.C – Code in C Language:
#include <avr/io.h> // contains definitions for DDRB, PORTB
#include <util/delay.h> // contains the function _delay_ms()
int main(void)
{
DDRB = 0b11111111; // set all pins on PortB to output
while(1)
{
PORTB = 0b00000001; // Set PortB0 output high, others low
_delay_ms(250); // Do nothing for 250 ms
PORTB = 0b00000000; // Set all of them low
_delay_ms(250); // Do nothing for 250 ms
}
return 0;
}
/* DDRB is a 8-bit register which sets direction for each pin in PortB
PORTB decides output for output pins
0b – prefix for binary numbers, 0x – hex, no prefix – decimal
Thus, 15 = 0xf = 0b1111
*/
Compiling and Programming
- Save the code as blink.c in a separate folder (not strictly
necessary, just a good practice)
- Create a makefile using Mfile and save in the same folder
- Open it in Programmer’s Notepad and change:
◦ Line 44: MCU = atmega16
◦ Line 65: F_CPU = 1000000
◦ Line 73: TARGET = blink, Line 83: SRC = $(TARGET).c
◦ Alternatively, TARGET = anything_you_want and SRC =
blink.c
◦ Line 278: AVRDUDE_PROGRAMMER = usbasp
◦ Line 281: AVRDUDE_PORT = usb
- In Programmer’s Notepad, Tools > Make All to compile
- Connect USBasp to computer and ATmega16
- Tools > Program to program ATmega16

More Related Content

What's hot

microcontroller board ppt
microcontroller board pptmicrocontroller board ppt
microcontroller board pptshashank tiwari
 
Pic microcontrollers for_beginners
Pic microcontrollers for_beginnersPic microcontrollers for_beginners
Pic microcontrollers for_beginnersPraveen Chary
 
Introduction to MPLAB IDE
Introduction to MPLAB IDEIntroduction to MPLAB IDE
Introduction to MPLAB IDEKarim El-Rayes
 
PIC introduction + mapping
PIC introduction + mappingPIC introduction + mapping
PIC introduction + mappingOsaMa Hasan
 
8-bit PIC Microcontrollers
8-bit PIC Microcontrollers8-bit PIC Microcontrollers
8-bit PIC MicrocontrollersPremier Farnell
 
174085193 pic-prgm-manual
174085193 pic-prgm-manual174085193 pic-prgm-manual
174085193 pic-prgm-manualArun Shan
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollersCorrado Santoro
 
PIC18F2XK20/4XK20 8-Bit Microcontroller Family
PIC18F2XK20/4XK20 8-Bit Microcontroller FamilyPIC18F2XK20/4XK20 8-Bit Microcontroller Family
PIC18F2XK20/4XK20 8-Bit Microcontroller FamilyPremier Farnell
 
Using Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesUsing Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesCorrado Santoro
 
Interrupts at AVR
Interrupts at AVRInterrupts at AVR
Interrupts at AVRHamdy Fouad
 
Handling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsHandling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsCorrado Santoro
 
AVR_Course_Day6 external hardware interrupts and analogue to digital converter
AVR_Course_Day6 external hardware  interrupts and analogue to digital converterAVR_Course_Day6 external hardware  interrupts and analogue to digital converter
AVR_Course_Day6 external hardware interrupts and analogue to digital converterMohamed Ali
 
MCS51 Training board Model CATC2016A
MCS51 Training board Model CATC2016AMCS51 Training board Model CATC2016A
MCS51 Training board Model CATC2016AArkhom Jodtang
 
Microcontroller lec 2
Microcontroller  lec 2Microcontroller  lec 2
Microcontroller lec 2Ibrahim Reda
 
Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]gauravholani
 

What's hot (20)

microcontroller board ppt
microcontroller board pptmicrocontroller board ppt
microcontroller board ppt
 
Rig nitc [autosaved] (copy)
Rig nitc [autosaved] (copy)Rig nitc [autosaved] (copy)
Rig nitc [autosaved] (copy)
 
Micro
MicroMicro
Micro
 
Pic microcontrollers for_beginners
Pic microcontrollers for_beginnersPic microcontrollers for_beginners
Pic microcontrollers for_beginners
 
Introduction to MPLAB IDE
Introduction to MPLAB IDEIntroduction to MPLAB IDE
Introduction to MPLAB IDE
 
PIC introduction + mapping
PIC introduction + mappingPIC introduction + mapping
PIC introduction + mapping
 
8-bit PIC Microcontrollers
8-bit PIC Microcontrollers8-bit PIC Microcontrollers
8-bit PIC Microcontrollers
 
Intrerfacing i
Intrerfacing iIntrerfacing i
Intrerfacing i
 
174085193 pic-prgm-manual
174085193 pic-prgm-manual174085193 pic-prgm-manual
174085193 pic-prgm-manual
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollers
 
PIC18F2XK20/4XK20 8-Bit Microcontroller Family
PIC18F2XK20/4XK20 8-Bit Microcontroller FamilyPIC18F2XK20/4XK20 8-Bit Microcontroller Family
PIC18F2XK20/4XK20 8-Bit Microcontroller Family
 
Using Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesUsing Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR Libraries
 
Interrupts at AVR
Interrupts at AVRInterrupts at AVR
Interrupts at AVR
 
Handling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsHandling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUs
 
AVR_Course_Day6 external hardware interrupts and analogue to digital converter
AVR_Course_Day6 external hardware  interrupts and analogue to digital converterAVR_Course_Day6 external hardware  interrupts and analogue to digital converter
AVR_Course_Day6 external hardware interrupts and analogue to digital converter
 
MPLABX with proteus
MPLABX with proteusMPLABX with proteus
MPLABX with proteus
 
MCS51 Training board Model CATC2016A
MCS51 Training board Model CATC2016AMCS51 Training board Model CATC2016A
MCS51 Training board Model CATC2016A
 
Microcontroller lec 2
Microcontroller  lec 2Microcontroller  lec 2
Microcontroller lec 2
 
Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]
 

Viewers also liked

Viewers also liked (14)

Hoja de vida esteban dorado
Hoja de vida esteban doradoHoja de vida esteban dorado
Hoja de vida esteban dorado
 
Top 10 Anime
Top 10 AnimeTop 10 Anime
Top 10 Anime
 
Count Instead THIS Instead of Calories
Count Instead THIS Instead of Calories Count Instead THIS Instead of Calories
Count Instead THIS Instead of Calories
 
Artritis psoriásica
Artritis psoriásicaArtritis psoriásica
Artritis psoriásica
 
Thesis summary knowledge discovery from academic data using association rule...
Thesis summary  knowledge discovery from academic data using association rule...Thesis summary  knowledge discovery from academic data using association rule...
Thesis summary knowledge discovery from academic data using association rule...
 
Oficio
OficioOficio
Oficio
 
Lpc
LpcLpc
Lpc
 
AUTOBIOGRAFIA
AUTOBIOGRAFIAAUTOBIOGRAFIA
AUTOBIOGRAFIA
 
Convergencia tegnologica
Convergencia tegnologicaConvergencia tegnologica
Convergencia tegnologica
 
Publication
PublicationPublication
Publication
 
Evaluation question 2
Evaluation question 2Evaluation question 2
Evaluation question 2
 
SPinach Lab
SPinach LabSPinach Lab
SPinach Lab
 
Deeley Recommendation
Deeley RecommendationDeeley Recommendation
Deeley Recommendation
 
Rubrica 2
Rubrica 2Rubrica 2
Rubrica 2
 

Similar to Untitled 1

Microcontroller
MicrocontrollerMicrocontroller
MicrocontrollerSpitiq
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVRMohamed Abdallah
 
PIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikarPIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikarGauravRaikar3
 
Chp4 introduction to the pic microcontroller copy
Chp4 introduction to the pic microcontroller   copyChp4 introduction to the pic microcontroller   copy
Chp4 introduction to the pic microcontroller copymkazree
 
Introduction2_PIC.ppt
Introduction2_PIC.pptIntroduction2_PIC.ppt
Introduction2_PIC.pptAakashRawat35
 
Design and Development of a prototype of AGV
Design and Development of a prototype of AGVDesign and Development of a prototype of AGV
Design and Development of a prototype of AGVKUNJBIHARISINGH5
 
Xcs 234 microprocessors
Xcs 234 microprocessorsXcs 234 microprocessors
Xcs 234 microprocessorssweta suman
 
5. Features of the LPC214X Family.pptx
5. Features of the LPC214X Family.pptx5. Features of the LPC214X Family.pptx
5. Features of the LPC214X Family.pptxSivakumarG52
 
Python-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxPython-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxTuynLCh
 
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptxINDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptxMeghdeepSingh
 
Programming with PIC microcontroller
Programming with PIC microcontroller Programming with PIC microcontroller
Programming with PIC microcontroller Raghav Shetty
 
Microcontroladores: Programación con microcontrolador PIC
Microcontroladores: Programación con microcontrolador PICMicrocontroladores: Programación con microcontrolador PIC
Microcontroladores: Programación con microcontrolador PICSANTIAGO PABLO ALBERTO
 
Embedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debuggingEmbedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debuggingAnne Nicolas
 
Basics Of Embedded Systems
Basics Of Embedded SystemsBasics Of Embedded Systems
Basics Of Embedded Systemsarlabstech
 

Similar to Untitled 1 (20)

Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
 
Presentation
PresentationPresentation
Presentation
 
PIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikarPIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikar
 
Chp4 introduction to the pic microcontroller copy
Chp4 introduction to the pic microcontroller   copyChp4 introduction to the pic microcontroller   copy
Chp4 introduction to the pic microcontroller copy
 
Introduction2_PIC.ppt
Introduction2_PIC.pptIntroduction2_PIC.ppt
Introduction2_PIC.ppt
 
Design and Development of a prototype of AGV
Design and Development of a prototype of AGVDesign and Development of a prototype of AGV
Design and Development of a prototype of AGV
 
Picmico
PicmicoPicmico
Picmico
 
Xcs 234 microprocessors
Xcs 234 microprocessorsXcs 234 microprocessors
Xcs 234 microprocessors
 
Avr report
Avr reportAvr report
Avr report
 
5. Features of the LPC214X Family.pptx
5. Features of the LPC214X Family.pptx5. Features of the LPC214X Family.pptx
5. Features of the LPC214X Family.pptx
 
Python-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxPython-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptx
 
Introduction to PIC.pptx
Introduction to PIC.pptxIntroduction to PIC.pptx
Introduction to PIC.pptx
 
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptxINDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
 
digital clock atmega16
digital clock atmega16digital clock atmega16
digital clock atmega16
 
2 unit-es-printed
2 unit-es-printed2 unit-es-printed
2 unit-es-printed
 
Programming with PIC microcontroller
Programming with PIC microcontroller Programming with PIC microcontroller
Programming with PIC microcontroller
 
Microcontroladores: Programación con microcontrolador PIC
Microcontroladores: Programación con microcontrolador PICMicrocontroladores: Programación con microcontrolador PIC
Microcontroladores: Programación con microcontrolador PIC
 
Embedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debuggingEmbedded Recipes 2019 - Introduction to JTAG debugging
Embedded Recipes 2019 - Introduction to JTAG debugging
 
Basics Of Embedded Systems
Basics Of Embedded SystemsBasics Of Embedded Systems
Basics Of Embedded Systems
 

Untitled 1

  • 1. Configuring the microcontroller before running it the first time: Fuse bytes : high and low Program them once before you start using the micro-controller Disable JTAG to free up PORTC for normal use Set the correct clock clock option With the hardware set up, run in Command Prompt : For 1MHz internal clock: vrdude -c usbasp -P usb -p m16 -U hfuse:w:0xd9:m -U lfuse:w:0xe1:m For 16MHz external crystal: vrdude -c usbasp -P usb -p m16 -U hfuse:w:0xc9:m -U lfuse:w:0xef:m Refer to datasheet sections on “System clock and clock options” and “Memory programming” for other clock options and their settings. Setting the wrong fuse values may render the uC unusable Led Blink Code AVR Atmega16 Led Blink Code Hello World Led using atmega16 in C Led Blink CodeCode AVR Atmega16 How We will Program it: Blink an LED - Choose a port and a pin - In the code 1. Set pin direction to output 2. Set pin output to high 3. Wait for 250ms 4. Set pin output to low 5. Wait for 250ms 6. Go to 2 Relevant registers : DDR – set pin data direction PORT – set pin output PIN – read pin input Blink.C – Code in C Language: #include <avr/io.h> // contains definitions for DDRB, PORTB #include <util/delay.h> // contains the function _delay_ms() int main(void) { DDRB = 0b11111111; // set all pins on PortB to output while(1) { PORTB = 0b00000001; // Set PortB0 output high, others low _delay_ms(250); // Do nothing for 250 ms PORTB = 0b00000000; // Set all of them low _delay_ms(250); // Do nothing for 250 ms } return 0; }
  • 2. /* DDRB is a 8-bit register which sets direction for each pin in PortB PORTB decides output for output pins 0b – prefix for binary numbers, 0x – hex, no prefix – decimal Thus, 15 = 0xf = 0b1111 */ Compiling and Programming - Save the code as blink.c in a separate folder (not strictly necessary, just a good practice) - Create a makefile using Mfile and save in the same folder - Open it in Programmer’s Notepad and change: ◦ Line 44: MCU = atmega16 ◦ Line 65: F_CPU = 1000000 ◦ Line 73: TARGET = blink, Line 83: SRC = $(TARGET).c ◦ Alternatively, TARGET = anything_you_want and SRC = blink.c ◦ Line 278: AVRDUDE_PROGRAMMER = usbasp ◦ Line 281: AVRDUDE_PORT = usb - In Programmer’s Notepad, Tools > Make All to compile - Connect USBasp to computer and ATmega16 - Tools > Program to program ATmega16