Homemade MCU Part 3: Making and driving digital tube circuit

Publisher:清新风华Latest update time:2016-12-15 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The usage of digital tubes is no different from that of light-emitting diodes. It is just that seven or eight light-emitting diodes are combined on a module to form an 8-shaped figure and a decimal point to display numbers. In order to reduce the number of pins, the same poles of each light-emitting tube are connected together as a common point, thus giving rise to the concept of common anode and common cathode digital tubes. Common anode tubes are to connect the positive poles of each light-emitting tube together, while common cathode tubes are just the opposite. See the figure below:

Generally speaking, the absorption current of most logic ICs is Stronger than the output current. Therefore, everyone likes to use common cathode digital tubes, because there are more optional ICs. Unfortunately, my set of digital tubes is common anode, so I plan to use a three-stage tube to drive the common end. My minimal system board: I use the most commonly used S9012. First I have to plan The best circuit method is to use the most commonly used dynamic scanning display. First build the simplest circuit and debug the parameters of the components to be used. src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://hiphotos.baidu.com/txz01/pic/item/61ee2c3e20ee4c3471cf6c8e.jpg?_=3264179% 22%20style=%22border:none;max-width:1333px%22%3E%3Cscript%3Ewindow.onload%20= %20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.8095873957499862',width:img.width,height:img .height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0">Don't connect R2 and 74HC244 in the above picture yet. One segment of the digital tube is directly grounded. When adjusting R1, it is measured that when the base current of S9012 is 0.21mA, the collector, that is, the digital tube, has 40mA, indicating that the amplification factor is sufficient. At this time, connect R2 and 74HC244, adjust R2 to control the current of the digital tube at 15mA, so that when the 8 segments are lit together, the transistor needs 120mA of current. The base needs 0.63mA. In order to reduce the load of the transistor, Make the transistor oversaturated, adjust R1 so that the base current is 2mA, and the voltage between the collector and the drain is about 0.1V. Good! At this time, R1 is 2K. R2 is 240 ohms. OK. The next step is to determine the circuit. There are three groups of interfaces between the circuit interface and AT89S51: segment code, bit code and power supply. In order to make AT89S51 independent, these three levels of interfaces are all made of pins, and are freely connected to the P1-P3 ports of AT89S51 with flat cables. The power supply is connected with a short-circuit cap. The completed board is shown in the figure below reverse side: Description: Then write the program. Let's write a query method first!com');%7D%3C/script%3E" frameborder="0"> reverse side: Description: Then write the program. First write a query method Yeah!com');%7D%3C/script%3E" frameborder="0"> reverse side: Description: Then write the program. First write a query method Yeah!
//The six-digit code tube is flashing at an interval of 0.3 seconds. This is a query method, which takes up more CPU resources./************************************************************************Define
pins
: P2_0------upper horizontal a P3_0-------ones
                  P2_1-----upper right vertical b P3_1-------ten
                  P2_2-----lower right vertical c P3_2-------hundreds
                  P2_3-----lower horizontal d P3_3-------thousands
                  P2_4-----lower left vertical e P3_4-------ten thousand
                  P2_5-----upper left vertical f P3_5-------hundred thousand
                  P2_6-----middle horizontal g
                  P2_7-----decimal point H
******************************************************************/
# include
typedef unsigned char uchar;
uchar code bit_num[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};//bit code value table: 0,1,2,3,4,5
uchar code meg_val[]={0x03,0x9f,0x25,0x0d,0x99,0x49};//segment code value table: 0,1,2,3,4,5
uchar code hello[]={0x03,0xe3,0xe3,0x61,0x91,0xff}; //HELLO
uchar code beybey[]={0x89,0x61,0xc1,0x89,0x61,0xc1};//beybey
uchar code ab6789[]={0xc1,0x11,0x09,0x01,0x1f,0x41};//ab6789
void delay(int n);
void main(void)
{
       uchar i,m;
       P2=0xff; //Turn off the segment code first
       P3=0xff; //Turn off the bit code
       delay(20);//Wait for a
       whilewhile(1)
        {
          for (m=30;m>0;m--) //Display 30 times, about 0.3 seconds
{
        for(i=0;i<=5;i++)
               {
                P2=0xff;
                P3=bit_num[i]; //Output bit code to P3 port
                P2=ab6789[i]; //Output segment code to P2 port
                delay(5);
        }
      }
          P2=0xff; //Turn off segment code
          P3=0xff; //Turn off bit code
          delay(1000); //Wait for 0.3 seconds
         }
}void delay(int n) //Subroutine
{
       int j;
       uchar k;
       for(j=0;j        {
          for(k=255;k>0;k--);
        }
}
=========================================
When I write the program into the chip and plug it in to run, it is garbled. Guess what happened?
It turns out that the direction of the P2 port is reversed. Have you noticed that in the AT89S51 pin arrangement, P0--P1 and P3 are all PX_0 on the top. Only the P2 port pin arrangement is P2_0 on the bottom. The direction is reversed. Since it is reversed, I will rewrite the segment code table. Try again, everything is normal.
Here I will talk about the arrangement of the segment codes. Many people asked how the digital tube segment codes are arranged. I also checked on the Internet, and it seems that there is no standard arrangement. It depends on your own connection method. This is also the reason why some digital tube programs downloaded on the Internet cannot be displayed normally on your own board. Generally speaking, the top diagram I have is the most marked. In the above program, it was originally intended that P2_0 corresponded to segment code a (that is, the horizontal line above). Until P2_7 corresponds to segment h (that is, the decimal point). As a result, who knew that the P2 port was just reversed. In this way, it is reversed, and P2_0 corresponds to segment h (the decimal point). For example, the digital tube I originally defined to display "2" segment code is 10100100B. Once it is connected in reverse, it is no longer "2". If you want to display "2" again, you have to reverse the high and low bits of the segment code. Change it to 00100101B and it will be OK. Here is another one that uses interruption to display: //This uses interruption mode and also flashes.
/************************************************************************
Define pins: P2_0------decimal point P3_0------units  
                  P2_1------middle horizontal P3_1------tens
                  P2_2------upper left vertical P3_2------hundreds
                  P2_3------lower left vertical P3_3------thousands
                  P2_4------lower horizontal P3_4------ten thousand
                  P2_5------lower right vertical P3_5------hundred thousand
                  P2_6------upper right vertical
                  P2_7------upper horizontal
******************************************************************/
# include
typedef unsigned char uchar;
uchar code bit_num[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};//bit code: 0,1,2,3,4,5
uchar code meg_val[]={0x49,0x99,0x0d,0x25,0x9f,0x03};//segment code: 0,1,2,3,4,5
uchar i,aa; //define global variable
bit fg; //define a light on and off flag void timer0(void) interrupt 1 using 1 //interrupt program
{
      if (fg) //light up the 6-bit digital tube when fg is 1
       { P2=0xff;
         if (i>=6)
           {
             i=0;
            }
         else
           {
             P3=bit_num[i]; //output bit code to P3 port
             P2=meg_val[i]; //output segment code to P2 port
             i++;
            }
       }
      else //When fg is 0, turn off the digital tube
        {
           if (aa==0)
         {
           P3=0xff;
           P2=0xff;
                }
         }
       aa++;
       if (aa>=254) //When the value of aa is accumulated to 254, the fg flag flips.
         {
           fg=~fg; 
           aa=0;
}
       TH0=0xf8; //Reinstall the initial value of the timer, 2ms, the value is 65536-2000
       TL0=0x30;
}
void main(void)
{
       P2=0xff; //First turn off the segment code
       P3=0xff; //Turn off the bit code
       TMOD=0x01; //Set T0 to mode 1
       TH0=0xf8; //Load the initial count high bit
       TL0=0x30; //Load the initial count low bit
       EA=1; //Total charge allowed
       ET0=1; //T0 charge allowed
       fg=1; //Set the on/off flag to on
       TR0=1; //Start interrupt
       while(1);
}

OK!


Reference address:Homemade MCU Part 3: Making and driving digital tube circuit

Previous article:Homemade MCU 8…USB-ISP download cable
Next article:Homemade MCU Part 4… LCD1602 Driver

Recommended ReadingLatest update time:2024-11-16 14:32

Research on key technologies of ultra-high power density motor drive system for electric vehicles
The driving force behind the development of ultra-high power density motor drive systems is: with the same volume or mass, the output power is greater, the overtaking acceleration capability and high-speed continuous driving capability are stronger, and excellent power performance and driving experience are obtained
[Embedded]
Research on key technologies of ultra-high power density motor drive system for electric vehicles
SiC modules enable higher power density in motor drives
SiC modules enable higher power density in motor drives The traction drive consumes almost all of the energy in an electric vehicle (EV). Therefore, the drive system must be as efficient as possible while taking up minimal space with minimal weight—all in an effort to maximize the range of the EV. As the indust
[Embedded]
SiC modules enable higher power density in motor drives
Low-speed comparator for driving relays
Low-speed comparator for driving relays Function of the circuit When it comes to low-speed comparison circuits, people tend to think that it is a circuit with poor performance. In fact, this circuit can be used as a relay drive circuit. If a dedicated comparator IC is used, its response time is usually within h
[Power Management]
Low-speed comparator for driving relays
Three-phase PWM motor driver A3936 and its application
Abstract: A3936 is a DMOS three-phase PWM motor driver produced by Allegro Corporation of the United States. This paper introduces the main features, pin functions and working principle of A3936 in detail, and gives the hardware circuit design method of the three-dimensional servo drive control system of a certain t
[Industrial Control]
Three-phase PWM motor driver A3936 and its application
STM32 development board capacitive touch screen driver, single point effective
STM32 development board capacitive touch screen driver, single point effective   Header file touch.h: u8 ft5x0x_read_data(void); void ft5x0x_i2c_init(void);   struct _ts_event {     u16    x1;     u16 y1;     u16    x2;     u16 y2;     u16    x3;     u16 y3;     u16 x4;     u16    y4;     u16 x5;     u16    y5;     u8
[Microcontroller]
C51 driver for ds1302
#include "D:\reg51.h " //header file #define uchar unsigned char uchar settime ={1,2,3,4,5,6,7}; uchar readtime ;  //******************************************************************** sbit T_CLK = P1^1; //real-time clock clock line pin  sbit T_IO = P1^0; //real-time clock data line pin  sbit T_RST = P1^2; //real-tim
[Microcontroller]
Using Maxim's driver-comparator-load (DCL) devices and parameter measurements
Eliminate external relays by leveraging the built-in functionality of Maxim driver-comparator-load (DCL) devices and parametric measurement unit (PMU) chipsets Abstract: This application note describes the capabilities of Maxim's new PMU and DCL products and uses their features to meet specific PMU
[Analog Electronics]
Using Maxim's driver-comparator-load (DCL) devices and parameter measurements
Isolated drive circuit for micro drive current
In the interface circuit of a microcomputer, there are generally two ways to isolate the host and peripherals: one is to use a relay; the other is to use an optocoupler.      For products that use batteries, the power consumption of the battery must be given priority. The circuit in the attached picture uses a photocou
[Power Management]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号