SlideShare a Scribd company logo
AVR
Microcontroller
© 2019 by Mahmoud Amr
family of AVR microcontrollers
Atmega32
• At  atmel (company)
• Mega  mega avr
• 32  is refer to the size of program
memory (flash ) in the atmega32 (32Kbyte) .
features of Atmega32
8-Bit AVR General Purpose Registers
at page 11 in datasheet
The X-register, Y-register, and Z-register
• as the X-, Y-, and Z-pointer registers can be set to index any
register in the file
The registers R26…R31 have some added functions to their general purpose usage.
These registers are 16-bit address pointers for indirect addressing of the data
space. The three indirect address registers X, Y, and Z are defined as described in
the figure.
I/O PORTS
Dio ports digital input output ports
GPIO ports  general purpose input output ports
I/O PORTS  input / output ports
 32 Programmable I/O pins.
PORT A (PA7..PA0)
PORT B (PB7..PB0)
PORT C (PC7..PC0)
PORT D (PD7..PD0)
 Each PORT is controlled by 3 registers:
1. DDRx (Data Direction Register)
2. PORTx (Output Register)
3. PINx (Input Register)
NOTE: The Directions of each I/O lines must be
configured (input or output) before they are used .
PORT is controlled by 3 registers
Decided which input and which output
To use I/O ports in ATMEGA32
(PORTx/PINx/DDRx) we need to include header
file <avr/io.h>
1- Configure the port direction use register DDRX
• 1 for Output.
• 0 for Input.
2- In Read(input case) : Use register PINx.
3- In Write(output case) : Use register PORTx.
set values in registers DIO
• DDRA=5; /*(decimal)mean I activate pin 0 and
pin 2 as output and the rest as
input pins */
• DDRB=0x14; /*(hexadecimal)mean I activate pin
2 and pin 4 as output and the rest
as input pins */
• DDRC=0b00000011; /*(binary)mean I activate pin 0 and
pin 1 as output pins and the rest
as input pins */
• deal with a specific one pin
deal with a specific one pin
• Make OR operation on the register with The pin number
– For example if we want to set pin number 5 in PORTA
» PORTA = PORTA | (1<<5);
-To set specified bit in register (1)
1000 1000
| OR
0001 0000
--------------
1001 1000
1001 1000
| OR
0001 0000
--------------
1001 1000
• Make AND operation on the register with (NOT) The pin number.
– For example if we want to set pin number 3 in PORTB
» PORTB = PORTB & ( ~(1<<3) );
-To clear specified bit in register
1000 1100
& AND
1111 1011
--------------
1000 1000
1000 1000
& AND
1111 1011
--------------
1000 1000
0000 0100
~ NOT
--------------
1111 1011
• Make XOR operation on the register with The pin
number
– for example if we want to toggle pin number 2 in PORTC
» PORTC = PORTC ^ (1<<PC2);
- To toggle specified bit in register
DDRx
Configure the port direction use register DDRX
1 for Output.
0 for Input.
DDRA=0xFF; //initialize portA as output
DDRB=0x00; //initialize portB as input
PORTx
When I need to Write data as 0 0V , 1  5V .
- set DDRx as output
PORTA=0xFF; //ALL portA are output 5V
PORTA=0x00; //ALL portA are output 0V
PINx
When I need to Write data as 0 0V , 1  5V .
- set DDRx as input
X = PINA; //PORTA as input and data save in X
• To use the delay feature, we need to include
header file <util/delay.h> and write before it
# define F_CPU 8000000ul to achieve the
required delay .
– _delay_ms(1000); //Delay 1000 ms = 1 second.
– _delay_ms(100); //Delay 100 ms.
Buttons
• Pushbutton
1- pull-up mode
2- pull-down mode
Button V out
No push 5 V
Push 0 V
Button V out
No Push 0 V
Push 5 V
 Note in case you set any PIN as input you can activate the internal pull up
resistor by setting the corresponding bit in PORTX register.
Example
To set the pin 2 in PORTB as input pin and use the internal pull up
resistor of this pin.
DDRB = DDRB & (~(1<<PB2));
PORTB= PORTB | (1<<PB2);

More Related Content

What's hot

Class7
Class7Class7
AT mega8 basics
AT mega8 basicsAT mega8 basics
AT mega8 basics
thetechnicalzone
 
set de instrucciones primera parte de atmel
set de instrucciones primera parte de atmelset de instrucciones primera parte de atmel
set de instrucciones primera parte de atmel
Tecnomaquinados de Queretaro
 
2014 ii c08t-sbc pic para ecg
2014 ii c08t-sbc pic para ecg 2014 ii c08t-sbc pic para ecg
2014 ii c08t-sbc pic para ecg
Aland Bravo Vecorena
 
Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2
Ikhwan_Fakrudin
 
Ch2 microcontroller architecture
Ch2 microcontroller architectureCh2 microcontroller architecture
Ch2 microcontroller architecture
Ahmad Sidik
 
Interfacing of 8255 IC By Er. Swapnil Kaware.
Interfacing of 8255 IC By Er. Swapnil Kaware.Interfacing of 8255 IC By Er. Swapnil Kaware.
Interfacing of 8255 IC By Er. Swapnil Kaware.
Prof. Swapnil V. Kaware
 
Lecture 2 (system overview of c8051 f020) rv01
Lecture 2 (system overview of c8051 f020) rv01Lecture 2 (system overview of c8051 f020) rv01
Lecture 2 (system overview of c8051 f020) rv01
cairo university
 
8255 PPI
8255 PPI8255 PPI
8255 PPI
deval patel
 
Controller Implementation in Verilog
Controller Implementation in VerilogController Implementation in Verilog
Controller Implementation in Verilog
Anees Akhtar
 
8255_utkarsh_kulshrestha
8255_utkarsh_kulshrestha8255_utkarsh_kulshrestha
8255_utkarsh_kulshrestha
Utkarsh Kulshrestha
 
8155 Basic Concepts
8155 Basic Concepts8155 Basic Concepts
8155 Basic Concepts
Srinath Kalikivayi
 
Operation of 8255A
Operation of 8255AOperation of 8255A
Operation of 8255A
Anuj Yadav
 
Lecture 04 branch call and time delay
Lecture 04  branch call and time delayLecture 04  branch call and time delay
Lecture 04 branch call and time delay
Vajira Thambawita
 
Avr report
Avr reportAvr report
Avr report
NITISH KUMAR
 
An cm-303 8-bit-siso_sipo_piso_pipo_shift_registers
An cm-303 8-bit-siso_sipo_piso_pipo_shift_registersAn cm-303 8-bit-siso_sipo_piso_pipo_shift_registers
Interfacing of io device to 8085
Interfacing of io device to 8085Interfacing of io device to 8085
Interfacing of io device to 8085
Nitin Ahire
 
Registers
RegistersRegisters
Registers
Jamia Hamdard
 
Microprocessor Basics 8085-8255 ch-5
Microprocessor Basics 8085-8255 ch-5Microprocessor Basics 8085-8255 ch-5
Microprocessor Basics 8085-8255 ch-5
Neelam Kapoor
 
Abc2
Abc2Abc2

What's hot (20)

Class7
Class7Class7
Class7
 
AT mega8 basics
AT mega8 basicsAT mega8 basics
AT mega8 basics
 
set de instrucciones primera parte de atmel
set de instrucciones primera parte de atmelset de instrucciones primera parte de atmel
set de instrucciones primera parte de atmel
 
2014 ii c08t-sbc pic para ecg
2014 ii c08t-sbc pic para ecg 2014 ii c08t-sbc pic para ecg
2014 ii c08t-sbc pic para ecg
 
Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2
 
Ch2 microcontroller architecture
Ch2 microcontroller architectureCh2 microcontroller architecture
Ch2 microcontroller architecture
 
Interfacing of 8255 IC By Er. Swapnil Kaware.
Interfacing of 8255 IC By Er. Swapnil Kaware.Interfacing of 8255 IC By Er. Swapnil Kaware.
Interfacing of 8255 IC By Er. Swapnil Kaware.
 
Lecture 2 (system overview of c8051 f020) rv01
Lecture 2 (system overview of c8051 f020) rv01Lecture 2 (system overview of c8051 f020) rv01
Lecture 2 (system overview of c8051 f020) rv01
 
8255 PPI
8255 PPI8255 PPI
8255 PPI
 
Controller Implementation in Verilog
Controller Implementation in VerilogController Implementation in Verilog
Controller Implementation in Verilog
 
8255_utkarsh_kulshrestha
8255_utkarsh_kulshrestha8255_utkarsh_kulshrestha
8255_utkarsh_kulshrestha
 
8155 Basic Concepts
8155 Basic Concepts8155 Basic Concepts
8155 Basic Concepts
 
Operation of 8255A
Operation of 8255AOperation of 8255A
Operation of 8255A
 
Lecture 04 branch call and time delay
Lecture 04  branch call and time delayLecture 04  branch call and time delay
Lecture 04 branch call and time delay
 
Avr report
Avr reportAvr report
Avr report
 
An cm-303 8-bit-siso_sipo_piso_pipo_shift_registers
An cm-303 8-bit-siso_sipo_piso_pipo_shift_registersAn cm-303 8-bit-siso_sipo_piso_pipo_shift_registers
An cm-303 8-bit-siso_sipo_piso_pipo_shift_registers
 
Interfacing of io device to 8085
Interfacing of io device to 8085Interfacing of io device to 8085
Interfacing of io device to 8085
 
Registers
RegistersRegisters
Registers
 
Microprocessor Basics 8085-8255 ch-5
Microprocessor Basics 8085-8255 ch-5Microprocessor Basics 8085-8255 ch-5
Microprocessor Basics 8085-8255 ch-5
 
Abc2
Abc2Abc2
Abc2
 

Similar to Microcontroller avr

Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
Mohamed Abdallah
 
8255.pdf
8255.pdf8255.pdf
8255.pdf
someshdash1
 
itft-8085 microprocessor
itft-8085 microprocessoritft-8085 microprocessor
itft-8085 microprocessor
Shifali Sharma
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
Thirunavakkarasu kannusamy
 
knowledge in daily life.ppt
knowledge in daily life.pptknowledge in daily life.ppt
knowledge in daily life.ppt
SunilSharma941036
 
Lathe Spindle Sensor
Lathe Spindle SensorLathe Spindle Sensor
Lathe Spindle Sensor
JoeCritt
 
assignment 1-MC.pdf
assignment 1-MC.pdfassignment 1-MC.pdf
assignment 1-MC.pdf
SANTHAKUMARP5
 
dspAt89 s52
dspAt89 s52dspAt89 s52
dspAt89 s52
Mahesh Madapati
 
Mod-2 M&M.pptx
Mod-2 M&M.pptxMod-2 M&M.pptx
Mod-2 M&M.pptx
TechCook1
 
Microcontroller at89 s52 datasheet
Microcontroller at89 s52 datasheetMicrocontroller at89 s52 datasheet
Microcontroller at89 s52 datasheet
Shanmugadhasan Saravanabavanantharajah
 
8085-microprocessor
8085-microprocessor8085-microprocessor
8085-microprocessor
ATTO RATHORE
 
Programming A Robot Using
Programming A Robot UsingProgramming A Robot Using
Programming A Robot Using
Spitiq
 
MicrocontrollersII (1).pptx
MicrocontrollersII (1).pptxMicrocontrollersII (1).pptx
MicrocontrollersII (1).pptx
nodov66591
 
AT89C52 Data sheet
AT89C52 Data sheetAT89C52 Data sheet
AT89C52 Data sheet
Microtech Solutions
 
Programmable Peripheral Devices
Programmable Peripheral Devices Programmable Peripheral Devices
Programmable Peripheral Devices
glorypriyadharshini1
 
Chp 2 and 3.pptx
Chp 2 and 3.pptxChp 2 and 3.pptx
Chp 2 and 3.pptx
SangeetaTripathi8
 
Micro
MicroMicro
Micro
Moaz Zahid
 
Keypad interfacing 8051 -NANOCDAC
Keypad interfacing 8051 -NANOCDACKeypad interfacing 8051 -NANOCDAC
Keypad interfacing 8051 -NANOCDAC
nanocdac
 
Untitled 1
Untitled 1Untitled 1
Untitled 1
lakachew
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
Sadiq Rahim
 

Similar to Microcontroller avr (20)

Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
 
8255.pdf
8255.pdf8255.pdf
8255.pdf
 
itft-8085 microprocessor
itft-8085 microprocessoritft-8085 microprocessor
itft-8085 microprocessor
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
 
knowledge in daily life.ppt
knowledge in daily life.pptknowledge in daily life.ppt
knowledge in daily life.ppt
 
Lathe Spindle Sensor
Lathe Spindle SensorLathe Spindle Sensor
Lathe Spindle Sensor
 
assignment 1-MC.pdf
assignment 1-MC.pdfassignment 1-MC.pdf
assignment 1-MC.pdf
 
dspAt89 s52
dspAt89 s52dspAt89 s52
dspAt89 s52
 
Mod-2 M&M.pptx
Mod-2 M&M.pptxMod-2 M&M.pptx
Mod-2 M&M.pptx
 
Microcontroller at89 s52 datasheet
Microcontroller at89 s52 datasheetMicrocontroller at89 s52 datasheet
Microcontroller at89 s52 datasheet
 
8085-microprocessor
8085-microprocessor8085-microprocessor
8085-microprocessor
 
Programming A Robot Using
Programming A Robot UsingProgramming A Robot Using
Programming A Robot Using
 
MicrocontrollersII (1).pptx
MicrocontrollersII (1).pptxMicrocontrollersII (1).pptx
MicrocontrollersII (1).pptx
 
AT89C52 Data sheet
AT89C52 Data sheetAT89C52 Data sheet
AT89C52 Data sheet
 
Programmable Peripheral Devices
Programmable Peripheral Devices Programmable Peripheral Devices
Programmable Peripheral Devices
 
Chp 2 and 3.pptx
Chp 2 and 3.pptxChp 2 and 3.pptx
Chp 2 and 3.pptx
 
Micro
MicroMicro
Micro
 
Keypad interfacing 8051 -NANOCDAC
Keypad interfacing 8051 -NANOCDACKeypad interfacing 8051 -NANOCDAC
Keypad interfacing 8051 -NANOCDAC
 
Untitled 1
Untitled 1Untitled 1
Untitled 1
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 

Recently uploaded

Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Envertis Software Solutions
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 

Recently uploaded (20)

Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 

Microcontroller avr

  • 2.
  • 3. family of AVR microcontrollers
  • 4. Atmega32 • At  atmel (company) • Mega  mega avr • 32  is refer to the size of program memory (flash ) in the atmega32 (32Kbyte) .
  • 6. 8-Bit AVR General Purpose Registers at page 11 in datasheet
  • 7. The X-register, Y-register, and Z-register • as the X-, Y-, and Z-pointer registers can be set to index any register in the file The registers R26…R31 have some added functions to their general purpose usage. These registers are 16-bit address pointers for indirect addressing of the data space. The three indirect address registers X, Y, and Z are defined as described in the figure.
  • 8.
  • 9. I/O PORTS Dio ports digital input output ports GPIO ports  general purpose input output ports I/O PORTS  input / output ports
  • 10.  32 Programmable I/O pins. PORT A (PA7..PA0) PORT B (PB7..PB0) PORT C (PC7..PC0) PORT D (PD7..PD0)  Each PORT is controlled by 3 registers: 1. DDRx (Data Direction Register) 2. PORTx (Output Register) 3. PINx (Input Register) NOTE: The Directions of each I/O lines must be configured (input or output) before they are used .
  • 11. PORT is controlled by 3 registers
  • 12. Decided which input and which output To use I/O ports in ATMEGA32 (PORTx/PINx/DDRx) we need to include header file <avr/io.h> 1- Configure the port direction use register DDRX • 1 for Output. • 0 for Input. 2- In Read(input case) : Use register PINx. 3- In Write(output case) : Use register PORTx.
  • 13. set values in registers DIO • DDRA=5; /*(decimal)mean I activate pin 0 and pin 2 as output and the rest as input pins */ • DDRB=0x14; /*(hexadecimal)mean I activate pin 2 and pin 4 as output and the rest as input pins */ • DDRC=0b00000011; /*(binary)mean I activate pin 0 and pin 1 as output pins and the rest as input pins */ • deal with a specific one pin
  • 14. deal with a specific one pin • Make OR operation on the register with The pin number – For example if we want to set pin number 5 in PORTA » PORTA = PORTA | (1<<5); -To set specified bit in register (1) 1000 1000 | OR 0001 0000 -------------- 1001 1000 1001 1000 | OR 0001 0000 -------------- 1001 1000
  • 15. • Make AND operation on the register with (NOT) The pin number. – For example if we want to set pin number 3 in PORTB » PORTB = PORTB & ( ~(1<<3) ); -To clear specified bit in register 1000 1100 & AND 1111 1011 -------------- 1000 1000 1000 1000 & AND 1111 1011 -------------- 1000 1000 0000 0100 ~ NOT -------------- 1111 1011
  • 16. • Make XOR operation on the register with The pin number – for example if we want to toggle pin number 2 in PORTC » PORTC = PORTC ^ (1<<PC2); - To toggle specified bit in register
  • 17. DDRx Configure the port direction use register DDRX 1 for Output. 0 for Input. DDRA=0xFF; //initialize portA as output DDRB=0x00; //initialize portB as input
  • 18. PORTx When I need to Write data as 0 0V , 1  5V . - set DDRx as output PORTA=0xFF; //ALL portA are output 5V PORTA=0x00; //ALL portA are output 0V
  • 19. PINx When I need to Write data as 0 0V , 1  5V . - set DDRx as input X = PINA; //PORTA as input and data save in X
  • 20.
  • 21. • To use the delay feature, we need to include header file <util/delay.h> and write before it # define F_CPU 8000000ul to achieve the required delay . – _delay_ms(1000); //Delay 1000 ms = 1 second. – _delay_ms(100); //Delay 100 ms.
  • 22. Buttons • Pushbutton 1- pull-up mode 2- pull-down mode Button V out No push 5 V Push 0 V Button V out No Push 0 V Push 5 V
  • 23.  Note in case you set any PIN as input you can activate the internal pull up resistor by setting the corresponding bit in PORTX register. Example To set the pin 2 in PORTB as input pin and use the internal pull up resistor of this pin. DDRB = DDRB & (~(1<<PB2)); PORTB= PORTB | (1<<PB2);