{{
''***********************************************
''*  Program 7.2X
''*  Author: Jon Titus 11-03-2014 Rev. 2
''*  Copyright 2014
''*  Released under Apache 2 license
''*  7-Segment code-test program.
''*  Display two digits with 2 multiplexed
''*  common-cathode 7-segment displays.
''*  A ULN2003A controls the cathode on each display.
''*  
''***********************************************
}}

CON _clkmode = xtal1 + pll16x           'Set MCU clock operation
    _xinfreq = 5_000_000                'Set for 5 MHz crystal
    
VAR
    byte segment_code[10]               'Storage for segment codes
    byte digit[8]                       'Storage for as many as 8 digits
    byte digit_count                    'Number of digits to display
    byte counter                        'Loop counter for digit display
    byte time_factor                    'Timing value for multiplexing
                                          
PUB Start                               'Main program starts here

segment_code[0] := %01111110       'Pattern for "0"
segment_code[1] := %00110000       'Pattern for "1"
segment_code[2] := %01101101       'Pattern for "2"
segment_code[3] := %01111001       'Pattern for "3"
segment_code[4] := %00110011       'Pattern for "4"
segment_code[5] := %01011011       'Pattern for "5"
segment_code[6] := %00011111       'Pattern for "6"
segment_code[7] := %01110000       'Pattern for "7"
segment_code[8] := %01111111       'Pattern for "8"
segment_code[9] := %01110011       'Pattern for "9"

digit[0] := 6                      'First digit to display
digit[1] := 1                      'Second digit to display
                                   'Eight digits maximum

digit_count := 2                   'Number of digits to display, 1 to 8 only

time_factor := 1                   'Change as needed, 1 to 255 only

dira[15..8] := %11111111           'Set eight output pins for segments
dira[27..26] := %11                'Set 2 outputs to control cathodes
outa[26..27] := %00                'Turn off cathodes to start

  repeat                           'Main loop
     
     repeat counter from 0 to digit_count-1        'Set upper digit count
       outa[15..8] := segment_code[digit[counter]] 'Get segment pattern for
                                                   '    digit
       outa[26 + counter] := %1                    'Turn on associated display
       waitcnt(clkfreq/time_factor + cnt)          'Delay
       outa[26 + counter] := %0                    'Turn off associated
                                                   '    display

