Gast
#75296
Hallo! Ich beschäftige mich erst seit kurzem mit Microcontrollern und meine erste Bekanntschaft ist die mit einem Atmel AVR ATMega128, allerdings wurden wir angewiesen, beim compilieren ATMega103 anzugeben, aus mir bisher unverständlichen Gründen. Aber wie auch immer, prinzipiell funktioniert alles wie es sollte. Ich wollte allerdings auch AVR Studio 4 zu Simulationen einsetzen und geniere mir daher ein .s-File, das allerdings Kommandos zu enthalten scheint, die das Studio nicht kennt. Wie ist das möglich? Das Studio kennt doch sowohl den ATMega128 als auch 103, und kompiliert habe ich immer mit avr-gcc. mfg Christian Der Vollständigkeit halber hier noch der Quellcode, das .s-File ist im Anhang. Im Endeffekt gibt es einen Kitt-artigen Effekt auf einem Bargraphen per simuliertem PWM. #include<io.h> #include<sig-avr.h> #include<stdlib.h> #include"DisplayExample.h" #include<interrupt.h> #include<inttypes.h> /*======================================*/ /* VARIABLES placed within SRAM memory */ /*======================================*/ uint8_t i = 0; uint8_t intcount = 0; uint8_t output = 0XFF; uint8_t values[] = {0, 0, 0, 0, 0, 0, 0, 0}; uint8_t temp[] = {0, 0, 0, 0, 0, 0, 0, 0}; void arraycount(k) { for(i = 0; i < 8; i++) { values[i] = 8-(abs(k-i)); } } void resettemp() { for(i = 0; i < 8; i++) { temp[i] = 0; } } void DisplayDigitAndPrepareNext() { if ((intcount & 0x0007)==0) { resettemp(); } for(i = 0; i < 8; i++) { if (temp[i] < values[i]) { temp[i]++; output=~output; output |= (1<<i); output=~output; } else { output |= (1<<i); } } } INTERRUPT(SIG_OUTPUT_COMPARE1A) { intcount++; outp(output,DISPL_DAT_OPORT); DisplayDigitAndPrepareNext(); } int main(void){ uint8_t count = 0; uint8_t k = 0; outp(0xFF,DISPL_DAT_OPORT); outp(0xFF,DISPL_DAT_DDR); sbi(TIMSK,OCIE1A); //enable output compare interrupts outp(0x20,OCR1AH); //time between writing out to LEDs outp(0x00,OCR1AL); //8192 = 555,76 us at 14,47 MHz count=0; sbi(TCCR1B,CS10); //counter reset after match with A (only timer/counter1) sbi(TCCR1B,CTC1); //starts counter sei(); // enable global interrupts count=1; //1 means count up, 0 means count down k=STARTVALUE; arraycount(k); DisplayDigitAndPrepareNext(); while(1) { if (intcount==225) { if (k==7) { count=0; } if (k==1) { count=1; } if (count==1) { k++; } else { k--; } intcount=0; arraycount(k); } } return 0; }