The learning journey of a MCU beginner (Part 7) --- Dynamic display of digital tubes

Publisher:神秘行者Latest update time:2020-03-29 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the previous article, we talked about using 74LS138 to control the bit selection of digital tubes. How to select it? Let's take a look at the manual of this decoder.


74LS138

/Y0--/Y7 is data output


A0--A2 is data input


/E1, /E2, E3 are enable controls, /E1 and /E2 are low level effective, E3 is high level effective


VDD is connected to the power supply; GND is connected to the ground


The most important thing is the truth table, to explain how it works


/E1 and /E2 are low level valid, E3 is high level valid, as long as one of them does not meet the conditions, /Y0--/Y7 will all output high level, our common cathode digital tube will not light up


All are satisfied from the fourth row onwards, and now you can look at A0--A2, the order is A2-


A1-A0, from top to bottom, are 000, 001, 010, 011, 100, 101, 110, 111. This shows that they are binary 0, 1, 2, 3, 4, 5, 6, 7. Look at the right half of Y0, 000 is Y0, 001 is Y1, 010 is Y2... Once you correspond, you will know how it is controlled?


Code:


Digital tube dynamics

There is a switch statement switch(i) which judges i. When i is 0, the statements after case 0 are executed. Add a break after each statement, otherwise the following statements will be executed continuously.


A for loop realizes the requirement that different digital tubes display different numbers. When i is 0, the first digital tube lights up and the number is 0. When i is 1, the second digital tube lights up and displays the number 1.


P0 = 0x00 is to make the P0 port more stable and return to its original position


I suddenly had an idea halfway through writing, which made it more difficult. I had to display it once and then do it again in reverse.


Improve

In fact, a nested for loop is added, which is judged as follows...


That 9 took a lot of time. I kept writing 8, so the display was 0, 1, 2, 3, 4, 5, 6, 0, 7, 6, 5, 4, 3, 2, 1, 0


I thought a and i were synchronized. I was careless and my foundation was not solid. a is in the order of 1, 2, 3, 4, 5, 6, 7... So when i is 7, a is 8, so here I write <9


The case 4 is protruding out of hand because of carelessness, but this is C language so the indentation is not a problem. If it is Python that relies on indentation for positioning, there will be a problem, but it seems that Python is rarely used to write microcontrollers. . . .


*

Reference address:The learning journey of a MCU beginner (Part 7) --- Dynamic display of digital tubes

Previous article:The MCU Learning Journey for Beginners (Twenty-one) --- Understanding MCU Serial Communication (I)
Next article:The Path of Learning for a Newbie in Microcontrollers (Part 1)

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号