$regfile = "attiny2313.dat" $crystal = 8000000 config portb = output 'sets PortB to output config portd = output 'sets PortD to output pind.2 = 1 'enables the internal pull-up resistor dim i as byte dim digit(4) as byte dim displ(4) as byte dim storage(4) as eram byte dim ex(4) as byte ex(1) = 3 'sets pins 3 to 6 of PortD to drive the digits ex(2) = 4 ex(3) = 5 ex(4) = 6 digit(1) = storage(1) 'recals the last value from the eeprom digit(2) = storage(2) digit(3) = storage(3) digit(4) = storage(4) Enable Interrupts 'enables the interrupts and defines the label for the routine Enable Int0 On Int0 button portd = 255 'blanks the display portb = 0 do for i = 1 to 4 'multiplexing the 4 digits and showing the correct values portb = displ(i) portd.ex(i) = 0 waitms 1 portd.ex(i) = 1 next loop end button: 'on interrupt 'blank display portd = 255 While pind.2 = 0 'debounce wend incr digit(2) 'increase the value by 1 if digit(1) > 9 then incr digit(2) digit(1) = 0 end if if digit(2) > 9 then incr digit(3) digit(2) = 0 end if if digit(3) > 9 then incr digit(4) digit(3) = 0 end if if digit(4) > 9 then digit(4) = 0 end if storage(1) = digit(1) 'store in eeprom storage(2) = digit(2) storage(3) = digit(3) storage(4) = digit(4) displ(1) = lookup(digit(1), Dta) 'Lookup the right value for portb in the data table displ(2) = lookup(digit(2), Dta) displ(3) = lookup(digit(3), Dta) displ(4) = lookup(digit(4), Dta) waitms 250 'debounce While pind.2 = 0 wend return Dta: 'values for portb to display 0 to 9 data 123, 9, 227, 203, 153, 218, 250, 11, 251, 219