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!
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
- Popular Resources
- Popular amplifiers
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Modern Product Design Guide
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- TGF4042 Function Signal Generator Review: Unboxing and Trial
- 【McQueen Trial】Python Programming (3)
- [Reprint] Summary of Zynq7010 NAND startup
- Free sharing of LDO and DCDC basic principle explanation video
- No response when controlling GPIO in user mode?
- Logistics POS machine with serial port expansion IC
- EEWORLD University Hall----Live Replay: Infineon system solutions make electric motorcycle design more reliable and efficient!
- EEWORLD University Hall----Live Replay: ADI's smoke detector integrated solution based on ADPD188BI
- How to use 4G base stations and 5G base stations in rural areas
- EEWORLD University Hall----Live Replay: Fujitsu Empowers Automotive Electronics Technology Transformation