I'm trying to make my code work easily for different pin-compatible chips. I did my prototyping on an ATmega168 and have moved to an ATmega8 but would like to make the code work for both.
The only difference is register names for timers and interrupts. I'm trying to use a conditional block at the top to read in the MCU definition from the makefile and define register names accordingly. Here's what I've come up with:
#if MCU == atmega8 //ATmega8 //INT0 register definitions #define EXT_INT_CONTROL MCUCR #define EXT_INT_SELECT GICR //Timer0 register definitions #define TIMER0_CTRL_REG TCCR0 #define TIMER0_INT_MASK TIMSK //Timer2 register definitions #define TIMER2_CTRL_REG TCCR2 #define TIMER2_INT_MASK TIMSK #elif MCU == atmega168 //ATmega168 //INT0 register definitions #define EXT_INT_CONTROL EICRA #define EXT_INT_SELECT EIMSK //Timer0 register definitions #define TIMER0_CTRL_REG TCCR0B #define TIMER0_INT_MASK TIMSK0 //Timer2 register definitions #define TIMER2_CTRL_REG TCCR2B #define TIMER2_INT_MASK TIMSK2 #endif
Works fine if MCU is atmega8, but when I change it atmega168 the #elif condition isn't working as you can see by the compiler errors:
Compiling: ping-pong-clock.c avr-gcc -c -mmcu=atmega168 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=ping-pong-clock.lst -std=gnu99 ping-pong-clock.c -o ping-pong-clock.o ping-pong-clock.c: In function "˜init': ping-pong-clock.c:250: error: "˜GICR' undeclared (first use in this function) ping-pong-clock.c:250: error: (Each undeclared identifier is reported only once ping-pong-clock.c:250: error: for each function it appears in.) ping-pong-clock.c: In function "˜initTimers': ping-pong-clock.c:267: error: "˜TIMSK' undeclared (first use in this function) ping-pong-clock.c:268: error: "˜TCCR0' undeclared (first use in this function) ping-pong-clock.c:271: error: "˜TCCR2' undeclared (first use in this function) make: *** [ping-pong-clock.o] Error 1
Any idea if there's a way to get this working?