// Target: m8515 #define OSC 4000000 #define BAUD 9600 //#define UBRR_BAUD ((OSC/(16*BAUD))-1) = 25,03... #define UBRR_BAUD 25 #include #include #include #include "usart.h" #ifndef OCR1A #define OCR1A OCR1 // 2313 support #endif #ifndef WGM12 #define WGM12 CTC1 // 2313 support #endif #ifndef PINC #define KEY_INPUT PIND // 2313 #else #define KEY_INPUT PINC // Mega8 #endif #define LED_DIR DDRB //#define XTAL 11059201L // nominal value #define XTAL 4000000L // after measuring deviation: 1.5s/d #define DEBOUNCE 256L // debounce clock (256Hz = 4msec) #define uchar unsigned char #define uint unsigned int uchar prescaler; uchar volatile second; // count seconds uchar volatile minuten; uchar volatile stunden; void usart_send(uint8_t data); SIGNAL (SIG_OUTPUT_COMPARE1A) { #if XTAL % DEBOUNCE OCR1A = XTAL / DEBOUNCE - 1; // compare DEBOUNCE - 1 times #endif if( --prescaler == 0 ){ prescaler = (uchar)DEBOUNCE; second++; // exact one second over usart_send(second); usart_send(minuten); usart_send(stunden); #if XTAL % DEBOUNCE // handle remainder OCR1A = XTAL / DEBOUNCE + XTAL % DEBOUNCE - 1; // compare once per second #endif } } int main( void ) { UBRRH = (unsigned char) (UBRR_BAUD>>8); UBRRL = (unsigned char) UBRR_BAUD; /* Aktivieren von transmitter */ UCSRB = (1<