Win Avr Interfacing
Win Avr Interfacing
microcontroller.
1. Timer/counter register TCNTn (TCNT0, TCNT1, TCNT2)
A count value is loaded to this register before programming.
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.
• OUT TCCR0,R16
• 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
EOR R17, R16 ; TOGGLE THE 5TH BIT OF PORT B TO GENERATE SQUARE WAVE
RJMP : L1
program to configure timer 0 on
mode 0
• DELAY PROGRAM USING TIMER
• LDI R20, OXF2 ; LOAD WITH SOME COUNT
• OUT TCNT0,R20
• OUT TCCR0,R20
• RJMP :L2
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
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
While(1)
Port D = PINC;
ISR (TIMER0_OVF_Vect)
{
TCNT0 = -32;
Port B ^=0x20;
}