Mf work-C # digital tube and dancing with the horse and lanterns (video)

Source: Internet
Author: User

through the legend of C # lighting, we understand the most basic input and output functions of single-chip microcomputer, that is, the so-called gpio .
this time, we need to add more "Lights"-digital tubes and four digital tubes .
first, go to the result and watch the video:

this video is a mixture of four digital tubes, LCD screen and marquee, it is better than the previous small flashing.

brief introduction to the principles of digital tubes
digital tubes are also called seven-segment digital tubes, A complete number of 8 uses seven small lights, and the decimal point is eight small lights. Well, each section is a small lamp, so the operation method is the same as that in the lighting myth
, but there are a lot more. Four digits, each digit with eight small lights, then there are a total of 32, plus grounding or high level, at least 33 feet, wiring is a very complex project.
however, our four digital tubes have only 12 feet, eight of which are responsible for the same small lamps of each number, and the four are left to choose which number to provide power. This involves a very sad thing: when you control the light position and prepare to control the output of ten digits, A single digit will go out, because ten digits are selected for the selected foot. If you select a single digit at the same time, only the same number as the ten digits will be placed, because the same segment of different numbers share the same pin !
what should I do ?? Some people think that there is a problem with the design of the digital tube, and there should be something like a LCD screen that is locked after each display.
the design of these digital tubes is no problem. On the contrary, they are still very subtle! As mentioned above, if the traditional gpio approach is adopted, the four digital tubes require 33 feet, which is a very waste of Pin resources. Imitation
according to the principle of the computer serial port hard drive, we can also use the serial port to control multiple digital tubes. In fact, N-bit digital tubes only need n + 8 pins.
how to solve the "Lock" problem? In fact, there is no need to solve this problem. We can use the visual error of the human eye. You must know that the basic principle of animation is also like this. After a single position is displayed, it will last for a short period of time, then display ten digits, then display hundreds of thousands of places, one by one. As long as the whole process is fast, our human eyes will think that they are lit up together!

Wiring
Let's take a look at the global layout. Here we have connected the LCD screen, the digital tube (the one on the LCD screen), and 10 small lights. Other things are made up of decoration. Too many things are messy. Sorry! Students with insufficient dubang lines can separate the experiment.

10 small lights of various colors, connected to the bread, ready for running horse lights. The following line is grounded Gnd.
The bottom right is Board The left pin schematic. We select 10 arrows from pg0 to Pg1, And the Gnd in the lower left corner.
Here, I intentionally made a mistake and used the master pin. In fact, on Explorer 1, the master node is connected to the buzzer. Now, if the driver is sufficient, I think that, you should be able to hear the background sound of the beep on the screen.

Thu
12-foot digital access method. You may find that many pins on the board are inserted with green jumpers. In fact, it is a mark I made, indicating that this foot has been used by other devices, to avoid
Conflict. Careful students can find that the digital tube routine of the explorer board 1 works normally when the LCD screen is not connected. After the LCD screen is connected, the LCD screen does not work and the LCD screen is abnormal. This is pin punch
Burst, just a lot of feet were used by the LCD screen.
Therefore, 12 additional digital tubes are selected here, from pc0 to pc1.
Digital tube, front facing you, there is a decimal point at the bottom, then, behind the bottom left is Pin 1, counter-clockwise, until the upper left corner of the 12. In this order, the digital tube and board needle are connected.

Source code
Digital tube source code. The principle is very simple. Open a thread and constantly refresh the numbers to be displayed, so you cannot stop. Oh, that's right. Single-Chip Microcomputer can also use the thread in. net!

Digital tube source code

 Using  System;  Using  System. Threading;  Using  Microsoft. Spot. hardware;  Namespace  Mftest {  ///   <Summary>  Four digital Tubes  </Summary>      Class  Led4 { ///   <Summary>  The number of segments for each number. one byte uses only seven bits, which indicates the clockwise direction of the seven CIDR blocks.  </Summary>          Static   Readonly Byte [] leddigitals = New Byte [] { 0x3f , 0x06 , 0x5b , 0x4f , 0x66 , 0x6d , 0x7d ,0x07 , 0x7f , 0x6f , 0x77 , 0x7c , 0x39 , 0x5e , 0x79 , 0x71  };  ///   <Summary>  Digital tube public foot  </Summary>          Public Int32 [] publicpins = New Int32 [] { 6 , 8 , 9 , 12  };  ///   <Summary>  Seven-segment digital tube foot  </Summary>          Public Int32 [] sevenpins = New Int32 [] { 11 , 7 ,4 , 2 , 1 , 10 , 5 , 3  };  ///   <Summary>  Actual Control Panel pins  </Summary>          Public  CPU. Pin [] ledpins; outputport [] ports;  Private  Int32 _ value; ///   <Summary>  Number to be displayed  </Summary>          Public Int32 value { Get { Return _ Value ;} Set {_ Value = Value ;}}  Private  Boolean _ ishex;  ///   <Summary>  Base. Only decimal and hexadecimal formats are supported. </Summary>          Public Boolean ishex { Get { Return _ Ishex ;} Set {_ Ishex = Value ;}} thread th;  Public   Void  Start (){  If (Ledpins = Null | Ledpins. Length < 1 ) Throw  New Exception ( "  No pins for led4!  "  ); Ports = New  Outputport [ledpins. Length];  For ( Int I = 0 ; I <ledpins. length; I ++ ){  //  I = 2 is foot 3, is DP Ports [I] =New Outputport (ledpins [I], I = 2 | Array. indexof (publicpins, I + 1 )> = 0  );}  For ( Int I = 0 ; I <ledpins. length; I ++ ) {Ports [I]. Write (  False  );} Th = New Thread (DIS); th. Start ();}  Public   Void  Stop (){  If (Th = Null ) Return  ; Th. Abort (); th = Null  ;}  Void  DIS (){  If  (Ishex) While ( True  ) Shownumber16 (value );  Else                  While ( True  ) Shownumber (value );}  Void  Shownumber (int32 N ){  For ( Int I = 0 ; I < 4 ; I ++){  //  If you want to display 0 instead of the first number, disable the display.                  If (N = 0 & I> 0  ) {Showdigital (I,  0 , False  );}  Else  {  //  Number to be displayed this time Showdigital (I, n % 10 , True  ); N = N/ 10  ;}}}  Void  Shownumber16 (int32 N ){  For ( Int I = 0 ; I < 4 ; I ++ ){ //  If you want to display 0 instead of the first number, disable the display.                  If (N = 0 & I> 0  ) {Showdigital (I,  0 , False  );}  Else  {  //  Number to be displayed this time Showdigital (I, N &0xf , True  ); N = N> 4  ;}}}  Void  Showdigital (int32 index, int32 N, Boolean show ){  //  Locate control pin              VaR Pin = ports [publicpins [Index]- 1  ];  // If it is not displayed, it is returned directly after it is disabled.              If (! Show) {pin. Write (  False  );  Return  ;}  //  7-segment representation of the output number              VaR D = Leddigitals [N];  For ( Int I = 0 ; I <7 ; I ++ ){  VaR P = ports [sevenpins [I]- 1  ]; P. Write (d > I & 0x1 ) = 0  );}  //  Disable decimal point Ports [sevenpins [ 7 ]- 1 ]. Write ( True );  //  Output numbers first, and then turn on and off Pin. Write ( True  );  //  Then, wait for a while to form a visual effect. Thread. Sleep ( 5  );  //  Close at last to prepare for the next display Pin. Write ( False  );}}} 

 

Control source code.

 

Control Code

 //  Explorer 1  //  Marquee pins  VaR Pins = New  CPU. pin [] {pins. PG1, pins. pf15, pins. pf13, pins. pf11, pins. PB1, pins. PC5, pins. pg0, pins. pf14, pins. pf12, pins. PBS };  VaR LEDs = New  Outputport [pins. Length];  For ( Int I =0 ; I <pins. length; I ++ ) {LEDs [I] = New Outputport (pins [I], I % 2 = 0  );}  VaR Led4 = New  Led4 ();  //  Digital tube pins Led4.ledpins = New CPU. pin [] {pins. pc0, pins. pf9, pins. pf7, pins. pf5, pins. PF3, pins. pf1, pins. pf2, pins. pf4, pins. pf6, pins. pf8, pins. pf10, pins. pC1}; led4.ishex = True ; //  Display in hexadecimal format  Led4.start ();  VaR K = 0  ;  For ( Int I = 0 ; I < 20000 ; I ++ ){ For ( Int J = 0 ; J <LEDs. length; j ++ ) {LEDs [J]. Write (K = J );}  If (K ++> = LEDs. Length) k = 0  ; Led4.value = I; thread. Sleep (  50  );} Led4.stop (); 

 

 

Everything is ready! SetProgramWrite to the Explorer 1 board. After restart, the digital tube is displayed in numbers, and the 10 small lights are highlighted from left to right.
If you are using other boards, select the pins and modify the control slightly.CodeYou can! Experiment can be separated due to insufficient pins!

 

You are welcome to study the study together! The page header contains the group number and Forum information address.

 

If you think this article is useful to you, please give me a suggestion. Thank you! O (partition _ partition) O

If you think this article is poor and you are suspected of misleading others, please give us an objection, give your distinguished comments, and make some improvements! Thank you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.