Control of digital tube of C51 single chip microcomputer

Publisher:QianfengLatest update time:2020-04-02 Source: eefocusKeywords:c51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Circuit Diagram

Note: In practice, the 74HC573 circuit of my microcontroller is connected in reverse with the P0 terminal.


138 decoder information: https://pan.baidu.com/s/1COTcutsnMxMSc8tq0M2yVw Password: 1jww


The truth table of 138 decoder:

74HC573 information: https://pan.baidu.com/s/1b5OJXniyd6gODyf_eA_sXA Password: m7zx


If you have studied digital electronics, you can take a quick look at the above. If not, it is recommended that you learn digital electronics before getting in touch with microcontrollers, or you can directly read the following.


process


1. First, you need to know how to correctly light up a digital tube (static display).


The interior of the digital tube is composed of seven strip-shaped LEDs and a small dot LED, and the characters are formed according to the brightness of each tube. Common digital tubes have 10 pins. There are two common terminals, which can be divided into common cathode and common anode according to the wiring form of the internal LED. When in use, the common terminal of the common cathode digital tube is grounded, and the common terminal of the common anode digital tube is connected to the power supply. Refer to the figure below:

By giving each pin a high or low level, the on and off of the digital tube can be controlled. Let's take an example. Take the common cathode digital tube as an example. To make the digital tube display the number 0, as long as the six pins abcdef input a high level, the digital tube can display the number 0. At this time, the hexadecimal is 0011 1111 (dp, g, f, e, d, c, b, a) 0x3f. Send the above 0x3f to the 74HC573 latch, and the latch is sent to the digital tube, which lights up the digital tube. (From: https://blog.csdn.net/fanyuqa/article/details/47395333). This time, a common cathode is used.


2. We have learned how to light up a digital tube. Now we will introduce which of the 8 digital tubes to light up.


This requires the use of a 138 decoder. Among them, G1=vcc, G2A=G2B=0, and the purchased circuit has been connected by default. In the above circuit, ABC are P22, P23, and P24 respectively;


If P22=0, P23=0, P24=1 (0 represents low level, 1 represents high level), that is, 001, the corresponding truth table is 4. That is, the 4th digital tube is selected.


Once you know how to select and light up a digital tube, you can start writing programs.


#include "reg52.h"  

typedef unsigned int uint;   

typedef unsigned char uchar;

 

sbit LSA=P2^2;

sbit LSB=P2^3;

sbit LSC=P2^4;

 

uchar code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,

0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //Display the value of 0~F

 

void main()

{

LSA=0;

LSB=0;

LSC=0;

P0=smgduan[0];

}

The procedure is relatively simple, but there are two things to note.


1. You cannot directly set P2^2=0;


2. After code+array, the array cannot be changed. https://zhidao.baidu.com/question/121263820.html


Here is a video of a static digital tube, which is quite good: https://pan.baidu.com/s/1I7Gz55NCO_yqopAWOr07QA Password: 3p7r


3. Dynamic digital tubes are based on static digital tubes, but different digital tubes are lit each time. When the interval is very short, the human eye cannot distinguish them and will feel that they are all lit at the same time.


#include

typedef unsigned int uint;

typedef unsigned char uchar;

sbit LSA=P2^2;

sbit LSB=P2^3;

sbit LSC=P2^4;

uchar out[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

 

void delay(uint num)

{

while(num--);

}

 

void display()

{

u8 i;

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

{

switch(i) //bit selection, select the digital tube to light up,

{

case(0):

LSA=0;LSB=0;LSC=0; break;//display bit 0

case(1):

LSA=1;LSB=0;LSC=0; break;//display the first bit

case(2):

LSA=0;LSB=1;LSC=0; break;//display the second digit

case(3):

LSA=1;LSB=1;LSC=0; break;//display the third bit

case(4):

LSA=0;LSB=0;LSC=1; break;//display the 4th bit

case(5):

LSA=1;LSB=0;LSC=1; break;//display the 5th bit

case(6):

LSA=0;LSB=1;LSC=1; break;//display the 6th bit

case(7):

LSA=1;LSB=1;LSC=1; break;//display the 7th bit

}

P0=out[i]; //Send segment code

delay(100); //Scan after a certain period of time

P0=0x00; //Blanking

}

}

 

void main()

{

while(1)

{

display(); 

}

}


Dynamic digital tube video tutorial: https://pan.baidu.com/s/1fLopEJvdCpouLziTaSWxmg Password: 7szd

Keywords:c51 Reference address:Control of digital tube of C51 single chip microcomputer

Previous article:51 MCU Introduction - Dot Matrix Display Programming Experiment
Next article:51 single chip microcomputer 38 decoder to realize dynamic digital tube control

Recommended ReadingLatest update time:2024-11-15 15:02

Using Problems in C51 Interrupts
The basic structure of the 8051 series MCU includes: 32 I/O ports (4 groups of 8-bit ports); two 16-bit timer counters; full-duplex serial communication; 6 interrupt sources (2 external interrupts, 2 timer/counter interrupts, 1 serial port input/output interrupt), two-level interrupt priority; 128 bytes of built-in RA
[Microcontroller]
[C51 code] LCD12864 header file [upper and lower screen]
Model: LCD12864a3 Driver: ST7920A Chinese character display coordinate diagram: Graphical display coordinate graph: /*==================== lcd12864.h =====================*/ #ifndef _LCD12864_h_ #define _LCD12864_h_ #include Atmel/AT89X51.h #include "delay.h" #include "link.h" /*==================
[Microcontroller]
[C51 code] LCD12864 header file [upper and lower screen]
Detailed explanation of data idata xdata code in keil c51
51 single-chip microcomputer adopts Harvard structure. The memory space addressing has overlap. Different variables can be defined on different buses (referred to as bus domains in this article, or domains for short). Several domain modifiers such as data, idata, xdata, and code are defined in keilc51. These modifiers
[Microcontroller]
Detailed explanation of data idata xdata code in keil c51
C51: write n data to 24C02, and then read n data
//Function function, //Write n data, then read n data. Display with LCD1602. #include reg51.h #include intrins.h   //Variable declaration #define uchar unsigned char #define uint unsigned int //Delay 1ms void delayms() {  uchar i;  for(i=0;i 250;i++);  for(i=0;i 80;i++); } void delaynms(uint s) {
[Microcontroller]
604 LCD screen input and output C51 source program
#include #include "INC\LCD1604.H" sfr LCD_INTER = 0x80; //Data bus interface  sbit LCDBUSY=LCD_INTER^7; //Flag bit sfr LCD_CONTROL = 0xA0; //Data bus interface  sbit LCDRS = LCD_CONTROL^0; //Data, instruction selection  sbit LCDRW = LCD_CONTROL^1; //Read and write selection  sbit LCDE = LCD_CONTROL^2; //Enab
[Microcontroller]
C51 Design of PID Control System for Water Tank Temperature
This system is a single-chip temperature control system based on PID. I found a complete program on the Internet and made the corresponding proteus hardware simulation according to his program, but It did not achieve the expected effect and needs to be improved. The procedure is as follows: #include<reg51.h   #inclu
[Microcontroller]
c51 parity bit application
    The parity bit P of the C51 special function register PWS, if the number of "1" in ACC is even, the hardware sets P = 0. If the number of "1" in ACC is odd, the hardware sets P = 1.     The sending end sends P to TB8 of SCON, and the parity information is sent together with the data frame.     The RB8 bit of SCO
[Microcontroller]
Single chip microcomputer timer T0 counts seconds C51 program + circuit
Schematic diagram: The c51 microcontroller program is as follows: #include reg51.h #define UCHAR unsigned char #define UINT  unsigned int   UCHAR table = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; FLY counter; FLY timer;   void inittime(void) { timer
[Microcontroller]
Single chip microcomputer timer T0 counts seconds C51 program + circuit
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号