Hello all!
I have an atmega168, and I want to count the time with a timer the time that one of my pins went high or low.
How do I do this?
I came up with the idea of a pin change interrupt, but I don't know how to do that.
I wrote the following code, but it is not working. It compile fine, but my idea does not works as I want.
#define F_CPU 14745600 #include#include #include #include #include #include #include "../delay.h" #include "../lcd.h" #include "../uart.h" // PIN DEFINITIONS: void setup() { EICRA = (1<<ISC11); PCMSK0 |= (1<<PC5); // turn on interrupts! EIMSK |= (1<<INT0); } volatile int32_t the_time; SIGNAL (SIG_INT0) { the_time++; } int main() { setup(); // init lcd lcd_init(); FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE); lcd_home(); // init serial port uart_init(); FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW); stdin = stdout = &uart_stream; // turn on interrupt handler sei(); while(1) { lcd_home(); fprintf_P(&lcd_stream, PSTR("%16.2f sec"), (double) the_time / 100.0); } return 0; }
Any ideas???
Thanks!!!