SlideShare uma empresa Scribd logo
1 de 13
Introduction to AVR
Features of AVR
(ATmega16)
• Harvard architecture
• 8 bit Microcontroller
• High performance - 16MIPS @ 16MHz
• Large program memory
• EEPROM – non volatile memory
• Two 8 bit, One 16 bit timer with total 4 PWM
channels
• On chip 10 bit ADC, 8 channels
• UART, I2C, SPI protocol support
Tools
• Compiler : WinAVR/AVR Studio/CodeVision AVR
• The programmer hardware
- Simple parallel/serial port based In System
Programmer (ISP) or
- USB based ISP (recommended) : USBasp
• Bread board, wires, power supply, crystal, etc.
Points to be noted
• PORT : group of 8 pins, or set of pins used for exchanging
data with external world
• Width of almost all registers : 8 bits (some 16 bits)
• In port related registers, every bit corresponds to one pin
of the port.
Bit 0 corresponds to Pin 0
Bit 0 corresponds to Pin 1 .. Etc
• Remember direct one to one correspondence between
HEX and BINARY numbers.
0xFF = 1111 1111
0xAA = 1010 1010
0x11 = 0001 0001
Input/Output Basics
• Three registers :
- DDRx : for configuring Data Direction (input/output)
of the port pins.
- PORTx: for writing the values to the port pins in
output mode. Configuring the port pins in
input mode.
- PINx: reading data from port pins in input mode
• Where x : A,B,C,D… depending on the available ports in your
AVR.
DDR – Data Direction Register
• Configures data direction of the port - Input / Output
• DDRx.n = 0 > makes corresponding port pin as input
DDRx.n = 1 > makes corresponding port pin as output
• Examples :
• to make all pins of port A as input pins :
DDRA = 0b00000000;
• to make all pins of port A as output pins
DDRA = 0b11111111;
• to make lower nibble of port B as output and higher nibble as
input
DDRB = 0b00001111;
PIN register
• Used to read data from port pins, when port is configured as
input.
• First set DDRx to zero, then use PINx to read the value.
• If PINx is read, when port is configured as output, it will give
you data that has been outputted on port.
• There two input modes :
- Tristated input
- Pullup input
This will be explained shortly
• Example :
DDRA = 0x00; //Set PA as input
x = PINA; //Read contents of PA
PORT register
• Used for two purposes …
1) for data output, when port is configured as output:
• Writing to PORTx.n will immediately (in same clock cycle) change
state of the port pins according to given value.
• Do not forget to load DDRx with appropriate value for configuring
port pins as output.
• Examples :
• to output 0xFF data on PB
DDRB = 0b11111111; //set all pins of
port b as outputs
PORTB = 0xFF; //write data on port
• to output data in variable x on PA
DDRA = 0xFF; //make port a as output
PORTA = x; //output 8 bit variable on
port
PORT register
2) for configuring pin as tristate/pullup, when port is
configured as input) :
• When port is configures as input (i.e DDRx.n=1), then PORTx.n
controls the internal pull-up resistor.
• PORTx.n = 1 : Enables pullup for nth bit
PORTx.n = 0 : Disables pullup for nth bit, thus making it tristate
• Examples :
• to make PA as input with pull-ups enabled and read data from PA
DDRA = 0x00; //make port a as input
PORTA = 0xFF; //enable all pull-ups
y = PINA; //read data from port a pins
• to make PB as tri stated input
DDRB = 0x00; //make port b as input
PORTB = 0x00; //disable pull-ups and make it
tri state
What is pull-up ?
• Pull-up resistor is used to ensure that tri-stated input always
reads HIGH (1) when it is not driven by any external entity.
• Pull-up is very important when you are using tri-stated input
buffers.
• Tri-state input pin offers very high impedance and thus can read
as logic 1/ logic 0 because of minute static charges on nearby
objects.
• Pin state changes rapidly and this change is unpredictable.
• This may cause your program to go haywire if it depends on input
from such tri-state pin.
Input/Output Basics
Summary
register bits →
pin function↓
DDRx.n PORTx.n PINx.n
tri stated input 0 0 read data bit(s)
x = PINx.n;
y = PINx;
pull-up input 0 1 read data bit(s)
x = PINx.n;
y = PINx;
output 1 write data bit(s)
PORTx.n = x;
PORTx = y;
n/a
• Following table lists register bit settings and resulting
function of port pins
I/O Basics – Exercise
1. Configure PB as output port
2. Configure PC as tri-stated input and read value into variable x.
3. Configure PA as pullup input and read lower nibble into
variable y and higher nibble into variable x.
4. Make higher nibble of PA as pullup inputs and lower nibble as
output.
5. Read, only input pins of above mentioned port and get the
binary number present on those pins into variable x.
6. Write four bit number 0x5 onto output pins of above mentioned
port
Answers to Exercise
1. DDRB = 0xFF (or) 0b11111111 (or) 255;
2. DDRC = 0xFF; PORTC = 0x00; x = PINC;
3. DDRA = 0x00; PORTA = 0xFF; y = PINA & 0b00001111;
x = (PINA & 0b11110000) / 24
4. DDRA = 0x0F; PORTA = 0xF0;
5. x = (PINA & 0b11110000) / 24
6. PORTA = PORTA | 0x05;

Mais conteúdo relacionado

Mais procurados

Atmel and pic microcontroller
Atmel and pic microcontrollerAtmel and pic microcontroller
Atmel and pic microcontroller
Tearsome Llantada
 
8086 assembly language
8086 assembly language8086 assembly language
8086 assembly language
Mir Majid
 
Switch mode power supply
Switch mode power supplySwitch mode power supply
Switch mode power supply
Anish Das
 
Basic structures in vhdl
Basic structures in vhdlBasic structures in vhdl
Basic structures in vhdl
Raj Mohan
 
UART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPTUART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPT
Sai_praneeth
 

Mais procurados (20)

Atmel and pic microcontroller
Atmel and pic microcontrollerAtmel and pic microcontroller
Atmel and pic microcontroller
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architecture
 
8086 assembly language
8086 assembly language8086 assembly language
8086 assembly language
 
PIC MICROCONTROLLERS -CLASS NOTES
PIC MICROCONTROLLERS -CLASS NOTESPIC MICROCONTROLLERS -CLASS NOTES
PIC MICROCONTROLLERS -CLASS NOTES
 
Switch mode power supply
Switch mode power supplySwitch mode power supply
Switch mode power supply
 
ANALOG TO DIGITAL AND DIGITAL TO ANALOG CONVERTER
ANALOG TO DIGITAL AND DIGITAL TO ANALOG CONVERTERANALOG TO DIGITAL AND DIGITAL TO ANALOG CONVERTER
ANALOG TO DIGITAL AND DIGITAL TO ANALOG CONVERTER
 
PIC Microcontrollers.ppt
PIC Microcontrollers.pptPIC Microcontrollers.ppt
PIC Microcontrollers.ppt
 
ARM Fundamentals
ARM FundamentalsARM Fundamentals
ARM Fundamentals
 
ARM Architecture
ARM ArchitectureARM Architecture
ARM Architecture
 
L9 understanding-atmega328 p-2
L9 understanding-atmega328 p-2L9 understanding-atmega328 p-2
L9 understanding-atmega328 p-2
 
Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
 
Basic structures in vhdl
Basic structures in vhdlBasic structures in vhdl
Basic structures in vhdl
 
UART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPTUART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPT
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 Microcontroller
 
Embedded C - Day 1
Embedded C - Day 1Embedded C - Day 1
Embedded C - Day 1
 
Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051
 
Introduction to Digital Signal processors
Introduction to Digital Signal processorsIntroduction to Digital Signal processors
Introduction to Digital Signal processors
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
Combinational circuits
Combinational circuitsCombinational circuits
Combinational circuits
 

Semelhante a AVR programming - BASICS

Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
Spitiq
 

Semelhante a AVR programming - BASICS (20)

Avr report
Avr reportAvr report
Avr report
 
Microcontroller avr
Microcontroller avrMicrocontroller avr
Microcontroller avr
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
 
Lecture6
Lecture6Lecture6
Lecture6
 
Lecture6.pptx
Lecture6.pptxLecture6.pptx
Lecture6.pptx
 
Programming A Robot Using
Programming A Robot UsingProgramming A Robot Using
Programming A Robot Using
 
Motorola parallel port
Motorola parallel portMotorola parallel port
Motorola parallel port
 
Presentation
PresentationPresentation
Presentation
 
MICROCONTROLLER.pptx
MICROCONTROLLER.pptxMICROCONTROLLER.pptx
MICROCONTROLLER.pptx
 
Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
 
UNIT 3 mp (1).ppt
UNIT 3 mp (1).pptUNIT 3 mp (1).ppt
UNIT 3 mp (1).ppt
 
8051 full ppt
8051 full ppt8051 full ppt
8051 full ppt
 
An Overview Study on I/O Expander with I2C and SMBus Interface
An Overview Study on I/O Expander with I2C and SMBus InterfaceAn Overview Study on I/O Expander with I2C and SMBus Interface
An Overview Study on I/O Expander with I2C and SMBus Interface
 
Universal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
Universal synchronous asynchronous receiver transmitter(usart) and AtoD CoverterUniversal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
Universal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
 
AN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGAN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACING
 
Port Organization of 8051 .pdf
Port Organization of 8051 .pdfPort Organization of 8051 .pdf
Port Organization of 8051 .pdf
 
Unit2.2 8051
Unit2.2 8051Unit2.2 8051
Unit2.2 8051
 
amba.ppt
amba.pptamba.ppt
amba.ppt
 
amba.ppt
amba.pptamba.ppt
amba.ppt
 

Último

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 

Último (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 

AVR programming - BASICS

  • 2. Features of AVR (ATmega16) • Harvard architecture • 8 bit Microcontroller • High performance - 16MIPS @ 16MHz • Large program memory • EEPROM – non volatile memory • Two 8 bit, One 16 bit timer with total 4 PWM channels • On chip 10 bit ADC, 8 channels • UART, I2C, SPI protocol support
  • 3. Tools • Compiler : WinAVR/AVR Studio/CodeVision AVR • The programmer hardware - Simple parallel/serial port based In System Programmer (ISP) or - USB based ISP (recommended) : USBasp • Bread board, wires, power supply, crystal, etc.
  • 4. Points to be noted • PORT : group of 8 pins, or set of pins used for exchanging data with external world • Width of almost all registers : 8 bits (some 16 bits) • In port related registers, every bit corresponds to one pin of the port. Bit 0 corresponds to Pin 0 Bit 0 corresponds to Pin 1 .. Etc • Remember direct one to one correspondence between HEX and BINARY numbers. 0xFF = 1111 1111 0xAA = 1010 1010 0x11 = 0001 0001
  • 5. Input/Output Basics • Three registers : - DDRx : for configuring Data Direction (input/output) of the port pins. - PORTx: for writing the values to the port pins in output mode. Configuring the port pins in input mode. - PINx: reading data from port pins in input mode • Where x : A,B,C,D… depending on the available ports in your AVR.
  • 6. DDR – Data Direction Register • Configures data direction of the port - Input / Output • DDRx.n = 0 > makes corresponding port pin as input DDRx.n = 1 > makes corresponding port pin as output • Examples : • to make all pins of port A as input pins : DDRA = 0b00000000; • to make all pins of port A as output pins DDRA = 0b11111111; • to make lower nibble of port B as output and higher nibble as input DDRB = 0b00001111;
  • 7. PIN register • Used to read data from port pins, when port is configured as input. • First set DDRx to zero, then use PINx to read the value. • If PINx is read, when port is configured as output, it will give you data that has been outputted on port. • There two input modes : - Tristated input - Pullup input This will be explained shortly • Example : DDRA = 0x00; //Set PA as input x = PINA; //Read contents of PA
  • 8. PORT register • Used for two purposes … 1) for data output, when port is configured as output: • Writing to PORTx.n will immediately (in same clock cycle) change state of the port pins according to given value. • Do not forget to load DDRx with appropriate value for configuring port pins as output. • Examples : • to output 0xFF data on PB DDRB = 0b11111111; //set all pins of port b as outputs PORTB = 0xFF; //write data on port • to output data in variable x on PA DDRA = 0xFF; //make port a as output PORTA = x; //output 8 bit variable on port
  • 9. PORT register 2) for configuring pin as tristate/pullup, when port is configured as input) : • When port is configures as input (i.e DDRx.n=1), then PORTx.n controls the internal pull-up resistor. • PORTx.n = 1 : Enables pullup for nth bit PORTx.n = 0 : Disables pullup for nth bit, thus making it tristate • Examples : • to make PA as input with pull-ups enabled and read data from PA DDRA = 0x00; //make port a as input PORTA = 0xFF; //enable all pull-ups y = PINA; //read data from port a pins • to make PB as tri stated input DDRB = 0x00; //make port b as input PORTB = 0x00; //disable pull-ups and make it tri state
  • 10. What is pull-up ? • Pull-up resistor is used to ensure that tri-stated input always reads HIGH (1) when it is not driven by any external entity. • Pull-up is very important when you are using tri-stated input buffers. • Tri-state input pin offers very high impedance and thus can read as logic 1/ logic 0 because of minute static charges on nearby objects. • Pin state changes rapidly and this change is unpredictable. • This may cause your program to go haywire if it depends on input from such tri-state pin.
  • 11. Input/Output Basics Summary register bits → pin function↓ DDRx.n PORTx.n PINx.n tri stated input 0 0 read data bit(s) x = PINx.n; y = PINx; pull-up input 0 1 read data bit(s) x = PINx.n; y = PINx; output 1 write data bit(s) PORTx.n = x; PORTx = y; n/a • Following table lists register bit settings and resulting function of port pins
  • 12. I/O Basics – Exercise 1. Configure PB as output port 2. Configure PC as tri-stated input and read value into variable x. 3. Configure PA as pullup input and read lower nibble into variable y and higher nibble into variable x. 4. Make higher nibble of PA as pullup inputs and lower nibble as output. 5. Read, only input pins of above mentioned port and get the binary number present on those pins into variable x. 6. Write four bit number 0x5 onto output pins of above mentioned port
  • 13. Answers to Exercise 1. DDRB = 0xFF (or) 0b11111111 (or) 255; 2. DDRC = 0xFF; PORTC = 0x00; x = PINC; 3. DDRA = 0x00; PORTA = 0xFF; y = PINA & 0b00001111; x = (PINA & 0b11110000) / 24 4. DDRA = 0x0F; PORTA = 0xF0; 5. x = (PINA & 0b11110000) / 24 6. PORTA = PORTA | 0x05;