Hello,
Below is some PBP3 code - to control a 4 digit 7-Segment display - driven by a TM1637
The basic flow was written by a previous submitter (My sincere thanks!)
I added functionality to display any specific 4-digit number

The eventual goal is to have the 12F683 receive a value via soft_serial and display it.
A kind of serial-to-7segment backpack - if you will

If anyone feels inclined to add that functionality - please do!!
We can all benefit from the results :-]

'================================================= =============================
' Compiler: PBP3
' Device: PIC12F683
' Description: 4 digit 7-Segment Display with TM1637 driver
' Device Oscillator: 8MHz internal
' MCLR off

'1 VDD
'2 GP5/T1CKI/OSC1/CLKIN
'3 GP4/AN3/T1G/OSC2/CLKOUT
'4 GP3/MCLR/VPP
'5 GP2/AN2/T0CKI/INT/COUT/CCP1
'6 GP1/AN1/CIN-/VREF/ICSPCLK
'7 GP0/AN0/CIN+/ICSPDAT/ULPWU
'8 VSS

'TM1637 NOTES:
'Displaying any value requires 4 transactions
'Each transaction incorporates a specific byte sent to the TM1637
'A startcondition alerts TM1637 to be ready for a byte transaction
'A stopcondition alerts TM1637 transaction byte is complete
'1st transaction byte value must = x40
'2nd transaction byte value designates which digit to display 192-195 = digit A-D
'3rd transaction byte value designates which segments turned on
'4th transaction byte value stipulates brightness 0-7


#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
#ENDCONFIG

'INTCON = %10001000 'Internal oscillator
OSCCON = %01110101 'Sets internal osc to 8 Mhz (Default) and stable
ANSEL = 0 ' Set all digital
CMCON0 = 7 ' Analog comparators off
TRISIO = %0010000 'set all pin output
'OPTION_REG.7 = 0 ' Enable internal pull ups

DEFINE OSC 8

'INIT Variables
DIO var GPIO.0
CLK var GPIO.1
TrisDIO VAR TRISIO.0
LED con 2
B0 var word
'B1 var byte
DispNum var byte
Cnt var byte
ByteToSend var byte 'Command or Data byte to be sent
DispCmd var byte
Brt8Cmd var byte
cntr var byte
TempNum var word
digitnum var byte[3]
Dig1Addr var byte
displaynums var byte

dispcmd = 64 '0x40
brt8cmd = 136 'Display brightness
'136 = mid bright 10001000
'143 = very bright 10001111

'Diagnostic routine
'DiagRoutine:
'CLK = 1
'for cnt = 1 to 10 'Blink LED 4 times.
'HIGH LED
'pause 100
'low LED
'pause 100
'next cnt

goto MAIN

'===================== *** StartCondition *** ======================
StartCondition:
clk = 0
dio = 1
clk = 1
pauseus 50
dio = 0 'DIO goes low when CLK is high.
pauseus 50
return

'====================== *** SendTheByte *** ==========================
SendTheByte:
clk = 0
for cnt = 0 to 7 'Send 8 bits of data, starting with the LSB.
dio = bytetosend.0(cnt)
pauseus 50
clk = 1
pauseus 50
clk = 0
Next cnt

dio = 1
Trisdio = 1 ' Set Data pin direction to input to receive ACK.
pauseus 50
clk = 1
pauseus 50
clk = 0
Trisdio = 0 ' Set Data pin direction back to output.
return

'======================= *** StopCondition *** ========================
StopCondition:
clk = 0
dio = 0
clk = 1
pauseus 50
dio = 1 'DIO goes high when CLK is high.
pauseus 50
return

'========================== *** MAIN *** =============================
MAIN:

'what number do we want the system to display
B0 = 9000

' Ascertain number of digits to be displayed
if B0 >= 0 THEN cntr = 1
if B0 > 9 then cntr = 2
if B0 > 99 then cntr = 3
if B0 > 999 then cntr = 4

TempNum = B0

'Ascertain 1st digit value to be displayed
if cntr > 3 then
digitnum[0] = TempNum / 1000
TempNum = TempNum - (digitnum[0] * 1000)
else
digitnum[0] = 0
endif

'Ascertain 2nd digit value to be displayed
if cntr > 2 then
digitnum[1] = TempNum / 100
TempNum = TempNum - (digitnum[1] * 100)
else
digitnum[1] = 0
endif

'Ascertain 3rd digit value to be displayed
if cntr > 1 then
digitnum[2] = TempNum / 10
TempNum = TempNum - (digitnum[2] * 10)
else
digitnum[2] = 0
endif

'Ascertain 4th digit value to be displayed
if cntr > 0 then
digitnum[3] = TempNum
else
digitnum[3] = 0
endif

for displaynums = 0 to 3
dig1addr = 192 + displaynums

LOOKUP digitnum[displaynums],[63,48,91,79,102,109,125,7,127,111],dispnum

'Values which produce segments for numbers 0-9
'0: 63
'1: 48
'2: 91
'3: 79
'4: 102
'5: 109
'6: 125
'7: 7
'8: 127
'9: 111

'================== Display 4 digits ========================
'1st transaction value must always be x40
bytetosend = 64
gosub startcondition
gosub sendthebyte
gosub stopcondition

'2nd transaction value must be which digit (A-D)to update
' The following values represent which digit
' One of these valuse will be loaded into Dig1Addr
' 192 = 11000000 digit A
' 193 = 11000000 digit B
' 194 - 10100000 digit C
' 195 - 10010000 digit D

bytetosend = Dig1Addr
gosub startcondition
gosub sendthebyte

' 3rd transaction value represents which number to display
' within the designated digit
bytetosend = dispnum
gosub sendthebyte
gosub stopcondition

' 4th transaction value stipulates LED brightness
bytetosend = brt8cmd
gosub startcondition
gosub sendthebyte
gosub stopcondition


next displaynums
pause 1000
'next B0




END