Dim digit As Byte 'input variable for GETMASK subroutine
Dim digit1 As Byte 'current high digit
Dim digit2 As Byte 'current low digit
Dim mask As Byte 'output variable from GETMASK subroutine
Dim mask1 As Byte 'current high digit mask
Dim mask2 As Byte 'current low digit mask
Dim i As Byte
Symbol d1enable = PORTC.0 'enable line for higher 7-segment display
Symbol d2enable = PORTC.1 'enable line for lower 7-segment display
TRISB = %00000000 'set PORTB pins as outputs
TRISC.0 = 0 'set RC0 pin as output
TRISC.1 = 0 'set RC1 pin as output
TRISD = %11111111 'Set port D to input
d1enable = True
d2enable = True
mask1 = 0
mask2 = 0
loop:
For i = 0 To 255
digit1 = PORTD 'get current high digit
digit2 = ShiftLeft(PORTD, 4) 'get current low digit
digit = digit1
Gosub getmask 'get mask for high digit
mask1 = mask
digit = digit2
Gosub getmask 'get mask for low digit
mask2 = mask
Gosub show1 'display new mask
Gosub show2 'display new mask
WaitUs 500 'delay interval suitable for simulation
'use large delay for the real device, say WAITMS 500
Next i
Goto loop
End
getmask: 'get appropriate 7-segment mask for input digit
mask = LookUp(0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71), digit
Return
show1: 'show high digit on its display
PORTB = mask1
Return
show2: 'show low digit on its display
PORTB = mask2
Return