Toggle PD6 instead of PC7 when timer compare interrupt occurs.

Move timer interrupt routine to timer.c
Change timer parameters
This commit is contained in:
Marco 2022-05-13 01:24:38 +02:00
parent 510cba47b1
commit 3fd547f2ea
3 changed files with 15 additions and 12 deletions

View File

@ -97,8 +97,8 @@ void cmd_handle_switch(void)
{
int state = 0;
PORTC ^= (1<<PC7);
PORTD ^= (1<<PD6);
state = PORTC & (1 << PC7);
state = PORTD & (1 << PD6);
printf("Pin state is %i\r\n", state);
}

View File

@ -11,9 +11,11 @@ int main()
/* With this MCU frequency, it is 38,4k baud */
uart_init(12);
printf("Starting up!\r\n");
/* Make PB2 an output pin */
DDRB |= (1 << DDB2);
DDRC |= (1 << DDC7);
DDRD |= (1 << DDD6);
initCtcTimer0();
@ -28,9 +30,3 @@ int main()
return 0;
}
ISR(TIMER0_COMPA_vect)
{
PORTB |= (1 << PB2);
}

View File

@ -1,4 +1,6 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include "include/timer.h"
void initCtcTimer0(void)
@ -10,7 +12,7 @@ void initCtcTimer0(void)
TIMSK0 |= (1 << OCIE0A);
/* Select clock. Prescaler of 8 */
TCCR0B |= (1 << CS01);
TCCR0B |= (1 << CS02) | (1 << CS00);
/* Use CTC Mode */
TCCR0A |= (1 << WGM01);
@ -18,7 +20,7 @@ void initCtcTimer0(void)
/*
* OCR0A contains TOP value for counter:
*/
OCR0A = 25;
OCR0A = 100;
}
void initOverflowTimer0(void)
@ -35,3 +37,8 @@ void initOverflowTimer1(void)
TCCR1B |= (1<<CS11);
TIMSK1 |= (1<<TOIE1);
}
ISR(TIMER0_COMPA_vect)
{
PORTB |= (1 << PB2);
}