How to use TM1637 chip for LED Display?


Results 1 to 14 of 14

Threaded View

  1. #1
    Join Date
    May 2011
    Location
    Bangalore, India
    Posts
    33

    Default How to use TM1637 chip for LED Display?

    Hi All,

    For the past 10 days, I have been trying to make the TM1637 work with PBP 2.60C but till now I have not been successful. It's a real low cost module. The price of the TM1637 4-digit 7-segment 0.36" display module is about $ 0.60 in Ali Express. There is a 0.56" version and that costs about $ 1.25.
    The module works fine with Arduino, but all the important instructions to interface with TM1637 are in the library file (TM1637Display.h). After spending some time with the library file, I decided to study the datasheet of the chip and write the required code in PBP. The protocol followed by the chip is very similar to I2C with a few differences. Like I2C, it's a two-wire interface but you can have only one slave on the bus and hence there is no slave address. Secondly, while transmitting a byte, the LS bit is sent first.

    The code I wrote for PIC 12F1840 is shown below and it is extremely simple. It should make the number '2' appear on the leftmost digit of the display. When I tested the code, the diagnostic LED blinked, but after that nothing happened. I used Saleae Logic Analyzer to check whether the Clock & Data pulses and Ack were all OK. After some tweaking, I managed to get everything correct (Screenshot file attached). The only issue is, the display shows nothing! Since I know that the module is working fine with Arduino, it's my code in PBP that needs to be looked into.

    I would highly appreciate any helpful hint, suggestion or sample code.

    - Bala


    '---------------------------------------------------------------------------
    ' This code is for using TM1637 with Four-digit 7-segment LED Display
    ' with PIC12F1840. Osc is set at 16MHz.
    '---------------------------------------------------------------------------
    '---------------------------------------------------------------------------
    '12F1840 Pinout:
    ' -------------------------------------------------------
    ' VDD VSS
    ' PortA.5 = Not_used PortA.0 = LED
    ' PortA.4 = Not_used PortA.1 = DIO
    ' PortA.3 = Not_used PortA.2 = CLK
    ' -------------------------------------------------------

    '@ __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_OFF & _BOREN_OFF
    '@ __CONFIG _CONFIG2, _PLLEN_OFF & _BORV_LO & _LVP_OFF

    ASM
    ifndef __12F1840
    error "12F1840 not selected"
    endif
    ENDASM

    OSCCON = %01111000 '16MHz HF, software PLL disabled
    DEFINE OSC 16

    'Port direction
    TRISA = %001000 'A.3 is input, rest are outputs.

    CM1CON0 = 0 'Disable comparator
    ANSELA = 0 'Disable A to D

    'List of Aliases
    LED var PortA.0
    DIO var PortA.1
    CLK var PortA.2
    TrisDIO VAR TrisA.1

    'List of variables
    Cnt var byte
    ByteToSend var byte 'Command or Data byte to be sent

    DispCmd var byte
    dispcmd = 64 'Command byte for displaying characters starting with the leftmost digit (0b01000000)

    Brt8Cmd var byte
    brt8cmd = 143 'Command byte for display on with maximum brightness (0b10001111)

    Dig1Addr var byte
    dig1addr = 192 'Address of digit 1 (left most) (0b11000000)

    DispNum var byte
    dispnum = 146 ' "2" (Common anode) (10010010)

    'Diagnostic routine
    DiagRoutine:
    for cnt = 1 to 4 'Blink LED 4 times.
    led = 1 : pause 100
    led = 0 : pause 100
    next cnt

    goto start

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

    SendTheByte:
    clk = 0
    for cnt = 7 to 0 step -1 '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:
    clk = 0
    dio = 0
    clk = 1
    pauseus 50
    dio = 1 'DIO goes high when CLK is high.
    pauseus 50
    return

    START:

    bytetosend = brt8cmd 'Brt8Cmd (10001111) (143) = Command for Display On with Maximum Brightness
    gosub startcondition
    gosub sendthebyte
    gosub stopcondition

    bytetosend = dispcmd 'DispCmd (01000000) (64) = Command byte with auto increment sent before sending the digit data
    gosub startcondition
    gosub sendthebyte
    gosub stopcondition

    bytetosend = dig1addr 'Dig1Addr (11000000) (192) = Address of digit 1 (leftmost digit)
    gosub startcondition
    gosub sendthebyte

    bytetosend = dispnum ' Number "2" (10010010) (146) (Common anode)
    gosub sendthebyte

    gosub stopcondition


    END
    Attached Images Attached Images  
    Last edited by Balachandar; - 10th October 2018 at 14:15.

Similar Threads

  1. TM1637 - display module include example
    By longpole001 in forum Code Examples
    Replies: 5
    Last Post: - 13th April 2020, 19:19
  2. 3642bh display module pinouts on tm1637 module
    By longpole001 in forum Schematics
    Replies: 0
    Last Post: - 31st July 2018, 19:09
  3. LED Matrix display
    By Art in forum General
    Replies: 13
    Last Post: - 5th October 2013, 05:06
  4. LED Bargraph chip (guitar LED bling-age) ..do with a PIC?
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 13th July 2009, 00:15
  5. TV Display Chip
    By zadok in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 17th April 2008, 23:17

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts