Skip to content

Instantly share code, notes, and snippets.

View mkleemann's full-sized avatar

Matthias Kleemann mkleemann

View GitHub Profile
@mkleemann
mkleemann / AVR_sleep_and_wakeup.c
Created January 31, 2012 18:52
ATmega8 power down and wakeup example
/* ATmega8 with internal 4Mhz clock (6cycle + 64ms) */
#include <avr/io.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <util/delay.h>
int main(void)
{
DDRC |= (1 << PC2) | (1 << PC1); // leds for testing
@mkleemann
mkleemann / atmega8_timer0.c
Created January 2, 2012 20:52
atmega8 timer0 - use overflow interrupt
// All values/comments are valid with ATmega8 running at Fosc = 4.000MHz
#include <avr/io.h>
#include <avr/interrupt.h>
// TIMER0 with prescaler clkI/O/1024
#define TIMER0_PRESCALER (1 << CS02) | (1 << CS00)
void main()
@mkleemann
mkleemann / atmega8_timer1.c
Created January 2, 2012 20:51
atmega8 timer1 - use 16-bit compare with ICR (input capture interrupt) for long periods of time
// All values/comments are valid with ATmega8 running at Fosc = 4.000MHz
#include <avr/io.h>
#include <avr/interrupt.h>
// TIMER1 with prescaler clkI/O/1024
#define TIMER1_PRESCALER (1 << CS12) | (1 << CS10)
// ~15s (4MHz@1024 prescale value)
#define TIMER1_COMPARE_VALUE 0xE4E1
@mkleemann
mkleemann / atmega8_timer2.c
Created January 2, 2012 20:49
atmega8 timer2 - use CTC/output compare interrupt w/o usage of OC2 pin
// All values/comments are valid with ATmega8 running at Fosc = 4.000MHz
#include <avr/io.h>
#include <avr/interrupt.h>
// TIMER2 with prescaler clkT2S/1024
#define TIMER2_PRESCALER (1 << CS22) | (1 << CS21) | (1 << CS20)
// TIMER2 output compare value
// --> value 98 is 25.088ms (4MHz@1024 prescale factor)