• AVR Freaks

Hot!Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display

Page: 123 > Showing page 1 of 3
Author
Joe Burch
New Member
  • Total Posts : 18
  • Reward points : 0
  • Joined: 2014/12/10 21:31:25
  • Location: 0
  • Status: offline
2014/12/13 23:29:30 (permalink)
0

Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display

Hello folks.  I wonder if someone could help me out with this.  Although I have a lot of experience with the Freescale product line, I'm relatively new with the PIC's.  I've been trying to write some I2C code that would let me control a (known good) TM1637 chip.  I've been using a (slightly modified) bit-banger written by Drew Vassallo and it doesn't work.  I've tried inserting delay loops at key portions of the program, I've used the simulator and still 'no joy'.  I'd hate to tell you how much evening time I've spent on this so far....
 
If someone could send me a simple bit banging I2C program - in assembly language, please - for the 16F (series), I'd be most appreciative.  According to the 'Chinglish' data sheet, one has to send the following data commands to the chip:
 
START - 0x40 - (for automatic data incrementing) - STOP
START - 0xc0 - (first digit - second digit - third digit - fourth digit - fifth digit - sixth digit) - STOP
START - 0x87 - (display intensity) - STOP
 
I'm attaching a cleaned up copy of the code - please don't laughprogram.txt program.txt .
 
Regards - Joe Burch - K3JLS
 
 
#1

40 Replies Related Threads

    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2014/12/14 12:31:41 (permalink)
    0
    What is not working exactly?
    Your code looks good enough, at a glance.
    Maybe you need to add more delays, in order to slow it down (and avoid the R-M-W effect, since your PIC has no LATx registers)

    GENOVA :D :D ! GODO
    #2
    Joe Burch
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2014/12/10 21:31:25
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2014/12/14 14:01:59 (permalink)
    0
    Hi Dario,
    Thanks for your reply.  It just doesn't work - at all!  I'll be sending a revised copy of the code shortly, but what is the 'R-M-W' problem and how does one fix it?
     
    Thanks - Joe
     
    #3
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2014/12/14 15:19:12 (permalink)
    0
    Take a look at this: http://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/rmw.htm
    Smile
    Basically, it happens when you write to one pin quickly after another on the same port.

    GENOVA :D :D ! GODO
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 17499
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2014/12/15 17:18:00 (permalink)
    +1 (1)
    RMW is worse with Bit Banged I2C since  the Pin is Pulled up.
    #5
    Joe Burch
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2014/12/10 21:31:25
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2014/12/19 17:19:30 (permalink)
    0
    Hello folks - I have it working and it works very well.  I did not need any shadow registers as the RMW situation was apparently not an issue, nor was the 'bit banging' a problem.  It just required some major 'tweaks' to the code.  It's really slick!
     
    My thanks to the very few who tried to help me.
     
    #6
    sjors
    New Member
    • Total Posts : 1
    • Reward points : 0
    • Joined: 2014/12/21 11:14:07
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2014/12/21 11:18:06 (permalink)
    0
    Hi Joe,
    I'm struggling with the same problem ; cannot get the 4 digit display using tm1637 to work with a pic ontroller.
    Could you explain what tweaks you did on your code to get it work ?
    regards
    Sjors
    #7
    Joe Burch
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2014/12/10 21:31:25
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2014/12/23 10:50:56 (permalink)
    -5 (3)
    Hi Sjors,
     
        It took me a long time, but I finally found the solution.  It works very well.  If you'll email me privately  - - I'll let you know what was done with the 'ACK' response.  I'm reluctant to share the 'answer' on this group since I received very little support to my queries. 
     
       It seems that most of the replies - especially for those new to the PIC - basically state 'check the data sheet'.
     
       For my money, I'll take the Freescale chips any day.  They're very easy to program, there's plenty of RAM and no bank bullcrap to worry about.
     
       Freescale would have a better showing in he hobbyist market if they didn't migrate so much to SOIC packages - regrettable!
     
    Joe
     
    #8
    David
    Pic User
    • Total Posts : 1286
    • Reward points : 0
    • Joined: 2007/12/17 23:19:53
    • Location: uk sussex
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2014/12/23 18:52:59 (permalink)
    +2 (2)
    funny attitude because you came here for help and did not get enough help you dont want to help forum, I guess you dont understand forums. I wish you luck in the future.

    David
    I support http://picforum.ric323.com because this forum is often too broken to use!
    #9
    afg.it
    New Member
    • Total Posts : 1
    • Reward points : 0
    • Joined: 2017/08/27 10:38:19
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2017/09/01 01:23:24 (permalink)
    0
    Hi
    For anyone interested, there is attached a driver Assembly for the TM1637.
     
    An also a link for some pages explaining (better than original data sheet) how the component works
    http://www.microcontroller.it/english/default_eng.htm

    Available for any enquiries
    Regards
     
    #10
    vank
    New Member
    • Total Posts : 1
    • Reward points : 0
    • Joined: 2018/04/20 00:31:20
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2018/05/22 03:46:42 (permalink)
    0
    Hello!
    The subject is very old.
    But I am now interested in Interfacing the PIC16F628A with a TM1637 in assembler.
    Can somebody help me?
    I do not get an ACK from TM1637.
    #11
    Jarrett
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2016/10/13 14:21:14
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2019/02/19 20:02:10 (permalink)
    0
    This is a pretty hilariously salty position. Requesting - No, demanding - omniscience from the people trying to help.
     
    Appreciate the assembly versions posted above.
    Here's a quick-and-dirty C implementation, too.
     
    To use:
     
        display_init(7);
        display_number(0x01);
    #12
    cgaufin
    New Users
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2018/03/23 06:42:51
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2019/03/13 14:17:21 (permalink)
    0
    Hello Jarrett,
    I am just starting out with a Curiosity board and wanted to get the display I have working. It uses the TM1637 and I tried to use the display files you sent, but the display will not light up. I have used the display using an arduino and their library so I know the display works, but I want to get it working with the Curiosity. If you would be willing to help, let me know.
     
    Thanks!
    #13
    Jarrett
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2016/10/13 14:21:14
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2019/03/13 14:25:38 (permalink)
    0
    Have you made sure to configure your desired pins as described in the source files I posted? Open drain and weak pullups, analog off
    #14
    cgaufin
    New Users
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2018/03/23 06:42:51
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2019/03/13 14:48:29 (permalink)
    0
    I believe that I have. In the pin module in MCC I made sure to click on the open drain (OD) option, clicked on the WPU option and endabled the register for that, and I made sure that the analog boxes were also not checked. It is probably something really simple that I am missing.  I attached the project as well. Say one wanted to display the number 1234, one would just call display_number(1234); correct?
    #15
    cgaufin
    New Users
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2018/03/23 06:42:51
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2019/03/27 10:04:16 (permalink)
    0
    I just wanted to reach out and refresh the thread to see if anyone had any luck getting this to function. I see it has been downloaded a few times.
    #16
    cgaufin
    New Users
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2018/03/23 06:42:51
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2019/03/28 14:12:56 (permalink)
    0
    I was feeling adventurous and so I decided to try and modify a TM1637 Arduino library. It ended up working, so that is good, but I haven't had time to look back over the datasheet to see "why it works" and how on earth one could pull that information from the data sheet.  I have attached the project as well for anyone interested. I commented out the original TM1637 github .h and .c file, so it is there for reference inside the code. I then began to comment out things that I wasn't planning on using. In the end, I have a program that counts from -550 to 550. Nothing fancy and a LOT of room for optimization. Maybe someone will find this helpful. I did this with the PIC16F1619 Curiosity board.
     
    #17
    arthurmk
    New Member
    • Total Posts : 1
    • Reward points : 0
    • Joined: 2019/03/17 07:37:59
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2019/04/02 06:47:13 (permalink)
    0
    here are still solutions
    /*
    * File: TM1637.h
    * Author: Arthur Mkoyan
    *
    * Created on 29 ????? 2019 ?., 17:21
    */
    #ifndef TM1637_H
    #define TM1637_H
    #include <inttypes.h>
    #include <stdbool.h>
    //#include <stdint.h>
    #include <xc.h>
    #include "mcc_generated_files/pin_manager.h" // declared OUTPUT=0,INPUT=1
    //#include "My_Function.h"
    //#include "lcd.h"
    //#include "My_Function.h"
    //#include "mcc_generated_files/mcc.h"
    //======================== define pin =======================

    #define TM1637_PORT LATA
    #define TM1637_Dir TRISA
    #define TM1637_DataPort PORTAbits.RA0

    #define TM1637_CLK_MASK 0b11111101
    #define TM1637_DIO_MASK 0b11111110
    //#define TM1637_Clk LATAbits.LA1
    //#define TM1637_Data LATAbits.LA0
    //#define clk LATAbits.LA1
    //#define dio LATAbits.LA0
    //#define TM1637_Pin_Init
    #define TM1637_CH TM1637_PORT=(TM1637_PORT | ~TM1637_CLK_MASK)
    #define TM1637_CL TM1637_PORT=(TM1637_PORT & TM1637_CLK_MASK)
    #define TM1637_DH TM1637_PORT=(TM1637_PORT | ~TM1637_DIO_MASK)
    #define TM1637_DL TM1637_PORT=(TM1637_PORT & TM1637_DIO_MASK)
     
     
    #define TM1637_DataDir_OutPut TM1637_Dir=TM1637_Dir&TM1637_DIO_MASK
    #define TM1637_DataDir_InPut TM1637_Dir=(TM1637_Dir&TM1637_DIO_MASK)|~TM1637_DIO_MASK
    //************definitions addres*********************
    #define TM1637_AUTO 0x40
    #define TM1637_FIXED 0x44
    #define TM1637_TEST 0x48
    #define TM1637_GRID_ADD 0xC0
     
    /**** definitions for the point *******/
    #define POINT_ON 1
    #define POINT_OFF 0
    /**************definitions for brightness***********************/
    #define TM1637_DISPLAY_OFF 0x80
    #define TM1637_DISPLAY_ON 0x88
    #define BRIGHT_DARKEST_1_16 0x00
    #define BRIGHT_DARKEST_2_16 0x01
    #define BRIGHT_DARKEST_4_16 0x02
    #define BRIGHT_DARKEST_10_16 0x03
    #define BRIGHT_DARKEST_11_16 0x04
    #define BRIGHT_DARKEST_12_16 0x05
    #define BRIGHT_DARKEST_13_16 0x06
    #define BRIGHT_DARKEST_14_16 0x07
    //--------------------------------------------------------//
    //Special characters index of tube table
    #define INDEX_NEGATIVE_SIGN 11
    #define INDEX_BLANK 12
    /************definitions for type of the 4-Digit Display*********************/
    //========================= global var ===============================
    #define TM1637_MAX_GIRD 6
    uint8_t TM1637_Segment_Count; //1-6
    uint8_t TM1637_Segment_Start; //1-6
    uint8_t TM1637_Segment_Data[TM1637_MAX_GIRD];
    uint8_t TM1637_Display_Brightness=BRIGHT_DARKEST_14_16;

    #ifdef __cplusplus
    extern "C" {
    #endif




    void TM1637_Init(uint8_t Seg_start,uint8_t Seg_count);
    void TM1637_SetAuto();
    void TM1637_SetFixed();
    void TM1637_SetDisplay_Brightness(uint8_t brightness);
    void TM1637_Display_On();
    void TM1637_Display_Off();
    void TM1637_Fixed_Write(uint8_t segment,uint8_t integ);
    void clearSegment(unsigned char segNumber);
    void clearDisplay(void);
    void display_WriteInt(int16_t integer);


     
     

    #ifdef __cplusplus
    }
    #endif
    #endif /* TM1637_H */
     
    // himnakanum vercvac e
    //http://www.microcontrolle.../componenti/TM1637.htm
    //
    #include "TM1637.h"

    static int8_t IntTab[12] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,0x17};//0-9,"-",clear
    //0x77,0x7c,0x39,0x5e,0x79,0x71,0x3d,0x76,0x74,0x18,
    //0x04,0x1f,0x1e,0xf6,0x38,0x37,0x54,0x63,0x5c,0x73,
    //0xbf,0x50,0x78,0x3e,0x1c,0x6e,0x40,0x01,0x08};
    /*static int8_t HexTab[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,//0-9
    0x77,0x7c,0x39,0x5e,0x79,0x71};//A-F*/
    //0x3d,0x76,0x74,0x18//"","H","h",""
    //0x04,0x1f,0x1e,0xf6,0x38,//"_","1f","J","H.","L",
    //0x37,0x54,0x63,0x5c,0x73//"П","54","graduc","5c","P"
    //0xbf,0x50,0x78,0x3e,0x1c,//"O.","|","78","U","1c"
    //0x6e,0x40,0x01,0x08};//,"Y","-","01","08"
    //====================================================
    static void Delay_us(unsigned int i) // n us delay
    {
    for (; i> 0; i--)
    __nop ();
    }
    void TM1637_Init(uint8_t Seg_start,uint8_t Seg_count){

    TM1637_Dir=(TM1637_Dir & TM1637_CLK_MASK)&TM1637_DIO_MASK;

    if((Seg_start+Seg_count-1)<=TM1637_MAX_GIRD)TM1637_Segment_Count=Seg_count;
    else TM1637_Segment_Count=TM1637_MAX_GIRD-Seg_start;

    if(Seg_start<=TM1637_MAX_GIRD)TM1637_Segment_Start=Seg_start;
    else {
    TM1637_Segment_Start=1;
    TM1637_Segment_Count=TM1637_MAX_GIRD;
    }

    }
    void TM1637_start(void){
    TM1637_CH;
    TM1637_DH;
    Delay_us(2);
    TM1637_DL;
    }
    void TM1637_ACK(){
    TM1637_CL;
    TM1637_DL;
    TM1637_DataDir_InPut;
    while(TM1637_DataPort)
    {
    }
    TM1637_DataDir_OutPut;
    TM1637_CH;
    Delay_us(2);
    TM1637_CL;
    }
    void TM1637_stop(void){
    TM1637_CL;
    Delay_us(2);
    TM1637_DL;
    Delay_us(2);
    TM1637_CH;
    Delay_us(2);
    TM1637_DH;
    }
    void TM1637_writeByte(unsigned char wr_data){
    unsigned char i;
    for(i=0;i<8;i++){
    TM1637_CL;
    if(wr_data&0x01)TM1637_DH;
    else TM1637_DL;
    Delay_us(3);
    wr_data=wr_data>>1;
    TM1637_CH;
    Delay_us(3);
    }
    TM1637_ACK();
    }
    void TM1637_Command(unsigned char command){
    TM1637_start();
    TM1637_writeByte(command);
    TM1637_stop();
    }
    void TM1637_SetAuto(){
    TM1637_Command(TM1637_AUTO);
    }
    void TM1637_SetFixed(){
    TM1637_Command(TM1637_FIXED);
    }
    void TM1637_SetDisplay_Brightness(uint8_t brightness){
    TM1637_Display_Brightness=brightness;
    }
    void TM1637_Display_On(){
    TM1637_Command(TM1637_DISPLAY_ON+TM1637_Display_Brightness);
    }
    void TM1637_Display_Off(){
    TM1637_Command(TM1637_DISPLAY_OFF);
    }
    int8_t coding(int8_t DispData){
    //uint8_t PointData;
    //if(TM1637_PointFlag == POINT_ON)PointData = 0x80;
    //else PointData = 0;
    if(DispData == INDEX_BLANK)DispData = 0x00;// + PointData;//The bit digital tube off
    else DispData = IntTab[DispData];// + PointData;
    return DispData;
    }
    void TM1637_Fixed_Write(unsigned char segment,uint8_t integ){
    TM1637_SetFixed();
    TM1637_start();
    unsigned char dat=coding(integ);
    TM1637_writeByte(TM1637_GRID_ADD|(segment-1));
    TM1637_writeByte(dat);
    TM1637_stop();
    }
    void clearSegment(unsigned char segNumber){
    TM1637_Fixed_Write(segNumber-1,0x7f);
    }
    void clearDisplay(void){
    for(uint8_t i=TM1637_Segment_Start-1;i<=TM1637_Segment_Count;i++){
    TM1637_Fixed_Write(i,0x7f);
    }
    }
    void coding_Table(){
    for(int i=TM1637_Segment_Start-1;i<TM1637_Segment_Count;i++)
    {
    TM1637_Segment_Data = coding(TM1637_Segment_Data);
    }
    }
    void convert_int(uint16_t integer){
    unsigned char thousands ,hundreds,tens,ones;

    thousands = integer / 1000;
    integer = (integer - thousands*1000);
    if(thousands==0)thousands=INDEX_BLANK;

    TM1637_Segment_Data[3]=thousands;
    hundreds =integer / 100;
    if((thousands==INDEX_BLANK)&&(hundreds==0))hundreds=INDEX_BLANK;
    TM1637_Segment_Data[2]=hundreds;

    tens=(integer%100)/10;
    if((thousands==INDEX_BLANK)&&(hundreds==INDEX_BLANK)&&(tens==0))tens=INDEX_BLANK;
    TM1637_Segment_Data[1]=tens;

    ones=integer%10;
    TM1637_Segment_Data[0]=ones;
    coding_Table();
    }
    void display_WriteInt(int16_t integer) //this routine will print any int to lcd directly
    {
    unsigned char i;

    convert_int(integer);
    TM1637_SetAuto();
    TM1637_start();
    TM1637_writeByte(TM1637_GRID_ADD); // Set the first address
    for(i=TM1637_Segment_Start-1;i<TM1637_Segment_Count;i++) // Addresses from Canada, do not always write address
    {
    TM1637_writeByte(TM1637_Segment_Data); // Send data
    }
    TM1637_stop();
    }
     

    static void SmgDisplay(void) // Write display register
    {
    unsigned char i;
    unsigned char SegData;

    TM1637_SetAuto();

    TM1637_start();
    TM1637_writeByte(0xc0); // Set the first address
    for(i=TM1637_Segment_Start;i<=TM1637_Segment_Count;i++) // Addresses from Canada, do not always write address
    {
    SegData = coding(i+1);
    TM1637_writeByte(SegData); // Send data
    }
    TM1637_stop();
    TM1637_Display_On();
    }
    #18
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2019/04/02 12:24:27 (permalink)
    0
    arthurmk
    here are still solutions

    This forum requires "code" tags around code for it to display correctly.
    They look like this:
    [CODE]   
    /*
    * File: TM1637.h
    * Author: Arthur Mkoyan
    [/CODE]
     
    except in lower case, so you get
       
    /*
    * File: TM1637.h
    * Author: Arthur Mkoyan

     
    Without them, array indices look like formatting commands, which is why some of your code is missing the indices, and shows in italic text instead.

    Nearly there...
    #19
    citizen3942
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2019/04/02 04:37:33
    • Location: 0
    • Status: offline
    Re: Interfacing the PIC16F628A with a TM1637 (Chinese) Multiplexed LED Display 2019/04/08 00:41:23 (permalink)
    0
    I have tried to modify this TM1637 library I found from this thread (unfortunately for newer PIC16F generation) to be compatible with 6 digit LED segment display from RobotDyn and PIC16F628A but I have been quite unlucky getting it operational. I have attached my version of the TM1637 library, but I am sure, that I have some problem in there.
    My PIC is running with OSC1 VCTCXO at 16.3676 MHz, and I am trying to count frequency on pin RA4, finally showing that on the display.
    If someone could review it and propose a fix for it - that would be very much appreciated for me and the community as well.
    #20
    Page: 123 > Showing page 1 of 3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5