'============================================================================
'=  Simple IN-16 nixie tube clock with multiplexed segments, low part count =
'=             Shortest Nixie Bascom code available on the net              =
'=                                                                          =
'=                    Copyright Evertdekker.com 2011                        =
'=                    Code Created with Bascom 2.0.7.1                      =
'============================================================================

$regfile = "M88pdef.dat"
$crystal = 1000000                                          'Internal 8mhz div/8
$hwstack = 32
$swstack = 64
$framesize = 16


Config Clock = Soft                                         'Use the softclock, 32.768KHz crystal connected to tosc1/2
Config Date = Dmy , Separator = -
Enable Interrupts
Date$ = "15-03-11"
Time$ = "12:15:45"

'== Setup hardware ==
Digit Alias Portc
Config Digit = Output                                       'Set up portc as output for the digit
Ddrd = &B00111111                                           'Setup portd as output for the segment and keep bit6&7 free for other use
Button_hr Alias Pinb.0
Button_min Alias Pinb.1
Config Button_hr = Input
Config Button_min = Input                                   'Set buttons as input
Set Portb.0
Set Portb.1                                                 'Switch on the pullup for the buttons

Dim Multiplex As Byte
Multiplex = 1                                               'Multiplexer starts with 1

Do

Select Case Multiplex
 Case 1 : Digit = _sec Mod 10                               'Seconds
 Case 2 : Digit = _sec / 10                                 'Seconds tens
 Case 4 : Digit = _min Mod 10                               'Minute
 Case 8 : Digit = _min / 10                                 'Minute tens
 Case 16 : Digit = _hour Mod 10                             'Hour
 Case 32 : Digit = _hour / 10                               'Hour tens
End Select

Portd = &B11000000 Or Multiplex                             'Switch on one tube
Waitms 2                                                    'Some delay to slow down the multiplexer

If Multiplex < 32 Then                                      'Shift the multiplexer one bit to the left until all 6 segments are done
 Shift Multiplex , Left , 1
Else
 Multiplex = 1                                              'Start over again at segment 1
End If

Debounce Button_min , 0 , Setminute , Sub                   'One of the buttons pressed, jump to the sub to change the time
Debounce Button_hr , 0 , Sethour , Sub

Loop
End

'=== Subs ===
Setminute:
 Incr _min
 If _min > 59 Then _min = 0
Return

Sethour:
 Incr _hour
 If _hour > 23 Then _hour = 0
Return