hello evryone ,
im new to mcu s expected about coding !
some years ago i made a rgd lamp with an attiny 2313 and i had no problems to compile the code which was given with the project!
last week i found a couple of attinys2313 an i wanted to use them in some rgb lamps ect!
i cant compile the code like back in the days!
hope u could help me to compile the code so that i can make a hex file !
the first error ist the excpected " before ) token
#define F_CPU 9600000UL
// handles falling edge of PWM on each LED
void abc(unsigned char a,unsigned char b,unsigned char c,unsigned char status);
unsigned char e; // software PWM clock
unsigned char pwm[3] = {255,255,255}; // current PWM widths
unsigned char to[3] = {255,255,255}; // target PWM widths
// main
int main(void) {
// outputs PORTB4, PORTB3, PORTB0
DDRB = 0b00011001;
// outputs on and pullup on PORTB1
// if driving the LED's anode, LEDs will be on
PORTB = 0b00011011;
// disable analog comparator
ACSR = (1<<ACD);
// enable INT0 interrupt (on low level, the default)
GIMSK = (1<<INT0);
// TIMER0 normal mode, prescaler 1, overflow interrupt enabled
// (will fire every 256 CPU cycles)
TCCR0A = 0x00;
TCCR0B = (1<<CS00);
TIMSK = (1<<TOIE0);
// enable interrupts
sei();
// forever
while(1){
// move actual PWM widths towards target widths
if (pwm[0])to[0]) pwm[0]--;
if (pwm[1])to[1]) pwm[1]--;
if (pwm[2])to[2]) pwm[2]--;
// once old targets reached
if(pwm[0]==to[0]&&pwm[1]==to[1]&&pwm[2]==to[2]) {
// select new random target PWM widths for all LEDs
to[0]=rand()%255;
to[1]=rand()%255;
to[2]=rand()%255;
}
// control speed of fading
_delay_ms(20);
} // forever
} // main
// software PWM
// frequency = F_CPU / 256 / 255
// = 96000000 / 256 / 255
// = 147.058823529 Hz
ISR(TIM0_OVF_vect) {
// imposes on 'e' a range of 0-254
if(e==255) {
// skip 255, wrap around to 0
e=0;
// start PWM cycle over by turning on all LEDs (if driving anode)
PORTB |= 0b00011001;
}
// turn off LEDs if their current width matches 'e' (if driving anode)
// NOTE: calling a function from within an ISR can incurr a large cycle
// penalty in the prologue and epilogue. since this ISR is called every
// 256 cycles, this can eat up available CPU rapidly. declaring called
// functions with the 'always_inline' attribute can help
abc(pwm[0],pwm[1],pwm[2],e);
// advance the software PWM clock
e++;
}
// handles falling edge of PWM on each LED
// clears each LED's ('a', 'b', or 'c') port bit on a match with 'status'
void abc(unsigned char a,unsigned char b,unsigned char c,unsigned char status) {
if((status==a)) PORTB&= ~(1<<3);
if((status==b)) PORTB&= ~(1<<4);
if((status==c)) PORTB&= ~(1<<0);
}
// button interrupt
ISR(INT0_vect) {
// turn on all LEDs (if driving anode)
PORTB |= 0b00011001;
// power down mode
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_mode();
/* mcu will sleep at this point forever, or until a reset */
// disable sleep mode
sleep_disable();
}
thank you already for your help