I use timer1 to multiplex a 4 digit, led display, read switches on the segment bus and to increment a counter to keep track of time.
I also use Delay() and Tone().
I set up the timer1 in the sketch.
The counter in the interrupt routine is used to time how long a switch is pushed closed.
When I compile the Sketch with IDE 1.6.5 everything works as it should.
When I compile the Sketch with IDE 1.8.5 (which it does with no errors), when I push a switch, the program locks up.
Anyone know why there would be a difference between the two versions of the IDE when compiling the timed switch routine? I'm starting to believe it assigns the delay function to a different timer in 1.8 then it did in 1.6. I guess I'll just have to try different timers for my display until I find the one which is free again.
This was so much easier when I wrote directly in Assembly and knew exactly what was going on!
ISR (TIMER1_COMPA_vect) {TIMER1_SERVICE_ROUTINE();}
noInterrupts();
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 238;
TCCR1B = 0x0b;
TIMSK1 |= (1 << OCIE1A);
interrupts();
void TIMER1_SERVICE_ROUTINE()
{
++tcount;
++ digit_counter;
if (digit_counter == 6 ) {(digit_counter = 1);}
switch(digit_counter)
-
-//write four digits
-
-
case 5: //this reads the switches which are on the display segment bus (and isolated with diodes)
digitalWrite(SLED4, LOW);
DDRD = 0x00;
PORTD= 0Xff;
digitalWrite(8, LOW);
for (int i = 0; i < 10; i++) {sw_inputs = PIND;} //read the switches 10 times to debounce
digitalWrite(8, HIGH);
break;
}
void timebutton()
{
duration = 0; //clear button duration counter
time0 = tcount; //set base time to current counter value
do {time1 = tcount; duration = time1- time0; //calculate how long the button has been pushed
if (duration > 1000) {digit4 = LED_n; digit3 = 0xff; digit2 = 0xff; digit1 = 0xff;} //1 second push message
if (duration > 2000) {digit4 = LED_C; digit3 = LED_N_0; digit2 = LED_d; digit1 = LED_E;}
delay(1); //for some reason a delay call has to be done here or it locks up.
}
while (bitRead(sw_inputs,R_sw) == 0); // wait until the bit goes high.
duration = time1- time0;
if (duration >2000){int_cw_mode(); duration = 0;}
if (duration >1000){Memory(); duration = 0;}
if (duration >50) {RIT(); duration = 0;}
}