51 MCU Experiment 5: Dynamic Digital Tube

Publisher:星光闪耀Latest update time:2020-04-25 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The circuit diagram of the digital tube module of the development board is as follows:

Due to the characteristics of the 74ls138 decoder, that is, only one digital tube can have a cathode level of 0, it is obviously impossible to make multiple digital tubes work at the same time. If you want to get the effect of multiple digital tubes working at the same time, you can only use the dynamic scanning display method. The so-called dynamic scanning display is to use the afterglow of the light-emitting tube and the visual persistence of the human eye to make people feel as if multiple digital tubes are working at the same time.


In the program, the digdisplay function uses for loops and switch statements to continuously scan the 8 digital tubes, complete the bit selection, and assign values ​​to the P0 port to realize the segment selection function. Thus, the 8 digital tubes output 1 to 8 in sequence, and use the delay function to control the output interval time to realize the dynamic output function.


detail:

(1) Set a certain delay after each digital tube displays.


(2) Set P0 to 0 (P0 = 0x00) to achieve the purpose of "erasing the image".


#include

#define uc unsigned 

sbit lsc=P2^2;

sbit lsb=P2^3;

sbit lsa=P2^4;

void delay(uc n)

{

    uc i,j;

    for(i=1;i<=n;i++)

      for(j=110;j>=1;j--);

}

uc code x[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,

0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

void digdisplay()

{

uc i;

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

{

switch(i)

{

case (1): lsa=0,lsb=0;lsc=0;break;

case (2): lsa=0,lsb=0;lsc=1;break;

case (3): lsa=0,lsb=1;lsc=0;break;

case (4): lsa=0,lsb=1;lsc=1;break;

case (5): lsa=1,lsb=0;lsc=0;break;

case (6): lsa=1,lsb=0;lsc=1;break;

case (7): lsa=1,lsb=1;lsc=0;break;

case (8): lsa=1,lsb=1;lsc=1;break;

}

P0=x[i];

        delay(1);

        P0=0x00;

}

}

void main()

{

    

    while(1)

    {

digdisplay();

    }

}


Advanced: Use digital tubes to output different digital combinations at intervals.


#include

#define uc unsigned char

sbit lsa=P2^2;

sbit lsb=P2^3;

sbit lsc=P2^4;

uc code x[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,

0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

void delay1(uc n)

{

uc i,j;

for(i=1;i<=n;i++)

  for(j=1;j<=110;j++);

}

void digdisplay(int n)

{

uc i;

if(n==1)

{

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

{

switch(i)

{

case(0): lsc=0;lsb=0;lsa=0; P0=x[0];break;

case(1): lsc=0;lsb=0;lsa=1; P0=x[2];break;

case(2): lsc=0;lsb=1;lsa=0; P0=x[5];break;

}

delay1(1);

}

}

    else

{

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

{

switch(i)

{

case(0): lsc=0;lsb=0;lsa=0; P0=x[4];break;

case(1): lsc=0;lsb=0;lsa=1; P0=x[1];break;

case(2): lsc=0;lsb=1;lsa=0; P0=x[3];break;

case(3): lsc=0;lsb=1;lsa=1; P0=x[1];break;

}

delay1(1);

}

}

}

void delay2(uc n)

{

uc i,j;

for(i=1;i<=10;i++)

  for(j=1;j<=110;j++)

  digdisplay(n);

}

void main()

{

while(1)

{

delay2(1);

delay2(0);

}

}

Reference address:51 MCU Experiment 5: Dynamic Digital Tube

Previous article:51 MCU Experiment 4: Static Digital Tube
Next article:STC89C52 series MCU internal resources - interrupt system

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号