According to the project requirements, you can use I/O external pull-up to drive the digital tube; you can also use 74HC138 (38 decoder) + 74HC245 (8-way signal transceiver) to drive the digital tube. This article will use the latter as the digital tube driving circuit to realize the display of the digital tube in the code.
Drive circuit:
Circuit explanation:
1) The digital tube components use common cathode digital tubes. If a certain digital tube needs to be lit, the bit select pin needs to be pulled to a level;
2) The eight digital tubes have 8 bit selection pins and 8 segment selection pins. In order to save I/O ports, 74HC138 is used to convert the 3-bit (CBA) selection into an 8-bit binary code. For example, when the CBA value is 000, Y0 outputs a low level, and the rest are high levels. Since Y0 is connected to the digital 1 bit selection pin (LED1 network label in the figure), digital tube 1 is selected.
3) 74HC138 controls the bit select pin, while 74HC245 controls the segment select pin to enhance the driving capability. In the circuit schematic, DIR is connected to a high level and OE is connected to GND, so that its working state is An input and Bn output. When P0 outputs 0x00, Bn terminal will also output 0x00;
Code:
1) The digital tube displays the value and has the corresponding code (the segment corresponding to the code is lit or not);
2) The digital tube codes are stored in a one-dimensional array according to a certain relationship (usually in the order of 0 to F);
3) 74HC245 transceiver, mainly used to drive the digital tube. According to the digital tube display, it can be seen that P0 data directly reaches the digital tube;
4) Call the element of the one-dimensional number, output the coded value through the I/O port, control the segment selection signal, and display the corresponding value;
5) Digital selection of digital tube, digital conversion into 3-way input signal of 38 decoder, select a digital tube for display.
Realize the digital tube display function:
void showsmg(uchar selsmg,uchar num){
//Select the number of digital tubes to be displayed, and disassemble it into the corresponding code of 38 decoder
smg0 = selsmg&0x01;
smg1 = (bit)((selsmg>>1)&0x01);
smg2 = (bit)((selsmg>>2)&0x01);
//Assign the digital tube code (one-dimensional array) to port P0 to display the corresponding digital
P0 = table[num];
}
Specific display code:
Function: 8 (7~0) digital tubes, displaying 7~0 from high to bottom;
/********************************************************************************
* @File name: main.c
* @Author: AdamChen
* @Version: 1.1
* @Date: 2020-08-07
* @Description: LED display
* @contact:975805363@qq.com
************************************************************************************/
#include "reg52.h"
typedef unsigned char uchar;
typedef unsigned int uint;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x80};
sbit smg2 = P2^4;
sbit smg1 = P2^3;
sbit smg0 = P2^2;
/***********************************************************
* Function name: delay
* Description: Delay function
* Parameter :
@ms millisecond
* Return :None
**************************************************************/
void delay(unsigned int ms) // ms represents the number of milliseconds required for delay
{
uint x,y;
for(x=ms;x>0;x--)
for(y=110;y>0;y--);
}
/***********************************************************
*
* Function name: showsmg
* Description: Digital tube display
* Parameter :
@selsmg Select the number of digital tubes
@num Displays the value
*
* Return :None
**************************************************************/
void showsmg(uchar selsmg,uchar num){
//Select the number of digital tubes to be displayed, and disassemble it into the corresponding code of 38 decoder
smg0 = selsmg&0x01;
smg1 = (bit)((selsmg>>1)&0x01);
smg2 = (bit)((selsmg>>2)&0x01);
//Assign the digital tube code (one-dimensional array) to port P0 to display the corresponding digital
P0 = table[num];
}
/***********************************************************
*
* Function name: main
* Description : 8 digital tubes, display 7 to 0 from high to low.
* Parameter: None
* Return :None
**************************************************************/
void main(){
uchar i;
while(1){
//Cycle selection, 8 digital tubes, display 7~0
for(i=0;i<8;i++)
{
showsmg(i,i);
delay(1);
}
}
}
Previous article:C51 Programming 8- Digital Tube (Working Principle 2)
Next article:C51 Programming 10-I/O Port Comprehensive Exercise
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Greenhouse automatic spraying system ---- H743 water lamp
- Design of wireless serial port hub using ARM microprocessor and ZigBee module
- [TI recommended course] #Live replay: TI mmWave millimeter wave radar application in automobiles#
- 1602 display dht11 temperature and humidity
- CircuitPython 6.1.0 released
- 【RT-Thread Reading Notes】+ Pain and Happiness
- Data acquisition technology based on SDI-12 bus (communication protocol)
- 04. WS2812B driver implementation of SPI
- In-depth disassembly | The magical use of Qorvo chips in handheld vacuum cleaners
- Please ask a MicroPython question