C51 programming 9-digital tube (display)

Publisher:Blissful567Latest update time:2022-06-23 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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);

    }         

  }

}

Keywords:C51 Reference address:C51 programming 9-digital tube (display)

Previous article:C51 Programming 8- Digital Tube (Working Principle 2)
Next article:C51 Programming 10-I/O Port Comprehensive Exercise

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号