TM1637 four-digit digital tube module driver (TM1637.h header file) 51 single-chip C language

Publisher:皮球Latest update time:2020-02-06 Source: 51heiKeywords:TM1637 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

TM1637 four-digit digital tube module is a 4-digit common anode digital tube (0.36 inches) display module with clock points. The driver chip is TM1637 and the driving mode is IIC. Therefore, only 2 signal lines are needed to enable the microcontroller to control the 4-digit 8-segment digital tube (the digital tube has 8 adjustable gray levels).


Control interface: 4 pins in total (GND, VCC, DIO, CLK), GND is ground, VCC is power supply, DIO is data input and output pin, CLK is clock signal pin.
 

TM1637.h microcontroller source program is as follows:

sbit CLK= P3^4; //define the clock line of the analog IIC bus

sbit DIO = P3^5; //define the data line of the analog IIC bus

  

code unsigned char tab[] = 

{

        0x3F,/*0*/

        0x06,/*1*/

        0x5B,/*2*/

        0x4F,/*3*/

        0x66,/*4*/

        0x6D,/*5*/

        0x7D,/*6*/

        0x07,/*7*/

        0x7F,/*8*/

        0x6F,/*9*/

        0x77,/*10 A*/

        0x7C,/*11 b*/

        0x58,/*12 c*/

        0x5E,/*13 d*/

        0x79,/*14 E*/

        0x71,/*15 F*/

        0x76,/*16 H*/

        0x38,/*17 L*/

        0x54,/*18 n*/

        0x73,/*19 P*/

        0x3E,/*20 U*/

        0x00,/*21 Black screen*/

}; 


void Delay_us(unsigned  int i)

{

        for(;i>0;i--)

                _nop_();;

}


//IIC starts

void TM1637_start(void)

{

         CLK=1;

         PART=1;

         Delay_us(2);

         PART=0;

}



//IIC response

void TM1637_ack(void)

{

        flying i;

        CLK=0;

        Delay_us(5);

         //PART=1;    

        while(DIO==1&&(i<250))i++;

        CLK=1;

        Delay_us(2);

        CLK=0;

}


//IIC stop

void TM1637_stop(void)

{

         CLK=0;

         Delay_us(2);

         PART=0;

         Delay_us(2);

         CLK=1;

         Delay_us(2);

         PART=1;

         Delay_us(2);

}


//Write data function

void TM1637_Write(unsigned char DATA)   

{

        unsigned char i;   

        for(i=0;i<8;i++)        

        {

                CLK=0;     

                if(DATA & 0x01)

                        PART=1;

                else DIO=0;

                 Delay_us(3);

                DATA=DATA>>1;      

                CLK=1;

                 Delay_us(3);

        }  

        //TM1637_ack();

}




// Display in order

void TM1637_display(fly a,fly b,fly c,fly d,fly h)

{


        TM1637_start();

        TM1637_Write(0x40); //Write data + automatic address plus 1 + normal mode

        TM1637_ack();

        TM1637_stop(); 

        TM1637_start();

        TM1637_Write(0xc0); //Set the display first address, i.e. the first LED

        TM1637_ack();


        TM1637_Write(tab[a]);

        TM1637_ack();

        TM1637_Write(tab[b]|h<<7); //When h is 1, the two points in the middle of the clock are displayed

        TM1637_ack();

        TM1637_Write(tab[c]);

        TM1637_ack();

        TM1637_Write(tab[d]);

        TM1637_ack();


        TM1637_stop(); 

        TM1637_start();

        TM1637_Write(0x89); //Turn on display, 2/16 brightness

        TM1637_ack();

        TM1637_stop();

}


Keywords:TM1637 Reference address:TM1637 four-digit digital tube module driver (TM1637.h header file) 51 single-chip C language

Previous article:51 single chip microcomputer controls the forward and reverse rotation of the motor
Next article:DS12887+lcd1602 perpetual calendar simulation schematic + program

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号