Hello,
I'm writing the code for a fairly simple digital timer with a 2 digit multiplexed 7 segment display. I'm using a 32kHz crystal on timer2 to give me a timebase but i run into trouble before I even enable interrupts. As per the mega48 datasheet I put in a delay to allow th crystal to spin up before setting the timer to async mode. Heres the setup code:
static inline void hardwareSetup() { int i,j; //configure i/o pins DDRB = 0;//port b0-b3 i/p leave rest as i/p PORTB = 0b00001111;//configure pullups on port c0-c3 DDRC = 0b00110000;//port c0-c3 i/p c4,c5 o/p c6 config as reset PORTC =0b00001111;//configure pullups on port c0-c3 DDRD = 0xff;//port d all outputs //setup async timer for simple overflow interrupt interrupts at 128hz TIMSK2 = 0;//disable timer2 interrupts #ifndef NOLOOP PORTD = 0b00111111;//set display to show zeros for(i = 0; i<0x00ff;i++)//wait for clock to stabilize { for(j = 0;j < 0x00ff;j++) PORTD ^= 0b10000000;//mux display } #endif #ifndef DEBUG ASSR =(1<<AS2);//set AS2 bit in ASSR for async mode #endif TCCR2A = 0;//normal mode TCNT2 = 0;//clear timer //shut down unused peripherals ACSR =(1<<ACD);//disable comparator ADCSRA = (1<<ADEN);//dissable adc #ifndef DEBUG PRR =(1<<PRTWI)|(1<<PRTIM0)|(1<<PRTIM1)|(1<<PRSPI)|(1<<PRUSART0)|(1<<PRADC); set_sleep_mode(SLEEP_MODE_PWR_SAVE);//sleep mode in power save mode #endif while(ASSR & 0x0f);//wait for updates to finish return; }
The problem i have is that the AVR somehow gets stuck in the for loop section. It just sits there displaying a single zero which to me says that its not even multiplexing the display. If I lower the number on the outer loop to 0x0040 it works just fine. I feel like I'm missing something obvious but I can't tell what I'm doing wrong :oops: