Gast
#408238
Hi Leute,
bin so frei gewesen und habe mir das gute Stück Software vom
Peter Dannegger (Precise 1 Second Timebase) kopiert und versucht zu
modifizieren!
Danke an Peter, für diese ausgezeichnete Software und sorry das ich
einfach so genommen hab ;) !!
Dann habe ich das halt nen bisschen geändert und versucht an meine
Bedürfnisse anzupassen, ging aber schief.Versteh aber leider nicht ganz
genau was da alles passiert !
Kann einer von mir da eventuell auf die Sprünge helfen ?
Hier das originale Programm:
=============================================================
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.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 8000000L // 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
SIGNAL (SIG_OUTPUT_COMPARE1A)
{
/***********************************************************************
*/
/* Insert Key Debouncing Here */
/***********************************************************************
*/
#if XTAL % DEBOUNCE
OCR1A = XTAL / DEBOUNCE - 1; // compare DEBOUNCE - 1 times
#endif
if( --prescaler == 0 ){
prescaler = (uchar)DEBOUNCE;
second++; // exact one second over
#if XTAL % DEBOUNCE // handle remainder
OCR1A = XTAL / DEBOUNCE + XTAL % DEBOUNCE - 1; // compare once per
second
#endif
}
}
int main( void )
{
LED_DIR = 0xFF;
while( KEY_INPUT & 1 ); // start with key 0 pressed
TCCR1B = 1<<WGM12^1<<CS10; // divide by 1
// clear on compare
OCR1A = XTAL / DEBOUNCE - 1;
TCNT1 = 0;
second = 0;
prescaler = (uchar)DEBOUNCE;
TIMSK = 1<<OCIE1A;
sei();
for(;;){
if( second == 60 )
second = 0;
LED_DIR = second; // display second (binary)
}
}