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

8254 timer - Microprocessor and interfacing
8254 timer - Microprocessor and interfacing8254 timer - Microprocessor and interfacing
8254 timer - Microprocessor and interfacingAmitabh Shukla
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptxMemonaMemon1
 
Unit 5 assembly language programming
Unit 5   assembly language programmingUnit 5   assembly language programming
Unit 5 assembly language programmingKartik Sharma
 
Differential amplifier
Differential amplifierDifferential amplifier
Differential amplifiersarunkutti
 
8051 data types and directives
8051 data types and directives8051 data types and directives
8051 data types and directivesSARITHA REDDY
 
PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programmingAkash Puri
 
Introduction to AVR Microcontroller
Introduction to AVR Microcontroller Introduction to AVR Microcontroller
Introduction to AVR Microcontroller Mahmoud Sadat
 
8086 pin details
8086 pin details8086 pin details
8086 pin detailsAJAL A J
 
Applications of op amps
Applications of op ampsApplications of op amps
Applications of op ampsSARITHA REDDY
 
register file structure of PIC controller
register file structure of PIC controllerregister file structure of PIC controller
register file structure of PIC controllerNirbhay Singh
 
Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kVijay Kumar
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil KawareProf. Swapnil V. Kaware
 
8051 Assembly Language Programming
8051 Assembly Language Programming8051 Assembly Language Programming
8051 Assembly Language ProgrammingRavikumar Tiwari
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Dhaval Kaneria
 
Microcontroller pic 16 f877 registers memory ports
Microcontroller pic 16 f877 registers memory portsMicrocontroller pic 16 f877 registers memory ports
Microcontroller pic 16 f877 registers memory portsNilesh Bhaskarrao Bahadure
 

Mais procurados (20)

8254 timer - Microprocessor and interfacing
8254 timer - Microprocessor and interfacing8254 timer - Microprocessor and interfacing
8254 timer - Microprocessor and interfacing
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptx
 
Unit 5 assembly language programming
Unit 5   assembly language programmingUnit 5   assembly language programming
Unit 5 assembly language programming
 
8255 PPI
8255 PPI8255 PPI
8255 PPI
 
Differential amplifier
Differential amplifierDifferential amplifier
Differential amplifier
 
ATmega 16
ATmega 16ATmega 16
ATmega 16
 
8051 data types and directives
8051 data types and directives8051 data types and directives
8051 data types and directives
 
I/O Ports
I/O Ports I/O Ports
I/O Ports
 
PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programming
 
Introduction to AVR Microcontroller
Introduction to AVR Microcontroller Introduction to AVR Microcontroller
Introduction to AVR Microcontroller
 
8251 USART
8251 USART8251 USART
8251 USART
 
8086 pin details
8086 pin details8086 pin details
8086 pin details
 
Applications of op amps
Applications of op ampsApplications of op amps
Applications of op amps
 
register file structure of PIC controller
register file structure of PIC controllerregister file structure of PIC controller
register file structure of PIC controller
 
Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.k
 
PIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC InterfacingPIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC Interfacing
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
 
8051 Assembly Language Programming
8051 Assembly Language Programming8051 Assembly Language Programming
8051 Assembly Language Programming
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
 
Microcontroller pic 16 f877 registers memory ports
Microcontroller pic 16 f877 registers memory portsMicrocontroller pic 16 f877 registers memory ports
Microcontroller pic 16 f877 registers memory ports
 

Semelhante a AVR programming - BASICS

Microcontroller avr
Microcontroller avrMicrocontroller avr
Microcontroller avrMahmoud Amr
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVRMohamed Abdallah
 
Programming A Robot Using
Programming A Robot UsingProgramming A Robot Using
Programming A Robot UsingSpitiq
 
Motorola parallel port
Motorola parallel portMotorola parallel port
Motorola parallel portBkannan2
 
MICROCONTROLLER.pptx
MICROCONTROLLER.pptxMICROCONTROLLER.pptx
MICROCONTROLLER.pptxfiqrie mohd
 
Microcontroller
MicrocontrollerMicrocontroller
MicrocontrollerSpitiq
 
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 InterfacePremier Farnell
 
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 CoverterTejas Shetye
 
AN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGAN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGTotal Project Solutions
 
Port Organization of 8051 .pdf
Port Organization of 8051 .pdfPort Organization of 8051 .pdf
Port Organization of 8051 .pdfSrikrishna Thota
 
Unit2.2 8051
Unit2.2 8051Unit2.2 8051
Unit2.2 8051sjajsj
 

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

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
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.pdfPoh-Sun Goh
 
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 POSCeline George
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
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...christianmathematics
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
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.pptxAmanpreet Kaur
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
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).pptxEsquimalt MFRC
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
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-701bronxfugly43
 
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).pdfssuserdda66b
 
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 ClassroomPooky Knightsmith
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 

Último (20)

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
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
 
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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
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...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
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
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.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
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
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
 
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
 
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
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

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;