0% found this document useful (0 votes)
17 views22 pages

Win Avr Interfacing

Uploaded by

Manasa c jois
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views22 pages

Win Avr Interfacing

Uploaded by

Manasa c jois
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

There are four main registers in Atmega 32 win avr

microcontroller.
1. Timer/counter register TCNTn (TCNT0, TCNT1, TCNT2)
A count value is loaded to this register before programming.

2. Timer/counter control register (TCCRn)


Used to set modes of operation of timers & clock source etc.,

3. Timer/counter Interrupt Flag regiser(TIFR)


Register supports checking for overflow flag status and output compare match
status

4. Output compare register (OCRn) :


The content of TCTn and OCRn are compared, when they are equal the output
compare Flag(OCFn) is set.
1. FOCO bit : Force compare output
match.
• It is write only bit.
• Writing 1 to it causes wave
generator to act as if a compare
match has occurred.

1. Com01 com00
• Compare output mode
• Controls the wave generator.
Timer/counter interrupt flag register
Steps to program timer 0 and
timer 2
• Load an appropriate count value to the TCNT0/2 register.

• Load a valid control word to TCCR0 register to program in Mode 0.

• Keep monitoring the TOVO flag in TIFR.

• Once it is set, stop the timer by loading the following code

• LDI R16, 0X00

• OUT TCCR0,R16

• Clear the TOVO flag for the next round.

• Go back to step 1
program to configure timer 0 on
mode 0
LDI R16, 1<<5 (0b 0010 0000) ; 5th bit of port B

OUT DDRB,R16 ; 5th bit of port B AS O/P

LDI R17, 0X00

OUT PORT B, R17

L1: RCALL DELAY

EOR R17, R16 ; TOGGLE THE 5TH BIT OF PORT B TO GENERATE SQUARE WAVE

OUT PORT B, R17

RJMP : L1
program to configure timer 0 on
mode 0
• DELAY PROGRAM USING TIMER
• LDI R20, OXF2 ; LOAD WITH SOME COUNT

• OUT TCNT0,R20

• LDI R20, 0X01 ; SET THE TIMER MODE

• OUT TCCR0,R20

L2 : IN R20, TIFR ; KEEP MONITORING TIFR

• SBIS R20, TOVO

• RJMP :L2

• LDI R20, 0X00

• OUT TCCR0, R20 ; STOP THE TIMER

• LDI R20, 0X01

• OUT TIFR, R20 ; CLEAR TOVO


program to configure timer 0 on mode 0 IN EMBEDDED C
# include <avr/io.h>
Void timer_dealy ( );
Int main()
{
DDRB = 0x20;
While(1)
{ timer_delay();
PORT B = PORT B ^0x20;
}
}
program to configure timer 0 on mode 0 IN EMBEDDED C

Void timer_dealy ( );
{
TCNT0 = 186;
TCCR0 = 0x01;
While(TIFR &(1<<TOVO)==0);
TCCR0=0x00;
TIFR = 0x01;
}
Timer 1 Modes of operation
Timer 1 Control Registers
Timer 1 Control Registers A
Timer 1 Control Registers B

1. ICNC1 : INPUT CAPTURE NOISE CANCELLAR


WHEN 0 : DISABLED
WHEN 1 : ENABLED

2. ICES1 : INPUT CAPTURE EDGE SELECTOR

WHEN 0 : RECONGNIZED ON FALLING EDGE OF THE CLOCK

WHEN 1 : RECOGNIZED ON RISING EDGE OF THE CLOCK


Win AVR interrupts
• Sources of interrupts in win AVR
• Two interrupts for each timers, one
for overflow, another for compare
match
• Three interrupts for external hard
ware
• Three interrupts for serial
communication
• The SPI interrupt
• The ADC interrupt
Win AVR interrupts
• The I bit of SREG must be set to 1 for enabling the interrupts.
• This is done through SEI instruction ( Set Interrupt).
• Cleared through CLI instruction.
• The bits of the TMSK register are used to enable and disable timer interrupts.
Win AVR interrupts
Win AVR interrupts
Win AVR interrupts
Win AVR interrupts
#include “avr/io.h”
#include “avr/interrupt.h”

Int main()
{
DDRB |=0x20; // set 5th bit as output
TCNT0 = -32;
TCCR0 = 0x01; // normal mode without pre scaler

TIMSK = (1<<TOIEO);
Sei (); // enable the interrupts

DDRC = 0x00; // make port c as input


DDRD =0xFF; // make port d as output

While(1)
Port D = PINC;

ISR (TIMER0_OVF_Vect)
{
TCNT0 = -32;
Port B ^=0x20;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy