inv-sw-32u4/src/inverter.c

46 lines
563 B
C

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "include/uart.h"
#include "include/timer.h"
uint8_t sec = 0;
uint16_t cnt = 0;
int main()
{
/* With this MCU frequency, it is 38,4k baud */
uart_init(12);
/* Make PB2 an output pin */
DDRB |= (1 << DDB2);
initCtcTimer0();
sei();
while (1) {
if ((PORTB & (1 << PB2)) > 1)
{
_delay_ms(1);
PORTB &= ~(1 << PB2);
}
if (cnt == 65500) {
printf("%u\n\r", TCNT0);
cnt = 0;
}
cnt++;
}
return 0;
}
ISR(TIMER0_COMPA_vect)
{
PORTB |= (1 << PB2);
}