Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <avr/sleep.h>
- // seconds counter
- volatile uint8_t sec;
- // minutes counter
- volatile uint8_t min;
- ////////////////////////////////////////////////////////
- //
- // clock frequency = 4MHz
- //
- // 64 = prescaler clock
- //
- ////////////////////////////////////////////////////////
- int main(void){
- sec = 0; min = 0;
- // Set up CTC mode
- // Timer1 Control Register A
- TCCR1A |= 0;
- // Timer1 Control Register B
- // Prescaler = 64
- TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10);
- // Initialize Compare Value
- OCR1A = 62499;
- // Timer Interrupt Mask Register (common)
- // enable T1 compare interrupts
- TIMSK |= _BV(OCIE1A) | _BV(OCIE1B);
- sei(); // enable global interrupts
- while (1) {
- // just sleep while waiting
- sleep_enable();
- sleep_cpu();
- sleep_disable();
- }
- return 0;
- }
- ISR (TIMER1_COMPA_vect) {
- if(++sec >= 60) {
- sec = 0;
- min++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement