Go Down

Topic: Aiuto per compilazione STK500boot.c (Read 6 times) previous topic - next topic

leo72

Il seguente codice crea un contamillisecondi agganciato al timer 2.
Basta mettere una chiamata a setTimer2 per attivare il timer, che aggancia un interrupt alla ISR TIMER2_OVF_vect, la quale aggiorna ms. Inserisci il codice da qualche parte nel bootloader.
Code: [Select]

volatile unsigned int ms=0;

//set timer 2 to use it in combination with the Real-Time Counter module
void setTimer2() {
    TIMSK2 &= ~(1<<TOIE2);
    TIMSK2 &= ~((1<<OCIE2A) | (1<<OCIE2B));
    ASSR &= ~(1<<AS2);
    TCCR2A &= ~((1<<WGM21) | (1<<WGM20));
    TCCR2B &= ~(1<<WGM22);
    TCCR2B |= (1<<CS22);
    TCCR2B &= ~((1<<CS21) | (1<<CS20));
    TCNT2=6;
    TIMSK2 |= (1<<TOIE2);
    SREG|=1<<SREG_I;
}


//Interrupt Routine: this manipulates the software RTC
ISR(TIMER2_OVF_vect) {
    ms++;
}

Questo codice mi pare occupi solo 46 byte, compilato su un Mega2560.

Giorgio

non riesco.. dovunque la metto mi rifila una sfilza di 22 errori.

leo72

La dichiarazione della variabile va in testa, fra quelle globali. Le altre 2 funzioni in un punto qualunque del codice. Ma che errori ti da?

Giorgio

Eccoli qui.
Tra un po butto fuori tutto dalla finestra.
(Ringrazio davvero tutti per la gentilezza e pazienza però...)

Code: [Select]
Build started 25.5.2012 at 16:42:55
../stk500boot.c: In function 'setTimer2':
../stk500boot.c:512:1: error: stray '\240' in program
../stk500boot.c:512:1: error: stray '\240' in program
../stk500boot.c:513:1: error: stray '\240' in program
../stk500boot.c:513:1: error: stray '\240' in program
../stk500boot.c:514:1: error: stray '\240' in program
../stk500boot.c:514:1: error: stray '\240' in program
../stk500boot.c:515:1: error: stray '\240' in program
../stk500boot.c:515:1: error: stray '\240' in program
../stk500boot.c:516:1: error: stray '\240' in program
../stk500boot.c:516:1: error: stray '\240' in program
../stk500boot.c:517:1: error: stray '\240' in program
../stk500boot.c:517:1: error: stray '\240' in program
../stk500boot.c:518:1: error: stray '\240' in program
../stk500boot.c:518:1: error: stray '\240' in program
../stk500boot.c:519:1: error: stray '\240' in program
../stk500boot.c:519:1: error: stray '\240' in program
../stk500boot.c:520:1: error: stray '\240' in program
../stk500boot.c:520:1: error: stray '\240' in program
../stk500boot.c:521:1: error: stray '\240' in program
../stk500boot.c:521:1: error: stray '\240' in program
../stk500boot.c: In function 'main':
../stk500boot.c:526:1: error: static declaration of '__vector_15' follows non-static declaration
../stk500boot.c:526:1: note: previous declaration of '__vector_15' was here
../stk500boot.c: In function '__vector_15':
../stk500boot.c:527:1: error: stray '\240' in program
../stk500boot.c:527:1: error: stray '\240' in program
../stk500boot.c: In function 'PrintFromPROGMEM':
../stk500boot.c:1169:13: warning: cast from pointer to integer of different size
../stk500boot.c: In function 'DumpHex':
../stk500boot.c:1419:34: warning: cast to pointer from integer of different size
../stk500boot.c: In function 'EEPROMtest':
../stk500boot.c:1462:21: warning: cast from pointer to integer of different size
../stk500boot.c:1483:21: warning: cast from pointer to integer of different size
In file included from ../stk500boot.c:1514:0:
../avrinterruptnames.h: At top level:
../avrinterruptnames.h:312:0: warning: ignoring #pragma mark __AVR_ATmega169__
../avrinterruptnames.h:351:0: warning: ignoring #pragma mark __AVR_ATmega640__
../stk500boot.c: In function 'VectorDisplay':
../stk500boot.c:1623:19: warning: cast from pointer to integer of different size
../stk500boot.c:1624:20: warning: cast to pointer from integer of different size
make: *** [stk500boot.o] Error 1
Build failed with 23 errors and 8 warnings...

leo72

Siccome adesso non sono a casa ed ho fatto un copia & incolla di un codice preso da un mio file generato su Linux ed elaborato su Windows, non vorrei che fosse passato qualche carattere unicode. Togli tutti gli spazi prima delle righe di codice, forse sono tabulazioni e non spazi.

Poi pare che ci sia già una dichiarazione di utilizzo dello stesso vettore ISR...

Go Up