2. AVR MICROCONTROLLER
The ATmega8 is a low-power CMOS 8-bit microcontroller based on the AVR RISC
architecture. By executing powerful instructionsin a single clock cycle, the
ATmega8 achieves through puts approaching1 MIPS per MHz, allowingthe system
designer to optimize power consumptionversus processing speed.
The AVR core combines a rich instruction set with 32 general purpose working
registers. All the32 registers are directly connected to the Arithmetic Logic Unit
(ALU), allowing two independentregisters to be accessed in one single instruction
executed in one clock cycle. The resulting architecture is more code efficient while
achievingthroughputs up to ten times faster than conventional CISC
microcontrollers.
The ATmega8 provides the following features: 8K bytes of In-System
Programmable Flash with Read-While-Write capabilities,512 bytes of EEPROM, 1K
3. byte of SRAM, 23 general purpose I/O lines, 32 general purpose working registers,
three flexible Timer/Counterswith compare modes, internal and external
interrupts, a serial programmable USART, a byte oriented Two wire Serial
Interface, a 6-channel ADC (eight channelsin TQFP and QFN/MLF packages) with
10-bit accuracy, a programmable Watchdog Timer with Internal Oscillator,an SPI
serial port, and five software selectable power saving modes. The Idle mode stops
the CPU while allowingthe SRAM, Timer/Counters, SPI port, and interrupt system
to continue functioning.The Power down mode saves the register contents but
freezes the Oscillator, disablingall other chip functions untilthe next Interrupt or
Hardware Reset. In Power-save mode, the asynchronoustimer continues to run,
allowingthe user to maintaina timer base while the rest of the device is sleeping.
The ADC Noise Reduction mode stops the CPU and all I/O modules except
asynchronous timer and ADC, to minimize switching noise during ADC
conversions. In Standbymode, the crystal/resonator Oscillatoris runningwhile the
rest of the device is sleeping. Thisallows very fast start-up combined with low-
power consumption.
The device is manufactured using Atmel’s high density non-volatilememory
technology. The Flash Program memory can be reprogrammed In-System through
4. an SPI serial interface, by a conventional non-volatilememory programmer, or by
an On-chip boot program running on the AVR core. The boot program can use any
interface to downloadthe applicationprogram in the ApplicationFlash memory.
Software in the Boot Flash Section will continue to run while the Application Flash
Section is updated,providing true Read-While-Write operation. By combiningan
8-bit RISC CPU with In-System Self-Programmable Flash on a monolithicchip, the
Atmel ATmega8 is a powerful microcontroller that provides a highly-flexibleand
cost-effective solution to many embedded control applications.
The ATmega8 AVR is supported with a full suite of program and system
developmenttools, IncludingC compilers, macro assemblers, program
debugger/simulators, In-Circuit Emulators, and evaluation kits.
5. features
High-performance, Low-power AVR® 8-bit Microcontroller
• Advanced RISC Architecture
– 130 Powerful Instructions – Most Single-clock Cycle Execution
– 32 x 8 General Purpose Working Registers
– Fully Static Operation
– Up to 16 MIPS Throughput at 16 MHz
6. – On-chip 2-cycle Multiplier
• High Endurance Non-volatile Memory segments
– 8K Bytes of In-System Self-programmableFlash program memory
– 512 Bytes EEPROM
– 1K Byte Internal SRAM
– Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
– Data retention: 20 years at 85°C/100 years at 25°C(1)
– Optional Boot Code Section with Independent Lock Bits In-System
Programmingby On-chip Boot Program True Read-While-Write Operation
– ProgrammingLock for Software Security
• Peripheral Features
– Two 8-bit Timer/Counterswith Separate Prescaler, one Compare Mode
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and
Capture
Mode
– Real Time Counter with Separate Oscillator
7. – Three PWM Channels
– 8-channel ADC in TQFP and QFN/MLF package
Eight Channels 10-bit Accuracy
– 6-channel ADC in PDIP package
Six Channels 10-bit Accuracy
– Byte-oriented Two-wire Serial Interface
– Programmable Serial USART
– Master/Slave SPI Serial Interface
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
• Special Microcontroller Features
– Power-on Reset and ProgrammableBrown-out Detection
– Internal Calibrated RC Oscillator
– External and Internal Interrupt Sources
– Five Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, and
Standby
11. One of the most important features of ATmega8 microcontroller is that
except 5 pins, all other pins can be used for supporting two signals.
o Pins 9,10,14,15,16,17,18,19 are used for port B, Whereas Pins
23,24,25,26,27,28 and 1 are used for port C and Pins 2,3,4,5,6,11,12 are used
for port D.
o Pin 1 is used as Reset pin and on applyinglow level signal for time longer than
minimum pulse length will generate a reset signal.
o Pins 3 and 2 can also be used in serial communication for USART (Universal
Synchronous and Asynchronous Receiver Transmitter).
o Pin 5 and 4 are used as external interrupts.
o Pins 10 and9 are used as timer counteroscillatorsas well as external oscillator
where the crystal is connected directly between the pins.
o Pin 19 is used as slave clock input or master clock output for Serial Peripheral
Interface (SPI) channel.
o Pin 18 is used as slave clock output or master clock input
o Pins 23 to 28 are used for analog to digital conversion (ADC) channels.
o Pin 12 and 13 are used as Analog Comparator inputs.
12. o Pins 6 and 11 are used as counter/timer sources.
TOOLS
• Compiler : WinAVR/AVR Studio/CodeVision AVR
• The programmer hardware
- Simple parallel/serialport based In System Programmer (ISP) or
- USB based ISP (recommended) : USBasp
• Bread board, wires, power supply, crystal, etc
13. POINTSTOBENOTED
• PORT : group of 8 pins, or set of pinsused 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
14. INPUT/OUTPUTBASICS
ATmega8 microcontroller consists of 3 I/O ports, named as B, C and
D with a combination of 23 I/O lines. Port D consists of 8 I/O lines,
Port C consists of 7 I/O lines, and Port B consists of 8 I/O lines.
Registers corresponding to the Input/output port X (B, C or D) are:
o DDRX: Data Direction Register of Port X (for configuring Data Direction
(input/output) of the port pins.)
o PORTX: Dataregister of Port X (for writing the values to the port pinsinoutput
mode. Configuring the port pins in input mode.)
o PINX: Input register of Port X (reading data from port pins in input mode)
o Where x : A,B,C,D… depending on the available ports in your AVR.
15.
16. DDR-DATADIRECTIONREGISTER
• 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 nibbleof port B as output and higher nibbleas
input
DDRB = 0b00001111;
17. PINREGISTER
• 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 explainedshortly
• Example :
DDRA = 0x00; //Set PA as input x =
PINA; //Read contents of PA
18. PORTREGISTER
• 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 pinsaccording to given value.
• Do not forget to load DDRx with appropriatevalue for configuring port
pins as output.
• Examples :
• to output 0xFF data on PB
DDRB = 0b11111111;
port b as outputs
//set all pins of
PORTB = 0xFF; //write data on port
• to output data in variablex on PA
DDRA = 0xFF; //make port a as output PORTA =
x; //output 8 bit variable on port
19. 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 internalpull-up resistor.
• PORTx.n = 1 : Enables pullupfor nth bit
PORTx.n = 0 : Disables pullupfor nth bit, thus making it tristate
• Examples :
• to make PA as input with pull-upsenabled 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
20. What is pull-up ?
• Pull-up resistor is used to ensure that tri-stated input alwaysreads
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 impedanceand 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 dependson input from
such tri-state pin.
21. Serial Peripheral Interface (SPI) in AVR Microcontroller
AVR microcontroller support wired communication protocols. Most of the
microcontroller comes with internal modules that support communication
protocols.
The commonly supported protocols in AVR microcontroller are:
o SPI (Serial Peripheral Interface)
o TWI (Two Wire Interface)
o UART (Universal Asynchronous Receiver Transmitter) communication
o USI (Universal Serial Interface)
o USB (Universal Serial Bus)
o Ethernet etc.
SPI is the simplest protocols among all the communication protocols. 8 Bit
data registers inside a device is connected by wires and these data registers
22. works as shift registers for controlling the data exchange inside the SPI
network. The device or devices that will controls the operation inside the
network is known as the master.
TASKS PERFORMED DURING TRAINING
• GPIO Programming.
• LED interfacing using AVR.
• Button interfacing using AVR.
• Working on keypad with AVR.
• LED Matrix and LED Matrix Display.
• DisplayingAlphabetsand Numbers on LED Matrix using AVR.
• Introductionto Seven Segment with AVR.
• Introductionto Buzzer.
• GLCD Introduction & interfacing with AVR.
• Introductionto ADC.
• Introductionto USART Protocol.
• Interfacing DC Motors with AVR.