Syntax

' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' Uses LOOKUP to transfer a single digit value to a 7-segment LED.

' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ            4_000_000
ID              "LOOKUP"

' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------

LEDs            VAR     RB                      ' 7-segment display
TRIS_LEDs       VAR     TRIS_B

' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

value           VAR     Byte                    ' digit to display
tmpB1           VAR     Byte                    ' subroutine parameter

' =========================================================================
  PROGRAM Start
' =========================================================================

' -------------------------------------------------------------------------
' Subroutine Declarations
' -------------------------------------------------------------------------

PUT_DIGIT       SUB     1

' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  TRIS_LEDs = %00000000                         ' make LEDs outputs

Main:
  DO
    FOR value = 0 TO 16                         ' demo values (last invalid)
      LEDs = PUT_DIGIT value                    ' update the display
      PAUSE 1000                                ' pause one second
    NEXT
  LOOP

' -------------------------------------------------------------------------
' Subroutine Code
' -------------------------------------------------------------------------

' Use: destination = PUT_DIGIT value
' -- converts number in 'value' to 7-segment digit pattern
'    and places it in 'destination'

PUT_DIGIT:
  tmpB1 = __PARAM1                              ' copy value

  IF tmpB1 < $A THEN
    ' decimal
    LOOKUP tmpB1, $3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67, tmpB1
  ELSE
    IF tmpB1 < $10 THEN
      ' hex
      tmpB1 = tmpB1 - 10                        ' adjust for LOOKUP
      LOOKUP tmpB1, $77,$7C,$39,$5E,$79,$71, tmpB1
    ELSE
      tmpB1 = %01000000                         ' display dash
    ENDIF
  ENDIF
  RETURN tmpB1