Device 16F877
Xtal = 4
Dim Number As Byte
Initialization:
TRISB = %00000000 ' Make PORTB all outputs
Number = 0 '
Main:
Number = 0
Repeat ' Create a loop
Inc Number ' Increment the Number register
GoSub Encode_Segment_Display ' Convert to segment data and display it
DelaymS 500 ' Small delay to slow down counting
Until Number = 4 ' Loop until number = 4, then reset
Goto Main ' Loop forever
Encode_Segment_Display:
SELECT Number
CASE 1
PORTB = %01110110
CASE 2
PORTB = %01111001
CASE 3
PORTB = %00111000
CASE 4
PORTB = %01110011
ENDSELECT
Return