/***********************************************************************
* skeletron
***********************************************************************
* Function: skeletron for future projects
* Set-Up: RXD=PD0,TXD=PD1,Speaker=PC0,SDA=PC4,SCL=PC5
***********************************************************************
* Processor: ATmega168 Automotive
* Clock: 3686400 Hz ( 3.7 MHz )
* Language: ANSI-C
* Compiler: avr-gcc/4.1.3, avr-libc
* Date: $LastChangedDate$
* Author: $LastChangedBy$
* Programmer: SP12
* ID: $Id$
***********************************************************************
* License: Creative Commons Attribution-Share Alike 3.0 Germany
*
* Copyright: 2009, Soeren Kornetzki
* Attribution: You are not allowed to remove any license, copyright or
* attribution notice. In addition you have to inform your
* users about the using of this sourc code ( bundle ) in
* the following form ( you are allowed to translate ):
* This software is using #SourceCodeBundleName#
* library created by Soeren Kornetzki (
* http://dev5-media.de ) licensed under the creative
* commons attribution-share alike 3.0 german license.
* Replace #SourceCodeBundleName# with the source code
* bundle name.
**********************************************************************/
/* define clock frequency of the main processor, if not defined */
#ifndef F_CPU
#define F_CPU 3686400UL
#endif
/* include librarys */
#include
#include
#include
#include
/* global variables */
volatile uint16_t t2ticks = 0;
/* prototypes */
void hw_init( void );
void t2_init( void );
/* main routine */
int main( void )
{
cli(); /* disable interrupts */
hw_init(); /* initialize hardware */
sei(); /* enable interrupts */
/* main loop */
while( 1 )
{
/* default sleep mode until ADC, Timer2, ext level Int, TWI Addr match, Brown Out, ext Reset or Watchdog triggers */
sleep_mode();
/* do sth. in TIMER2_COMP_vect */
/* why does nothing happend here? Device should wake-up after TIMER2_COMPA_vect */
PORTC ^= _BV( PC1 );
}
return 0;
}
/* initialize processor ports, default sleep mode, hardbeat Timer2 and others */
void hw_init( void )
{
/* configure PORTD */
DDRD = 0x00000000;
PORTC = 0x00000000;
/* configure PORTB */
DDRB = 0x00000000;
PORTB = 0x00000000;
/* configure PORTC */
DDRC = 0x00000011;
PORTC = 0x00000000;
/* set sleep mode to ADC Noise Reduction */
set_sleep_mode( SLEEP_MODE_PWR_SAVE );
/* initialize and start ms hardbeat Timer2 */
t2_init();
}
/* initialize Timer2 to trigger every millisecond */
void t2_init( void )
{
/* TODO: initialize Timer2 */
TCCR2A = ( _BV( COM2A0 ) | _BV( WGM21 ) ); /* CTC */
TCCR2B = ( _BV( CS21 ) | _BV( CS20 ) ); /* clkT2S/32 */
OCR2A = 115; /* Timer2 compare value A */
TIMSK2 = ( _BV( OCIE2A ) ); /* interrupt on Timer2 compare A match */
}
/* TIMER2_COMP_vect called every millisecond */
ISR( TIMER2_COMPA_vect )
{
/* TODO: do sth. */
if( ++t2ticks >= 100 )
{
PORTC ^= _BV( PC0 ); /* toggle Port C Pin 0 */
t2ticks = 0;
}
}