Easy 4 digit LED display

pxgator

Senior Member
#1
The TM1637 LED display is widely available, cheap, and an easy way to add a four
digit LED display to a PICAXE project. Borrowing code from the link below I wrote
a version which runs much faster and the code size is reduced. It has been tested from
4 to 32 mhz on M2 parts and also at 64 mhz on X2 parts. The code could be made
to run even faster by converting the subroutines to macros.

http://www.picaxeforum.co.uk/showth...-7-segment-displays-(TM1637)&highlight=tm1637


Code:
[color=Green];TM1637_test.bas[/color]

[color=Navy]#picaxe [/color][color=Black]08m2[/color]

[color=Green];segment data for TM1637
     ;(  0   1   2   3   4   5   6   7   8   9   A   b   C   d   E   F  dash blank)[/color]
[color=Blue]DATA [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]([/color][color=Navy]$3f[/color][color=Black],[/color][color=Navy]$06[/color][color=Black],[/color][color=Navy]$5b[/color][color=Black],[/color][color=Navy]$4f[/color][color=Black],[/color][color=Navy]$66[/color][color=Black],[/color][color=Navy]$6d[/color][color=Black],[/color][color=Navy]$7d[/color][color=Black],[/color][color=Navy]$07[/color][color=Black],[/color][color=Navy]$7f[/color][color=Black],[/color][color=Navy]$6f[/color][color=Black],[/color][color=Navy]$77[/color][color=Black],[/color][color=Navy]$7c[/color][color=Black],[/color][color=Navy]$39[/color][color=Black],[/color][color=Navy]$5e[/color][color=Black],[/color][color=Navy]$79[/color][color=Black],[/color][color=Navy]$71[/color][color=Black], [/color][color=Navy]$40[/color][color=Black], [/color][color=Navy]$00[/color][color=Blue])[/color]


[color=Green];for TM1637[/color]
[color=Blue]symbol dio [/color][color=DarkCyan]= [/color][color=Blue]C.1                        [/color][color=Green];TM1637 data pin to 08m2 leg 6[/color]
[color=Blue]symbol clk [/color][color=DarkCyan]= [/color][color=Blue]C.2                        [/color][color=Green];TM1637 clock pin to 08m2 leg 5[/color]
[color=Blue]symbol  [/color][color=Purple]D3 [/color][color=DarkCyan]= [/color][color=Purple]b2[/color]
[color=Blue]symbol  [/color][color=Purple]D2 [/color][color=DarkCyan]= [/color][color=Purple]b3                         [/color][color=Green];for all 4 digits[/color]
[color=Blue]symbol  [/color][color=Purple]D1 [/color][color=DarkCyan]= [/color][color=Purple]b4[/color]
[color=Blue]symbol  [/color][color=Purple]D0 [/color][color=DarkCyan]= [/color][color=Purple]b5[/color]


[color=Blue]gosub [/color][color=Black]brightness                        [/color][color=Green];set display brightness[/color]

[color=Blue]for [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]17                        [/color][color=Green];sequence thru all character
  [/color][color=Purple]D3 [/color][color=DarkCyan]= [/color][color=Purple]b1[/color][color=Black]:[/color][color=Purple]D2 [/color][color=DarkCyan]= [/color][color=Purple]b1                       [/color][color=Green];bytes stored in the data 
  [/color][color=Purple]D1 [/color][color=DarkCyan]= [/color][color=Purple]b1[/color][color=Black]:[/color][color=Purple]D0 [/color][color=DarkCyan]= [/color][color=Purple]b1
  [/color][color=Blue]gosub [/color][color=Black]DISPLAY
  [/color][color=Blue]pause [/color][color=Navy]1000[/color]
[color=Blue]next [/color][color=Purple]b1[/color]
[color=Blue]end[/color]

[color=Green];===========================================================================  

;Group of subroutines to read the values from data and output to the display[/color]

[color=Black]DISPLAY:
  [/color][color=Green];Enable sequential movement (from one digit to next)
  [/color][color=Blue]call [/color][color=Black]i2CStart
  [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]$40
  [/color][color=Blue]call [/color][color=Black]i2CWrByte
  [/color][color=Blue]call [/color][color=Black]i2CStop
  
  [/color][color=Green];Move to first digit
  [/color][color=Blue]call [/color][color=Black]i2CStart 
  [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]$C0
  [/color][color=Blue]call [/color][color=Black]i2CWrByte

  [/color][color=Green];First value
  [/color][color=Blue]read [/color][color=Purple]D3[/color][color=Black],[/color][color=Purple]b0
  [/color][color=Blue]call [/color][color=Black]i2CWrByte
  
  [/color][color=Green];Second value
  [/color][color=Blue]read [/color][color=Purple]D2[/color][color=Black],[/color][color=Purple]b0
  [/color][color=Blue]if [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Navy]17 [/color][color=Blue]then                                         
  [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Purple]b0 [/color][color=DarkCyan]+ [/color][color=Navy]128                         [/color][color=Green];add 128 to turn on colon
  [/color][color=Blue]endif                                             
  call [/color][color=Black]i2CWrByte              

  [/color][color=Green];Third value
  [/color][color=Blue]read [/color][color=Purple]D1[/color][color=Black],[/color][color=Purple]b0
  [/color][color=Blue]call [/color][color=Black]i2CWrByte

  [/color][color=Green];Fourth value
  [/color][color=Blue]read [/color][color=Purple]D0[/color][color=Black],[/color][color=Purple]b0
  [/color][color=Blue]call [/color][color=Black]i2CWrByte
  
  [/color][color=Blue]call [/color][color=Black]i2CStop
  [/color][color=Blue]return[/color]

[color=Black]i2CStart:
  [/color][color=Blue]high clk
  high dio
  low dio
  low clk
  return
  [/color]
[color=Black]i2CStop:
  [/color][color=Blue]low clk
  low dio
  high clk
  high dio
  return[/color]

[color=Green];Send a byte[/color]
[color=Black]i2CWrByte:  [/color][color=Green];outpinC.1 = dio
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit0[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit1[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit2[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit3[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit4[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit5[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit6[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit7[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Blue]return[/color]

[color=Green];Set the brightness ($88 = on, $88 to $8F are the brightness levels)[/color]
[color=Black]brightness:
  [/color][color=Blue]call [/color][color=Black]i2CStart
  [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]$89
  [/color][color=Blue]call [/color][color=Black]i2CWrByte
  [/color][color=Blue]call [/color][color=Black]i2CStop
  [/color][color=Blue]return
  [/color]
[color=Green];===========================================================================[/color]

Cheers to All
 
Last edited:
#2
The TM1637 LED display is widely available, cheap, and an easy way to add a four
digit LED display to a PICAXE project. Borrowing code from the link below I wrote
a version which runs much faster and the code size is reduced. It has been tested from
4 to 32 mhz on M2 parts and also at 64 mhz on X2 parts. The code could be made
to run even faster by converting the subroutines to macros.

Code:
[color=Green];TM1637_test.bas[/color]

[color=Navy]#picaxe [/color][color=Black]08m2[/color]

[color=Green];segment data for TM1637
     ;(  0   1   2   3   4   5   6   7   8   9   A   b   C   d   E   F  dash blank)[/color]
[color=Blue]DATA [/color][color=Navy]0[/color][color=Black],[/color][color=Blue]([/color][color=Navy]$3f[/color][color=Black],[/color][color=Navy]$06[/color][color=Black],[/color][color=Navy]$5b[/color][color=Black],[/color][color=Navy]$4f[/color][color=Black],[/color][color=Navy]$66[/color][color=Black],[/color][color=Navy]$6d[/color][color=Black],[/color][color=Navy]$7d[/color][color=Black],[/color][color=Navy]$07[/color][color=Black],[/color][color=Navy]$7f[/color][color=Black],[/color][color=Navy]$6f[/color][color=Black],[/color][color=Navy]$77[/color][color=Black],[/color][color=Navy]$7c[/color][color=Black],[/color][color=Navy]$39[/color][color=Black],[/color][color=Navy]$5e[/color][color=Black],[/color][color=Navy]$79[/color][color=Black],[/color][color=Navy]$71[/color][color=Black], [/color][color=Navy]$40[/color][color=Black], [/color][color=Navy]$00[/color][color=Blue])[/color]


[color=Green];for TM1637[/color]
[color=Blue]symbol dio [/color][color=DarkCyan]= [/color][color=Blue]C.1                        [/color][color=Green];TM1637 data pin to 08m2 leg 6[/color]
[color=Blue]symbol clk [/color][color=DarkCyan]= [/color][color=Blue]C.2                        [/color][color=Green];TM1637 clock pin to 08m2 leg 5[/color]
[color=Blue]symbol  [/color][color=Purple]D3 [/color][color=DarkCyan]= [/color][color=Purple]b2[/color]
[color=Blue]symbol  [/color][color=Purple]D2 [/color][color=DarkCyan]= [/color][color=Purple]b3                         [/color][color=Green];for all 4 digits[/color]
[color=Blue]symbol  [/color][color=Purple]D1 [/color][color=DarkCyan]= [/color][color=Purple]b4[/color]
[color=Blue]symbol  [/color][color=Purple]D0 [/color][color=DarkCyan]= [/color][color=Purple]b5[/color]


[color=Blue]gosub [/color][color=Black]brightness                        [/color][color=Green];set display brightness[/color]

[color=Blue]for [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]17                        [/color][color=Green];sequence thru all character
  [/color][color=Purple]D3 [/color][color=DarkCyan]= [/color][color=Purple]b1[/color][color=Black]:[/color][color=Purple]D2 [/color][color=DarkCyan]= [/color][color=Purple]b1                       [/color][color=Green];bytes stored in the data 
  [/color][color=Purple]D1 [/color][color=DarkCyan]= [/color][color=Purple]b1[/color][color=Black]:[/color][color=Purple]D0 [/color][color=DarkCyan]= [/color][color=Purple]b1
  [/color][color=Blue]gosub [/color][color=Black]DISPLAY
  [/color][color=Blue]pause [/color][color=Navy]1000[/color]
[color=Blue]next [/color][color=Purple]b1[/color]
[color=Blue]end[/color]

[color=Green];===========================================================================  

;Group of subroutines to read the values from data and output to the display[/color]

[color=Black]DISPLAY:
  [/color][color=Green];Enable sequential movement (from one digit to next)
  [/color][color=Blue]call [/color][color=Black]i2CStart
  [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]$40
  [/color][color=Blue]call [/color][color=Black]i2CWrByte
  [/color][color=Blue]call [/color][color=Black]i2CStop
  
  [/color][color=Green];Move to first digit
  [/color][color=Blue]call [/color][color=Black]i2CStart 
  [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]$C0
  [/color][color=Blue]call [/color][color=Black]i2CWrByte

  [/color][color=Green];First value
  [/color][color=Blue]read [/color][color=Purple]D3[/color][color=Black],[/color][color=Purple]b0
  [/color][color=Blue]call [/color][color=Black]i2CWrByte
  
  [/color][color=Green];Second value
  [/color][color=Blue]read [/color][color=Purple]D2[/color][color=Black],[/color][color=Purple]b0
  [/color][color=Blue]if [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Navy]17 [/color][color=Blue]then                                         
  [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Purple]b0 [/color][color=DarkCyan]+ [/color][color=Navy]128                         [/color][color=Green];add 128 to turn on colon
  [/color][color=Blue]endif                                             
  call [/color][color=Black]i2CWrByte              

  [/color][color=Green];Third value
  [/color][color=Blue]read [/color][color=Purple]D1[/color][color=Black],[/color][color=Purple]b0
  [/color][color=Blue]call [/color][color=Black]i2CWrByte

  [/color][color=Green];Fourth value
  [/color][color=Blue]read [/color][color=Purple]D0[/color][color=Black],[/color][color=Purple]b0
  [/color][color=Blue]call [/color][color=Black]i2CWrByte
  
  [/color][color=Blue]call [/color][color=Black]i2CStop
  [/color][color=Blue]return[/color]

[color=Black]i2CStart:
  [/color][color=Blue]high clk
  high dio
  low dio
  low clk
  return
  [/color]
[color=Black]i2CStop:
  [/color][color=Blue]low clk
  low dio
  high clk
  high dio
  return[/color]

[color=Green];Send a byte[/color]
[color=Black]i2CWrByte:  [/color][color=Green];outpinC.1 = dio
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit0[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit1[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit2[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit3[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit4[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit5[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit6[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Purple]outpinC.1 [/color][color=DarkCyan]= [/color][color=Purple]bit7[/color][color=Black]:[/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Blue]pulsout clk[/color][color=Black], [/color][color=Navy]1
  [/color][color=Blue]return[/color]

[color=Green];Set the brightness ($88 = on, $88 to $8F are the brightness levels)[/color]
[color=Black]brightness:
  [/color][color=Blue]call [/color][color=Black]i2CStart
  [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]$89
  [/color][color=Blue]call [/color][color=Black]i2CWrByte
  [/color][color=Blue]call [/color][color=Black]i2CStop
  [/color][color=Blue]return
  [/color]
[color=Green];===========================================================================[/color]

Cheers to All
Thanks very much for the code.

I have ordered a few of these screens and planning on trying to implement one into my project.

Would you be able to put up a schematic diagram in terms of pin conecction from screen to PICAXE please?

I am using PICAXE14M2 if that makes a difference.

Thanks very much.

Andrei.
 

hippy

Technical Support
Staff member
#3
It seems to be an I2C connection, so just two signals plus power ...

Code:
symbol dio = C.1 ;TM1637 data pin to 08m2 leg 6
symbol clk = C.2 ;TM1637 clock pin to 08m2 leg 5
Not studied the TM1367 datasheet but I would have thought the bit-banged I2C software could be replaced by HI2C commands to simplify things, improve speeds and reduce memory. That would swap the two pins around; CLK on C.1, SDA on C.2.
 
Last edited:

pxgator

Senior Member
#4
Thanks very much for the code.

I have ordered a few of these screens and planning on trying to implement one into my project.

Would you be able to put up a schematic diagram in terms of pin conecction from screen to PICAXE please?

I am using PICAXE14M2 if that makes a difference.

Thanks very much.

Andrei.
The code is using bit banged I2C so any pins that can be outputs could be used.
I've never been able to get the correct data on this part in order to use real I2C.
The bit banged I2C is quite quick with my code.


Cheers to All

P.S. Even the available Arduino code examples for
this part uses bit banged I2C.
 

PhilHornby

Senior Member
#5
Risk of "Magic Smoke"

The code is using bit banged I2C so any pins that can be outputs could be used.
I've seen a few example of using bit-banged I2C in the forum, but none seem to have addressed this issue :-

Code:
From the PIC datasheet:

Both the SCL and SDA connections are bidirectional [B]open-drain[/B] lines, each requiring pull-up resistors for the supply voltage
Presumably there is no way to manually configure an Output Pin to be open-drain, so how are potential clashes to be avoided (i.e. PIC o/p @ logic 1, other bus member at logic 0).

Would a simple resistor (or diode?) do the job, or is an external transistor necessary?
 

hippy

Technical Support
Staff member
#6
I am sure that some of my example code has dealt with the open-drain issue; that is achieved by only using INPUT and LOW commands, never setting the pin high.

There used to be issues with earlier PICAXE devices because they had fixed input and output pins, but with the modern M2 and X2 devices that is not a problem.

I would recommend using the same pins for bit-banging as the PICAXE uses for hardware does because it's then easy to switch between the two, and it also helps when developing code knowing that the other mechanism works. That applies to SPI and UART connections as much as to I2C.

This is example code I have for an old 08M which uses INPUT and LOW only -

Code:
; *****************************************************************************
; *                                                                           *
; *     I2C Test Program for the PICAXE-08M                     I2C6.BAS      *
; *                                     ^^^                                   *
; *****************************************************************************
; *                                                                           *
; *     This is an version of I2C3.BAS specifically designed to run on the    *
; *     PICAXE-08M using its bi-directional port abilities.                   *
; *                                                                           *
; *     The core I2C routines use just 140 bytes of code.                     *
; *                                                                           *
; *****************************************************************************

;                              --.---.-- +V
;                               .|. .|.
;                               | | | | 2 x 4K7
;                               |_| |_|
;        PICAXE-08M              |   |           I2C Eeprom / Ram
;       .----------.             |   |             .----------.
;       |       X1 |-------------^---|-------------| SDA   A2 |---.
;       |          |                 |             |       A1 |---{
;       |       X4 |-----------------^-------------| SCL   A0 |---{
;       `----------'                               |       WP |---{
;                                                  `----------'  _|_ 0V

; *****************************************************************************
; *                                                                           *
; *     Define the I2C device being used                                      *
; *                                                                           *
; *****************************************************************************

                                                ; 24LC256, Word Addressed

        Symbol  I2C_ADDRESS     = %10100000     ; $A0

; *****************************************************************************
; *                                                                           *
; *     Variables                                                             *
; *                                                                           *
; *****************************************************************************

        Symbol  tstAdr          = b0
        Symbol  tstVal          = b1

        Symbol  i2cAdr          = w1    ' b3:b2
        Symbol  i2cAdrLsb       = b2
        Symbol  i2cAdrMsb       = b3

        Symbol  i2cVal          = b4

        Symbol  i2cDataByte     = b5
        Symbol  i2cAckBit       = b6
        Symbol  i2cBitCount     = b7

; *****************************************************************************
; *                                                                           *
; *     Bit-Banged I/O definitions                                            *
; *                                                                           *
; *****************************************************************************

        Symbol  SDA             = 1
        Symbol  SCL             = 4

        Symbol  SDA_PIN         = pin1
        Symbol  SCL_PIN         = pin4

; *****************************************************************************
; *                                                                           *
; *     Main Program Code                                                     *
; *                                                                           *
; *****************************************************************************

        ; Wait for Terminal Window Pop-Up

        Pause 1000

        ; Initialise the I2C comms

        Gosub InitI2cDevice

        ; Test I2C

        For i2cAdr = $00 To $3F
          i2cVal = i2cAdr+3
          Gosub WriteI2cData
          Gosub ReadI2cData
          i2cVal = i2cVal-3
          If i2cVal <> i2cAdr Then
            SerTxd( "Er" )
          End If
        Next

        SerTxd( "Ok" )

        End

; *****************************************************************************
; *                                                                           *
; *     High-Level I2C Interface Routines                                     *
; *                                                                           *
; *****************************************************************************

WriteI2cData:

        Gosub I2cSendHeader

        i2cDataByte = i2cVal
        Gosub I2cSendByte

        Gosub InitI2cDevice

        Pause 20                        ; 20mS to allow write

        Return

ReadI2cData:

        Gosub I2cSendHeader

        Gosub I2cStart

        i2cDataByte = I2C_ADDRESS | $01
        Gosub I2cSendByte

        Input SDA                       ; SDA = 1 / Tri-State SDA
        For i2cBitCount = 0 To 7
          Gosub I2cStrobeScl
          i2cVal= i2cVal * 2 | i2cAckBit
        Next

InitI2cDevice:

        Low SCL                         ; SCL = 0
        Low SDA                         ; SDA = 0
        Input SCL                       ; SCL = 1
        Input SDA                       ; SDA = 1
        Return

; *****************************************************************************
; *                                                                           *
; *     Low-Level I2C Interface                                               *
; *                                                                           *
; *****************************************************************************

I2cSendHeader:

        Gosub I2cStart

        i2cDataByte = I2C_ADDRESS & $FE
        Gosub I2cSendByte

        i2cDataByte = i2cAdrMsb
        Gosub I2cSendByte

        i2cDataByte = i2cAdrLsb

I2cSendByte:

        For i2cBitCount = 0 TO 7
          If i2cDataByte < $80 Then
            Low SDA                     ; SDA = 0
          Else
            Input SDA                   ; SDA = 1
          End If
          Gosub I2cStrobeScl
          i2cDataByte = i2cDataByte * 2
        Next
        Input SDA                       ; SDA = 1 / Tri-State SDA
        Gosub I2cStrobeScl
; ---   if i2cAckBit = 1 Then
; ---     SerTxd( "ACK FAILED",CR,LF )
; ---   end if
        Return

I2cStart:

        Input SDA                       ; SDA = 1
        Input SCL                       ; SCL = 1
        Low SDA                         ; SDA = 0
        Low SCL                         ; SCL = 0
        Return

I2cStrobeScl:

        Input SCL                       ; SCL = 1
        Do
        Loop Until SCL_PIN = 1
        i2cAckBit = SDA_PIN
        Low SCL                         ; SCL = 0
        Return

; *****************************************************************************
; *                                                                           *
; *     End of program                                                        *
; *                                                                           *
; *****************************************************************************
 

pxgator

Senior Member
#8
I have used the code posted above with 08M2's, 14M2's, and 20X2's on many TM1637 LED
display projects. All have and still are working perfectly. Maybe the TM1637 is not truly
an I2C device??

Cheers to All
 

hippy

Technical Support
Staff member
#9
Maybe the TM1637 is not truly an I2C device??
It seemed to be from the datasheets I looked at and the bit-banged code earlier. Talking of which -

Code:
  outpinC.1 = bit7:pulsout clk, 1
  pulsout clk, 1
  return
That's a bit iffy as PhilHornby noted above. It is clocking in an ACK from the I2C device which, if bit7 just happens to have set C.1 high, will be trying to pull that high to 0V. Admittedly only for a short period of time.
 

pxgator

Senior Member
#10
Thanks for the info hippy but like I mentioned above the code and
setup that I use with PICAXE chips and the TM1637 have worked
trouble free for a long time. I've never experienced any errors.

Cheers to All
 

hippy

Technical Support
Staff member
#11
Maybe the TM1637 is not truly an I2C device??
It seemed to be from the datasheets I looked at and the bit-banged code earlier.
Having had cause to look at the datasheet more recently it is fair to say it uses an I2C-style protocol but is not what one would call a traditional I2C device. The device doesn't have a Device ID and the command and data bits are sent lsb first rather than msb first as is the case with usual I2C.

Because of the TM1637 peculiarities it would seem difficult to control it using I2C commands which would be used to control other I2C devices and bit-banging would appear to be the most appropriate way to do that.
 
Top