51 MCU + TM1620 drive 3-digit digital tube program

Publisher:笑脸猫Latest update time:2016-12-10 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

TM1620 is a diode driver chip produced by Tianwei Company, SOP20 package. The chip is shown in the figure below:

TM1620 pin diagram

It can drive up to 6 8-bit digital tubes, as shown in the following figure:

TM1620 driver digital tube

The procedure is as follows:

/****************************************************** *
 * Name: STC51 drives TM1620 3-digit digital tube display
 * MCU: STC12C5608AD
 * Main frequency: 12Mhz (external 12MHz crystal oscillator)
 * Author: Ration
 * Date: December 5, 2013 (edited)
 * Copyright: Copyright belongs to "MCU Learning Network". Please keep integrity when disseminating.
 *
 * For more programs, please visit: http://www.rationmcu.com
 *************************************************/
#include "stc12c5608ad.h"
#include 

#define uint unsigned int // Macro definition uint (0~65535)
#define uchar unsigned char // 
#define uint32 unsigned long 


sbit STB =P3^2; // define chip select communication port
sbit CLK =P3^3; // Define the clock communication port
sbit DIO =P3^4; //Define data input/output communication port

uchar bai_num,shi_num,ge_num;


static uchar code LED_tab[11]={ //Define the digital code table of digital tube 0~9
0x3f, //0B00111111, //0
0x30, //0B00000110, //1
0x6d, //0B01011011, //2
0x79, //0B01001111, //3
0x33, //0B01100110, //4
0x5b, //0B01101101, //5
0x5f, //0B01111101, //6
0x70, //0B00000111, //7
0x7f, //0B01111111, //8
0x7B, //0B01101111, //9
0x4f, //E                                               
};

void delay_ms(uchar cyc)
{
    //When = 1, delay 1ms
    uchar ii,jj;

    for(jj=1;jj<=cyc;jj++)
    {
        for(ii=0;ii<200;ii++)
        {
            _nop_();
        }
    }
}


void TM1620_Write(uchar wr_data)
{
    uchar i;

    for(i=0;i<8;i++)
    {
        CLK = 0;
        if(wr_data&0x01)DIO = 1;
        else DIO = 0;
        CLK = 1;
        wr_data>>=1;
    }                 
}

void Write_COM(unsigned char cmd) //Send command word
{
    STB = 0;
    TM1620_Write(cmd);
    STB = 1;
}

void init_TM1620(void)
{
    Write_COM(0x44); // 01000000 ready to write data to the display register, normal mode, automatic address increase
    STB=0;
    TM1620_Write(0xc0); // 11000000 Set the display address to start from 0
    TM1620_Write(0x00); // All displays are off
    STB=1;
    STB=0;
    TM1620_Write(0xc2);
    TM1620_Write(0x00);
    STB=1;
    STB=0;
    TM1620_Write(0xc4);
    TM1620_Write(0x00);
    STB=1;
    Write_COM(0x8f); // Brightest 10001111 Set extinction pulse 14/16 Display on
}

void led_show()
{
// Write_COM(0x44); // 01000000 ready to write data to the display register, normal mode, automatic address increase
    STB=0;
    TM1620_Write(0xc0); // 11000000 Set the display address to start from 0
    TM1620_Write(LED_tab[bai_num]); // All displays are off
    STB=1;
    STB=0;
    TM1620_Write(0xc2); // 11000000 Set the display address to start from 0
    TM1620_Write(LED_tab[shi_num]); // All displays are off
    STB=1;    
    STB=0;
    TM1620_Write(0xc4); // 11000000 Set the display address to start from 0
    TM1620_Write(LED_tab[ge_num]); // All displays are off
    STB=1;
}





void main()
{
    CLK = 1; // Pull up the TM1620 communication clock pin
    STB = 1; // Pull up the TM1620 communication chip select pin
    DIO = 1; // Pull up the TM1620 communication data pin

    init_TM1620(); // Initialize the LED control chip
    bai_num=0;
    shi_num=0;
    ge_num=0;
    led_show();

    while(1)
    {
        ;
    }
}

Please obtain the complete Keil project file as follows!


Reference address:51 MCU + TM1620 drive 3-digit digital tube program

Previous article:Solution to 51 MCU PWM duty cycle less than 0
Next article:stc51 MCU pwm program stc12c5608ad

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号