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