Detailed explanation of the classic experimental examples of single-chip microcomputers (with source code) (Part 3)

Publisher:cw57324588Latest update time:2013-05-26 Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
2. Experiment of displaying 00 to 99 in two-digit digital tubes

  Now let's use the two digital tubes on the experiment board to do an experiment to display the numbers 00 to 99 in a loop. First, complete the necessary hardware part.

  Digital tubes are divided into common cathode and common anode types. Both can be driven by microcontrollers, but the driving methods are different, and the corresponding display codes of 0 to 9 are exactly the opposite.

  First, let's introduce the single-chip microcomputer driving method of two common anode digital tubes. The circuit is as follows:

  

  Netizens can see that: P2.6 and P2.7 ports control the power supply of tens and ones of the digital tube respectively. When the corresponding port becomes a low level, the corresponding transistor will be turned on, and +5V will supply power to the corresponding bit of the digital tube through the IN4148 diode and the driving transistor. At this time, as long as the P0 port sends out the digital display code, the digital tube can display the number normally.

  Because two different digits need to be displayed, a dynamic scanning method must be used. That is, the ones digit is displayed for 1 millisecond first, and then the tens digit is displayed for 1 millisecond, and this cycle continues. In this way, as long as the scanning time is less than 1/50 second, the two different digits will be stably displayed due to the visual residual effect of the human eye.

  Next, we will introduce a single-chip microcomputer driving method for common cathode digital tubes. The circuit is as follows:

  

  Netizens can see that +5V directly supplies power to the 8 segments of the digital tube through a 1K resistor, and the P2.6 and P2.7 ports control the power supply of the tens and ones of the digital tube respectively. When the corresponding port becomes low level, the corresponding bit can absorb current. The data output by the P0 port of the microcontroller is equivalent to short-circuiting the digital segments that the digital tube does not want to display to the ground, so that the digital tube will display the required numbers.

  Netizens can see that the hardware of common cathode digital tubes is simpler, so in mass production, the hardware overhead is small, PCB area is saved, welding workload is reduced, and overall cost is reduced. Therefore, the use of common cathode digital tubes is more conducive to mass production. The test boards sold now all use common cathode digital tubes.

  The following is an assembly language program that uses the two-digit digital tube of the AT89C51 experimental board to display 00~99 in a loop.

  a_bit equ 20h ; memory location for storing the single digit of the digital tube

  b_bit equ 21h ; memory location for storing the ten digit of the digital tube

  temp equ 22h ;Counter value is stored in memory location

  star: mov temp, #0; initialize the counter, starting from 0

  stlop: acall display; call display subroutine

  inc temp; add 1 to the counter

  mov a,temp

  cjne a,#100,next ; Determine whether the counter is full of 100?

  mov temp, #0; reset to zero when it reaches 100 and start over

  next: ljmp stlop; loop execution if not satisfied

  ; Display subroutine

  display: mov a, temp; convert the hexadecimal number in temp to decimal

  mov b, #10; decimal/10=decimal

  div ab

  mov b_bit, a; the tens bit is in a

  mov a_bit, b ; the ones bit is in b

  mov dptr, #numtab; specify the start address of the table lookup

  mov r0, #4

  dpl1: mov r1, #250;

  dplop: mov a, a_bit; get the unit digit

  MOVC A, @A+DPTR; check the 7-segment code of the single digit

  mov p0, a ; send out the 7-segment code of the unit digit

  clr p2.7 ; open the single digit display

  acall d1ms ;display 162 microseconds

  setb p2.7; turn off the units display to prevent ghosting

  mov a, b_bit ; get the tens digit

  MOVC A, @A+DPTR; check the 7-segment code of the ten-digit number

  mov p0, a ; send out the ten-digit 7-segment code

  clr p2.6 ; open ten-digit display

  acall d1ms ;display 162 microseconds

  setb p2.6; turn off the ten-digit display to prevent ghosting

  djnz r1, dplop; loop executed 250 times

  djnz r0, dpl1; loop execution 250X4=1000 times

  ret

  ;2+2X80=162 microseconds, delay is calculated based on 12MHZ

  D1MS: MOV R7, #80

  DJNZ R7, $

  RET

  ;The 7-segment digital tube 0 to 9 digits on the experimental board display the common cathode code

  numtab: DB 0CFH, 03H, 5DH, 5BH, 93H, 0DAH, 0DEH, 43H, 0DFH, 0DBH

  end

  ;If it is a common anode digital tube display code

  numtab: DB 30H, 0FCH, 0A2H, 0A4H, 06CH, 25H, 21H, 0BCH, 20H, 24H

Keywords:MCU Reference address:Detailed explanation of the classic experimental examples of single-chip microcomputers (with source code) (Part 3)

Previous article:Detailed explanation of the classic experimental examples of single-chip microcomputers (with source code) (Part 2)
Next article:Detailed explanation of the classic experimental examples of single-chip microcomputers (with source code) (IV)

Recommended ReadingLatest update time:2024-11-16 16:32

Discussion on the stability of multi-computer communication system based on single chip microcomputer
In the process of developing a single-chip multi-machine communication system, the author adopted other design methods to eliminate the unstable factors of the system. The entire system has been running stably and reliably for two years. I hope to discuss this with you further. The structure of the half-duplex comm
[Microcontroller]
Discussion on the stability of multi-computer communication system based on single chip microcomputer
Cortex-M MCU based on SPIFI peripheral completely solves the problem of embedded flash memory selection
Introduction: The SPI Flash Interface (SPIFI) technology, first used in the new NXP ARM Cortex-M3 microcontroller, can help 32-bit embedded system designers replace large, expensive parallel Flash with small, low-cost serial Flash. Using SPIFI (pronounced as spiffy, meaning "excellent, neat, beautiful", etc. - translat
[Microcontroller]
Cortex-M MCU based on SPIFI peripheral completely solves the problem of embedded flash memory selection
PIC16F87x MCU memory features and data memory usage planning
Compared with other single-chip microcomputers, the PICmicro single-chip microcomputer of SMIC adopts many unique designs in hardware structure and instruction system. The hardware system design of the PIC series microcontrollers is simple and the instruction system design is concise; it adopts the Harvard bus struc
[Microcontroller]
PIC16F87x MCU memory features and data memory usage planning
How to design a stable and reliable USB control system based on CY7C68013A microcontroller?
introduction Universal Serial Bus (USB), as a new interface technology on computers, is becoming more and more popular. Compared with previous interfaces such as RS 232, RS 485, ISA, PCI and parallel interfaces, USB avoids the shortcomings of large interface size, inconsistent interface specifications, and does not su
[Microcontroller]
How to design a stable and reliable USB control system based on CY7C68013A microcontroller?
Why does the microcontroller have so little memory?
Many friends have this question: Nowadays, solid-state drives are measured in T units, and the memory of mobile phones and computers is 8G or even 32G. Why is the RAM of microcontrollers less than 1M? The classic AT89C51 microcontroller has only 128 bytes of RAM (memory) inside, and the similarly classic MSP430F149 ha
[Microcontroller]
AVR128 MCU minimum system serial port, external interrupt, marquee, uCOS-II transplantation
Experiment name: Serial communication experiment Function description: The computer sends data to the development board through the serial port, and the development board sends the data back as is. Experiment purpose: Learn serial communication Experiment description: MCU--M128           internal 8M crystal oscillator
[Microcontroller]
Design of interruption-style lighting based on 51 single-chip microcomputer
This design aims to use interrupt 0 (INT0) to complete the design of 2 styles of LED display. Operation method: Start simulation, then run demo2 style, wait for a while, and then press the switch "Change" to run another style. simulation: Reference Code: #include reg52.h #define uint unsigned int #define ucha
[Microcontroller]
Design of interruption-style lighting based on 51 single-chip microcomputer
Microcontroller and embedded system applications
1 Overview With the development of my country's equipment manufacturing industry, embedded systems have become the core technology of the manufacturing industry. It is widely used in many fields such as industrial control, simulation systems, medical instruments, information appliances, communication equipment, etc.
[Microcontroller]
Latest Analog Electronics 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号