0% found this document useful (0 votes)
34 views75 pages

Microcontroller Interfacing Essentials

The document provides an overview of the history and architecture of AVR microcontrollers. It discusses how AVR was developed in 1996 by Atmel Corporation and derives its name from its creators. It also describes the different categories of AVR microcontrollers and highlights features like their RISC architecture and Harvard bus structure. Additionally, it summarizes the architecture of a common AVR chip, the Atmega16, outlining its memory, I/O ports, timers/counters, and other components.

Uploaded by

Besho Atef
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
34 views75 pages

Microcontroller Interfacing Essentials

The document provides an overview of the history and architecture of AVR microcontrollers. It discusses how AVR was developed in 1996 by Atmel Corporation and derives its name from its creators. It also describes the different categories of AVR microcontrollers and highlights features like their RISC architecture and Harvard bus structure. Additionally, it summarizes the architecture of a common AVR chip, the Atmega16, outlining its memory, I/O ports, timers/counters, and other components.

Uploaded by

Besho Atef
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 75

History of AVR

• AVR was developed in the year 1996 by Atmel Corporation.


• The architecture of AVR was developed by Alf-Egil Bogen and Vegard
Wollan.

• AVR derives its name from its developers and stands


for Alf-Egil Bogen Vegard Wollan RISC microcontroller
History of AVR
also known as Advanced Virtual RISC.

The AT90S8515 was the first microcontroller which was based on AVR
architecture.

the first microcontroller to hit the commercial market was AT90S1200


in the year 1997.
AVR microcontrollers categories
 TinyAVR :
Less memory, small size, suitable only for simpler applications
 MegaAVR :
These are the most popular ones having good amount of memory (up to 256
KB), higher number of inbuilt peripherals and suitable for moderate to complex
applications.
XmegaAVR :
Used commercially for complex applications, which require large program
memory and high speed.
What’s special about AVR?

• They are fast: AVR microcontroller executes most of the instructions


in single execution cycle.
• AVRs are about 4 times faster than PICs, they consume less power
and can be operated in different power saving modes.
• Free IDE
• Powerful Data sheet
the comparison between the three most commonly used families of
microcontrollers.
AVR Architecture
• AVR is an 8-bit microcontroller belonging to the family of Reduced
Instruction Set Computer (RISC).
• In RISC architecture the instruction set of the computer are not only
fewer in number but also simpler and faster in operation.
• AVR follows Harvard Architecture format .
Harvard Architecture
processor is equipped with separate memories and buses for
Program and the Data information. Here while an instruction is being
executed, the next instruction is pre-fetched from the program
memory.
What is 8-bit?
• This means that the microcontroller is capable of transmitting and
receiving 8-bit data.
• The input/output registers available are of 8-bits
Atmega16
In our journey with the AVR we will be working on Atmega16 microcontroller
40-pin IC and belongs to the megaAVR category of AVR family.
Some of the features of Atmega16 are:
• 16KB of Flash memory
• 1KB of SRAM
• 512 Bytes of EEPROM
• Available in 40-Pin DIP
• 8-Channel 10-bit ADC
• Two 8-bit Timers/Counters
• One 16-bit Timer/Counter
• 4 PWM Channels
• In System Programmer (ISP)
• Serial USART
• SPI Interface
• Digital to Analog Comparator.
flavors for Atmega16
Here are two microcontroller:
• Atmega16:- Operating frequency range is 0 – 16
MHz.
• Atmega16L:- Operating frequency range is 0 – 8
MHz.
Hint
If we are using a crystal of 8 MHz = 8 x 106 Hertz = 8 Million cycles, then AVR
can execute 8 million instructions.
Naming Convention
• The AT refers to Atmel the manufacturer, Mega means that the
microcontroller belong to MegaAVR category, 16 signifies the memory
of the controller, which is 16KB.
Atmega16 Architecture
Atmega16 Architecture cont.
 I/O Ports
• four (PORTA, PORTB, PORTC and PORTD)
• 8-bit input-output ports.

Internal Calibrated Oscillator


• By default Atmega16 is set to operate at internal calibrated oscillator of 1
MHz.
• The maximum frequency of internal oscillator is 8Mhz.
• ATmega16 can be operated using an external crystal oscillator with a
maximum frequency of 16MHz.
Atmega16 Architecture cont.
ADC Interface
• Atmega16 is equipped with an 8 channel ADC (Analog to Digital Converter)
with a resolution of 10-bits.
Timers/Counters
• two 8-bit and one 16-bit timer/counter.
• Timers are useful for generating precision actions for e.g., creating time
delays between two operations.
 Watchdog Timer
• Watchdog timer is present with internal oscillator.
• Watchdog timer continuously monitors and resets the controller if the code
gets stuck at any execution action for more than a defined time interval.
Atmega16 Architecture cont.
 Interrupts:
• Atmega16 consists of 21 interrupt sources out of which four are external.
• The remaining are internal interrupts which support the peripherals like
USART, ADC, Timers etc.

USART
• interface is available for interfacing with external device capable of
communicating serially (data transmission bit by bit).
Atmega16 Architecture cont.
General Purpose Registers
• Atmega16 is equipped with 32 general purpose registers which are coupled
directly with the Arithmetic Logical Unit (ALU) of CPU.
Atmega16 Architecture cont.
Memory
Atmega16 consist of three different memory sections:
• Flash EEPROM:
• Byte Addressable EEPROM
• SRAM
Atmega16 Architecture cont.
ISP
• AVR family of controllers have In System Programmable Flash Memory which
can be programmed without removing the IC from the circuit, ISP allows to
reprogram the controller while it is in the application circuit.
SPI
• Serial Peripheral Interface, SPI port is used for serial communication between
two devices on a common clock source.
• The data transmission rate of SPI is more than that of USART.
Atmega16 Architecture cont.
 TWI
• Two Wire Interface (TWI) can be used to set up a network of devices, many
devices can be connected over TWI interface forming a network, the devices
can simultaneously transmit and receive and have their own unique address.

DAC
• Digital to Analog Converter (DAC) interface which can be
used for reverse action performed by ADC.
• DAC can be used when there is a need of converting a digital signal to analog
signal.
AVR reset circuit
AVR crystal circuit
AVR GPIO
• Every micro-controller has GPIO ports.
• GPIO stands for general purpose input output. These GPIO ports are
used to take input on a micro-controller pin or output a value on
micro-controller pin.
AVR GPIO Ports
AVR GPIO Ports
GPIO control registers
• DDRn – Data Direction Register
• PORTn – Port Output data Register
• PINn – Port Input Register
• n- Indicates the port name i.e. A, B, C & D
GPIO control registers
GPIO control registers cont.
DDRn Register
• Data Direction Register configures data direction of a port or a port pin.
• Writing a value 0 configure that port pin as INPUT and writing a value 1
configures a port pin as OUTPUT.
GPIO control registers cont.
• PORTn Register
• To output data when port is configured as output
• To activate/deactivate internal pull-up registers when port
is configures as input
GPIO control registers cont.
• activate/deactivate internal pull-up register
• When you set bits in DDRn to 0, i.e. make port pins as inputs
• then corresponding bits in PORTn register are used to activate/deactivate
pull-up registers associated with that pin.
• activate pull-up resister, set bit in PORTn to 1, and to deactivate (i.e to make
port pin tri stated) set it to 0.
GPIO control registers cont.
GPIO control registers cont.
PINn Register
• The PINn register keeps the status of all the pins in that port. By
reading this register we can get the current logic level (0 or 1) on the
pin.
Example
LEDS and Switches
Switch Debouncing
Debouncing solution
Seven Segment
Seven Segment
A seven segment consists of eight LEDs which are aligned in a manner
so as to display digits from 0 to 9 when proper combination of LED is
switched on.
 Seven segment uses seven LED’s to display digits from 0 to 9 and the
eighth LED is used for the dot.
Seven Segment types
• Seven Segment are available in two configuration
• Common Anode
• Common Cathode.
Display digits.
Multiplexing 7segments using decoder
Multiplexing 7segments using decoder
Relay interfacing
Keypad Interfacing
Keypad Interfacing
Keypad is organized as a matrix of switches in rows and column.
The concept of interfacing keypad with the MCU is:
• Every number is assigned two unique parameters, i.e. row and column
number (n(R, C) for example 6 (2, 3)).
• Hence every time a key is pressed the number is identified by detecting
the row and column number of the key pressed.
Keypad Interfacing Cont.
Keypad scanning
Initially all the rows are set to zero by the controller and the columns are scanned
to check if any key is pressed
 In case no key is pressed the output of all the columns will be high.
Whenever a key is pressed the row and column corresponding to the key will get
short, resulting in the output of the corresponding column goes to go low
since we have made all the rows zero this gives the column number of the
pressed key.
LCD Interfacing
LCD?
LCD (Liquid Crystal Display) screen is an electronic display module and find a wide
range of applications.

A 16x2 LCD display is very basic module and is very commonly used in various
devices and circuits

The reasons being: LCDs are economical; easily programmable; have no limitation
of displaying special & even custom characters (unlike in seven segments),
animations and so on.
Interfacing LCD
LCD Interfacing signals
• 8-bit data bus (RD7-RD0)
• Three control signals
• RS – Register Select (RA3)
• R/W – Read/Write (RA2)
• E – Enable (RA1)
• Three power connections
• Power, ground, and variable resistor to control brightness
Interfacing LCD
Driver has two 8-bit internal registers
Instruction Register (IR):
• The command register stores the command instructions given to
the LCD.
• A command is an instruction given to LCD to do a predefined task
like initializing it, clearing its screen, setting the cursor position,
controlling display etc.
Data Register (DR) to write data (ASCII characters)
• The data register stores the data to be displayed on the LCD.
• The data is the ASCII value of the character to be displayed on the
LCD.
LCD Interfacing modes
Can be interfaced either in 8-bit mode or 4-bit mode
• In 8-bit mode, all eight data lines are connected
• In 4-bit mode, only four data lines are connected
• Two transfers per character (or instruction) are needed
LCD Operation
When the microcontroller writes an instruction to IR or data to DR, the
controller:
Sets DB7 high indicating that the controller is busy
Sets DB7 low after the completion of the operation
The microcontroller should always check whether DB7 is low before sending
an instruction or a data byte
Note : we skip this check and make delays instead of it.
Timing diagram: writing to LCD
initialize LCD
• The following instructions are used to initialize LCD.
• 0x38 to initialize LCD in 8-bit mode
• 0x01 to clear LCD
• 0x0E to make cursor ON
• 0x80 to go to first line and 0th position in LCD
• Delay of around 50 micro second is necessary b/w two commands for
execution of instructions.
Send command function

• To send any command to LCD


• Transfer the command to LCD_DATA port
• Set RS and RW bit to go LOW and enable as HIGH
• Give a small delay
• Set enable to LOW
write Data function

• To display any data on LCD


• Transfer the data (Ascii value of the character to be sent) to LCD_DATA
port.
• Make RW as LOW and set RS and enable as HIGH.
• Give a small delay.
• Make enable pin LOW
LCD Commands
Interrupts
• An interrupt is an exception, a change of the normal progression, or
interruption in the normal flow of program execution.
Interrupt Vs Polling
If response time is really critical, a “tight” polling loop is used.

polling can be faster than interrupts......, but further processing is on


hold!
Interrupt types
Interrupt handling
Interrupt Vector Table
• The interrupt vector is a const location in memory that programmed
with the address of interrupt service routine (ISR).
• Whenever an unmasked interrupt occurs program execution starts
from the address contained in the interrupt vector.
Interrupt Vector Table
Interrupt Vector Table priorities
• All interrupts have separate interrupt vectors in the interrupt vector
table
• Interrupts have priority in accordance
with their position in the table and have enable and disable bit.
• Lower interrupt vector address have higher priority.
• Reset has top priority.
Interrupts periorities
Interrupt nesting
Interrupt nesting cont.
Enabling interrupts

• Global Interrupt Enable (GIE) bit must be set in the status register
(SREG)
• The individual interrupt enable bits must be set in the proper control
register.
• See datasheet
External Interrupts
• External Interrupts:
Level- or edge-triggered
Level-triggered

threshold
t
trigger point

Edge-triggered

t
trigger point
Using interrupts
• Keep the ISR short!
• If you change variables: Keep in mind that you could jump to the ISR
from everywhere in your program!ƒ
• If you want to create a section were no IRs are allowed clear the
Interrupt flag in the SREG register (careful!)
Using interrupts

You might also like