Tutorials - Elettronica



LED/Key controller.

TM1637 is a LED and key controller. The most important features are:

  • controller for six digit of 7-segments display(common anode)
  • adjustable brightness
  • auto blanking
  • scan for 2 x 8 keys
  • sychronous interface, 2-wires data + clock

The application scheme is:

The chip is available in package DIP or SOP a 20 pin. The pinout is:

  Label Nome Pin Descrizione
DIO Data I/O 17 Data and command I/O
Data is transferred with the clock line high.
Any 8-bit, the chip generate an ACK status
CLK Input clock 18 Communication's lock (rising edge)
K1-K2 In keyboard  scan  19-20 Input for the keyboard
SG1-SG8 Out (segments) 2-9 Output of segment's drivers (open drain)
GRID6-GRID1 Out (digits) 10-15 Output of digit common anode (P channel open drain)
VDD power supply 16 power supply +
GND ground 1 common

TM1637 can be powerd from 3 to 5V and cn supply 50mA sink current to the segments.

Communication's interface.

The very poor data sheet in Chinglish is not very explicit, but it is still possible to trace the operation of the device.

The interface to the microcontroller is serial two-wire, given and clock (called DIO and CLK).
The data from the microprocessor must remain unchanged until the clock is at a high level. If the clock is low, the data line may vary.

The communication start condition is the application of a START, obtained with the data line that passes from high to low level while the clock is at high level.
The communication is closed by sending the STOP condition: the data line switches from low to high level with the clock to high level.

If the data transfer has been corrected, the device responds with an "ACK", sending the data line down to the downhill edge of the eighth clock stroke. The line is released at the end of the next ninth clock stroke.
The scheme proposed by the manufacturer (see above) includes 10k pull-up on the communication lines and also 100pF real mass capacitors; the latter are characterized as "connected to the DIO, CLK communication port pull-up and pull-down (sic!). can reduce interference to radio communications port".

One effect, however, is to load the lines with a fairly sensitive capacity, which makes the signal rising fronts rather curved.


The data sheet, about communication protocol, say "not equal to 12C bus protocol totally (sic!) because there is no slave address". 

The above reason clearly indicates that the manufacturer is not part of the I2C consortium (where a fee has to be paid for valid addresses). 
And, in fact, the communication pins are called DIO and CLK and not SDA and SCL.

The lack of a slave address prevents the controller from being plugged into an I2C bus together with other peripherals, even one might think that it can be used alone, since the protocol could be understood as only "not completely" compatible.

Unfortunately, the device does not have much to do with I2C; in fact, there are other problems:

  • first, the less significant bits are sent first, while in I2C it is the opposite.
  • second, the ACK response of the device follows a different timing.

All this means that the TM1637 cannot be used as any I2C element (and even more so in a bus common to other devices) and a suitable driver must be used.

In this regard, it has to be said that, thanks to the ultra-low costs of Chinese 4- or six-digit modules, this interface is widespread and ad hoc libraries for Arduino and similar have been created.


La struttura dei registri dati.

TM1637 can receive commands and data.
Communication involves a simple command/data structure.

Commands are processed directly, while data is sent to internal registers. 

There are 6 registers, corresponding to the six digits that can be controlled. Each bit corresponds to one segment of the display. As bizarre as it may be, the table proposed on the data sheet is replicated:

seg1 seg2 seg3 seg4 seg5 seg6 seg7 seg8  
b0 b1 b2 b3 b4 b5 b6 b7  
xxHL  4 bit bassi xxHU  4 bit alti  

When sent to the registers it will be shown on the corresponding display: TM1637 does not have a decoding between data and segments, so bits sent to 1 correspond to segments on, 0 correspond to segments off.

Writing one or more registers is done following a specific command that has the bit7:6=10.



A command must be inserted in the first byte sent after the clock descending edge in the initial START.
Commands are groups of 8 bits of which bits 6 and 7 indicate the following type:

b7 b6 Comando
0 1 Commands related to data processing
1 0 Display control
1 1 Address setting

If a STOP is sent by the MASTER during the transmission of a command, it is invalidated (the commands and data sent before are valid).

Commands related to data processing are:

b7 b6 b5 b4 b3 b2 b1 b0 Funzione Descrizione
0 1 0 0     0 0

data read/write

Write to display
0 1     1 0 Read keys
0 1   0    


Auto increment
0 1   1     Fixed address
0 1 0      

Test mode

Normal mode
0 1 1       Test mode

Bits b0 and b1 cannot contain 01 or 11.

The data sheet specifies that bits5:4 can be set to 0. It does not say anything about the undesired bits, which suggests that they can take on any value.
In any case, filling the blank spaces with 0 means that the command "Normal mode" has the same value as the command "Write data on display" and "Automatic increase", so you can suppose the following:"Write data on display".

  • 01000000  0x40   is the normal operating mode: this means that the byte sent below is a datum towards
                                the display, with the automatic increase in destination addresses
  • 01000010  0x42   read the input situation
  • 01000100  0x44   set the fixed address mode
  • 01001000  0x48   test mode (internal use)

There is no description of the "Test mode", but since it is cryptically referred to as "(for internal)" it must be assumed that it is an aid for the chip function tests before release by foundry

Two possible operative mode (command 0x40 e 0x44):

  • 0x40 with fixed destination address: data are sent to the selected address only
  • 0x44 with increasing car destination address: each data will be written progressively in successive addresses starting from the selected one.

The register addresses correspond to the display digits, with bit7:6 to 1:

b7 b6 b5 b4 b3 b2 b1 b0 Indirizzo display
1 1 0 0 0 0 0 0 C0H
1 1 0 0 0 1 C1H
1 1 0 0 1 0 C2H
1 1 0 0 1 1 C3H
1 1 0 1 0 0 C4H
1 1 0 1 0 1 C5H

By default, the selected address is C0H, i. e. the first digit on the left, when resetting the power supply.
If a value higher than 5 is sent, it is ignored and there are no effects until a valid address is sent.
In auto-increase mode, the starting address for the data must be sent.

The commands relative to the display control concern its on/off status and the change in brightness, obtained with a PWM.

b7 b6 b5 b4 b3 b2 b1 b0 Function Description
1 0 0 0   0 0 0 brightness PWM 1/16
1 0   0 0 1 PWM 2/16
1 0   0 1 0 PWM 4/16
1 0   0 1 1 PWM 10/16
1 0   1 0 0 PWM 11/16
1 0   1 0 1 PWM 12/16
1 0   1 1 0 PWM 13/16
1 0   1 1 1 PWM 14/16
1 0 0       Display
Display OFF
1 0 1       Display ON

The table, unfortunately, is not at all clear. In fact, it turns out that bit3 on/off must be added to the brightness value. So you have that:

  • 10000000                   0x80             display off
  • 10001000                   0x88             display on with PWM 1/16
  • 10001001-100001111 0x89-0x8F    brightness control, 7 step 


The management of registers.

The management of the registers involves a simple command/data structure.

Let's see in the following diagram an example of an incrementing auto-address transmission:

  1. A START condition, similar to the classic I2C condition, is used to start communication: DIO (SDA) goes down with CLK (SCL) at a high level.
  2. This follows the output of an 8-bit command, synchronized with the clock, that the specific data sheet must be less than 250kHz.
  3. The device responds by bringing down the DIO line (SDA) with an "ACK" that is cleared by the ninth clock stroke.
  4. If the command does not result in data output, the Master closes communication with a STOP condition (CLK goes high with low DIO).
  5. A subsequent communication is restarted with a START. If the command requires more than one data, it is sent in sequence, while the device responds "ACK" as shown above.
  6. A STOP and subsequent START allow you to send other data/command.

The first data item goes to the address indicated by the command; the following data goes to successive addresses, incremented by 1 at each writing. This simplifies the transmission of more data, such as in the presentation of multiple digits on the display.

If you choose the fixed address, the sequence can be as follows:.

The data following the commands are always sent to the same address. This allows you to update only one digit of the display.


Reading the keyboard.

TM1637 can support 2 blocks of 8 contacts each. 
Contacts are connected between lines that command the segments (SG1-SG8) and two common lines (K1 and K2)

Caution: TM1637 does not support a condition where more than one key is pressed.

The key condition can be requested with a specific command (0x42).

The lowest bit (bit0) is transmitted first.

If there are no pressed keys, the returned data is FFh (1111111111).
If a key is pressed, the returned data is indicated in the following table: The following table shows the value of the data returned.

  SG1 SG2 SG3 SG4 SG5 SG6 SG7 SG8
K1 1110_1111 0110_1111 1010_1111 0010_1111 1100_1111 0100_1111 1000_1111 0000_1111
K2 1111_0111 0111_0111 1011_0111 0011_0111 1101_0111 0101_0111 1001_0111 0001_0111

In practice, the byte read has this meaning:

K1   K2
b7 b6 b5 b4 b3 b2 b1 b0 Tasto   b7 b6 b5 b4 b3 b2 b1 b0 Tasto
   1  1  1 1 0 1 1 1 S1    1  1  1 0 1 1 1 1 S2
1 0 1 1 0 S5 0 1 1 1 0 S6
1 0 1 0 1 S9 0 1 1 0 1 S10
1 0 1 0 0 S13 0 1 1 0 0 S14
1 0 0 1 1 S4 0 1 0 1 1 S3
1 0 0 1 0 S8 0 1 0 1 0 S7
1 0 0 0 1 S12 0 1 0 0 1 S11
1 0 0 0 0 S16 0 1 0 0 0 S15

Basically, the first 5 lowest bits are significant (b4: b0); b4: b3 distinguish the keys on the common line K1 or K2, while b2: b0 encode the key.

The following table shows the value of the returned data according to the key pressed (keeping the bizarre numbering of the buttons in the previous diagram):

Tasto S16 S15 S14 S13 S12 S11 S10 S9  S8  S7  S6  S5  S4  S3  S2  S1 
Matrice SG8
hex F0


EC F4 F1 E9 ED  F5 F2   EA EE F6 F3 EB EF F7

The reading clock must be less than 250kHz.

The data sheet shows a diagram for scanning the keys:

According to the manufacturer, the key acquisition system is particularly protected against EMC interference, as the TM1637 is used in power appliances such as induction hobs.



The manufacturer provides an example of a driver in C, which is reported in full without changes:

Reference Program
/ *
* Copyright: Shenzhen Tian Microelectronics
* File name: TM1637
* Current Version: 1.0
* SCM Model: AT89S52
* Development Environment: Keil uVision3
* Crystal earthquake frequency: 11.0592M
* Program features: the TM1637 all filled with all the display data register address
  0xff, and open the display, and then read the key value.
* /
   # include <reg52.h>
   # include <intrins.h>
   // Define port
   sbit clk = P1 ^ 2;
   sbit dio = P1 ^ 1;

/ / / =======================================
void Delay_us (unsigned int i) // n us delay
   for (; i> 0; i--)
_  nop_ ();
/ / / ======================================
void I2CStart (void) // 1637 start
   clk = 1;
   dio = 1;
   Delay_us (2);
   dio = 0;
/ / / =============================================
void I2Cask (void) // 1637 Answer
   clk = 0;
   Delay_us (5); // After the falling edge of the eighth clock delay 5us, ACK signals the beginning of judgment
   while (dio);
   clk = 1;
   Delay_us (2);
   clk = 0;
/ / / ========================================
void I2CStop (void) // 1637 Stop
   clk = 0;
   Delay_us (2);
   dio = 0;
   Delay_us (2);
   clk = 1;
   Delay_us (2);
   dio = 1;
/ / / =========================================
void I2CWrByte (unsigned char oneByte) // write a byte
   unsigned char i;
   for (i = 0; i <8; i + +)
      Clk = 0;
      if (oneByte & 0x01) // low front
      {dio = 1;}
      else {dio = 0;}
      Delay_us (3);
      oneByte = oneByte >> 1;
      clk = 1;
      Delay_us (3);
/ / / ----------------------------------------------- -
unsigned char ScanKey (void) // read buttons \
   unsigned char rekey, rkey, i;
   I2CStart ();
   I2CWrByte (0x42); // read command buttons
   I2Cask ();
   dio = 1; // read keys before data lines pulled
   for (i = 0; i <8; i + +) // start reading from the low
      Clk = 0;
      rekey = rekey >> 1;
   return (rekey);

void SmgDisplay(void) // Write display register
   unsigned char i;
   I2CWrByte(0x40); //40H address is automatically incremented by 1 mode, 44H fixed address mode
   I2CWrByte(0xc0); // Set the first address
   for(i=0;i<6;i++) // Addresses from Canada, do not always write address
      I2CWrByte(0xff); // Send data
   I2CWrByte(0x8f); // Open display, maximum brightness
void init() // Initialization routine
   // Initialization slightly
void main(void)
    unsigned char keydate;

// Initialization
    SmgDisplay(); // Write register and open display
       keydate=Scankey(); // Read key value, the key value is not read out for treatment.

A driver has been created in Assembly. Here you will find a version for Enhanced Midrange.

Some notes on hardware.

1. - input RC

On all Chinese 4-digit and TM1637 cards, 10k pull-up and 100pF capacitors are installed on the input lines.
This value is not a negligible capacitance and influences the timing of signal ascent and descent. 
Pull-ups can be reduced to 4k7, especially if the connection cable between micro and display is not minimal.

2. - Decimal points

Modules with 4 digits and TM1637 are available on the market at very low prices.
As with most Chinese products in this class, the technical documentation of these modules is non-existent and even for the displays it can be very difficult to find even an indicative data sheet.
In all cases, these are single blocks, including 4-digit figures and some additional points.
The problem is precisely these points: photographs can be misleading, as the displays may seem to have several decimal places, but these can in practice be partially inactive.

Displays can have 12 or 14 pins, depending on the number of points available.

In 12-pin displays such as CL5642Bx-30, the middle points depend on bit 7 of the second digit (instead of the relative decimal point), while the other decimal points, even if they seem to exist, are practically not present.
Other 12-pin displays, such as the CL3641 or ZS3641, do not have central points, but have the decimal point for each digit.
Displays such as LD3462BS  have only the center points.

In some 14-pin display modules, such as the JYB5643, you have separate access to the center points and an additional point at the top, which can be operated as a fifth digit segment.
Other modules have different designs.

If a specific use of points is required, it will be necessary to check whether the selected module is suitable for the desired application.

3. - Power supply

One final note concerns the supply voltage: if TM1637 can be supplied from 3 to 5V (this is not explained in the data sheet), it is the minimum conduction voltage of the LEDs that determines the minimum supply value. Thus, blue LEDs will not be able to be powered at less than 5V.



Copyright afg. Tutti i diritti riservati.
Aggiornato il 01/09/17.