;************************************************
;Pulsin TM1637.bas
;Roger LEGAT 18/09/2020
;Display Pulsin value on 4 LED Digit
;(1msec=1000 to 2msec=2000)
;Picaxe 08M2
;*************************************************
#Picaxe 08M2
; _ _
; Vcc o| U |o Gnd
; C.5 x| |x C.0
; Pulse C.4 >| |> C.1 DIO (Pullup actived)
; C.3 x|___|> C.2 CLK (Pullup actived)
;Setfreq m16
Setfreq m4 ; Default : Pulsin in msec
;Pins I/O ***************
Symbol Clk = C.2 : input C.2
Symbol Dio = C.1 : Output C.1
Symbol Pulse = C.4 : Input C.4
;Dirs=%01111
;Pullup %01100 ;Active R_Pullup sur C.1,C.2
; Real R.pullup on board recommanded !
;Bytes **********************
Symbol Pack = b0 ; Byte to send -> bit0 to bit7
Symbol i = b4 ; work variable
Symbol DIGIT1 = b6
Symbol DIGIT2 = b7
Symbol DIGIT3 = b8
Symbol DIGIT4 = b9
;Words *****************************
Symbol Value = w1 ; Value to display on 4 digit
;EEPROM( 0 1 2 3 4 5 6 7 8 9 10 )'Pos 10 = Blank
DATA 0, ($3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$00)
;**** Initialisation TM1637 *********************************
;Symbol TypeAdr=$40 ; auto increment addressing (Default)
Symbol AdrOrigin=$C0 ; Address of 1er digit
Symbol Brighness=$8C ; Brighness 69%
High Clk: High Dio: Low Dio ; I2CStart
Pack=Brighness ;Send Brighness level
Gosub I2CSendPack
Low Clk: Low Dio : High Clk : High Dio ;I2CStop
;== MAIN LOOP ===================================================
DO
Pulsin 1,Pulse,Value
Gosub SetDigit
LOOP
End
;=========================================================
;*** Sub-Routines ***************************************
;=========================================================
SetDigit:
bintoascii Value,b5,b6,b7,b8,b9 ; b5 not used (only 4 digit)
;Convert Ascii code to Nombre
b6=b6-48 ; Code Ascii of 0=48, of 1=49, of 2=50 ...
b7=b7-48
b8=b8-48
b9=b9-48
;Ready to send packs :))
;Adressing first digit
High Clk: High Dio: Low Dio ; I2CStart
Pack = AdrOrigin : Gosub I2CSendPack ; b0 (=AdrOrigin) is the first PACK to send
; ??? is it necessary to re-specify the brighness in the series ????
Read b6,b0 ; b0(now=b6 =DIGIT1) is the new PACK to send
If Pack = 0 then
Pack = 10 ; Blank only first digit if equal to zero
Endif
Gosub I2CSendPack
Read b7,b0 : Gosub I2CSendPack ; DIGIT2 b0(=b7) is the new PACK to send
Read b8,b0 : Gosub I2CSendPack ; DIGIT3 b0(=b8) is the new PACK to send
Read b9,b0 : Gosub I2CSendPack ; DIGIT4 b0(=b9) is the new PACK to send
Low Clk: Low Dio : High Clk : High Dio ;I2CStop
Return
;*** Sending Pack bit by bit, bit0 LSB first (Shiftout not supported by 08M2 !)
I2CSendPack:
For i=1 to 8
Low Clk
OutpinC.1 = bit0 ; DIO = bit0 of PACK
Pack = Pack/2 ;>>> shift right >>> bit1 becomes bit0
High Clk
Next i
Return