51 MCU Tutorial from Scratch - 25 Dynamic Scanning Display Interface Circuit and Program

Publisher:快乐的成长Latest update time:2012-02-16 Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Dynamic scanning display interface circuit and program

In the single-chip system, the dynamic scanning display interface is one of the most widely used display methods in the single-chip system. Its interface circuit connects the same-named ends of the 8 stroke segments ah of all displays together, and the common pole COM of each display is independently controlled by the I/O line. When the CPU sends the glyph code to the field output port, all displays receive the same glyph code, but which display is lit depends on the COM end, which is controlled by the I/O, so we can decide when to display which bit. The so-called dynamic scanning means that we use the time-sharing method to control the COM end of each display in turn, so that each display is lit in turn.

During the scanning process, the lighting time of each display is extremely short (about 1ms). However, due to the persistence of vision and the afterglow effect of the light-emitting diode, although the displays are not actually lit at the same time, as long as the scanning speed is fast enough, it gives the impression of a stable set of display data without flickering.

The following figure shows the dynamic scanning interface on our microcontroller experiment board. The P0 port of 89c51 can inject a large current, so we use a common anode digital tube, and do not use a current limiting resistor, but only use two 1N4004 to step down the voltage to power the digital tube. Only two are used here, and it can actually be expanded. Their common end is controlled by the PNP transistor 8550. Obviously, if 8550 is turned on, the corresponding digital tube can light up, and if 8550 is turned off, the corresponding digital tube cannot light up. 8550 is controlled by P2.7 and P2.6. In this way, we can control the lighting or extinguishing of a certain digital tube by controlling P27 and P26.

The following single-chip microcomputer program uses the digital tube on the experimental board to display 0 and 1.

FIRST EQU P2.7 ; bit control of the first digital tube

SECOND EQU P2.6 ; The second digital tube position control

DISPBUFF EQU 5AH; Display buffer is 5AH and 5BH

ORG 0000H

AJMP START

ORG 30H

START:

MOV SP,#5FH ;Set up the stack

MOV P1,#0FFH

MOV P0,#0FFH

MOV P2, #0FFH ; Initialize, display, LED off

MOV DISPBUFF,#0 ;The first bit displays 0

MOV DISPBUFF+1,#1; The second hold displays 1

LOOP:

LCALL DISP ;Call display program

AJMP LOOP

; The main program ends here

DISP:

PUSH ACC; ACC is pushed onto the stack

PUSH PSW; PSW is pushed onto the stack

MOV A, DISPBUFF; Get the first number to be displayed

MOV DPTR,#DISPTAB ; font table first address

MOVC A,@A+DPTR; Get font code

MOV P0,A ; send the font code to P0 (segment port)

CLR FIRST; open the first display port

LCALL DELAY ; Delay 1 millisecond

SETB FIRST ; Turn off the first bit display (start preparing the second bit data)

MOV A,DISPBUFF+1; Get the second bit of the display buffer

MOV DPTR,#DISPTAB

MOVC A,@A+DPTR

MOV P0,A ; send the second font code to port P0

CLR SECOND ; Open the second display

LCALL DELAY ; Delay

SETB SECOND ; Turn off the second digit display

POP PSW

POP ACC

RET

DELAY: ; Delay 1 millisecond

PUSH PSW

SETB RS0

MOV R7,#50

D1: MOV R6,#10

D2: DJNZ R6,$

DJNZ R7,D1

POP PSW

RET

DISPTAB:DB 28H,7EH,0a4H,64H,72H,61H,21H,7CH,20H,60H

END

It can be seen from the above MCU routine that the dynamic scanning display must be continuously called by the CPU to ensure continuous display.

The above program can realize the display of numbers, but it is not very practical. Why? Here, only two numbers are displayed, and no other work is done. Therefore, the two digital tubes take turns to display for 1 millisecond, which is no problem. In actual work, of course, it is impossible to display only two numbers. Other things must be done. In this way, the time interval between the second call of the display program is uncertain. If the time interval is relatively long, the display will be discontinuous. In actual work, it is difficult to ensure that all work can be completed in a very short time. Moreover, this display program is a bit "wasteful". Each digital tube display takes 1 millisecond, which is not allowed in many combinations. What should we do? We can use the timer. When the timing time is reached, an interrupt is generated, a digital tube is lit, and then it returns immediately. This digital tube will be lit until the next timing time is reached, without calling the delay program. This time can be left for the main program to do other things. When the next timing time is reached, the next digital tube will be displayed, so there is little waste.

Counter EQU 59H ; Counter, through which the display program knows which digital tube is currently displayed

FIRST EQU P2.7 ; bit control of the first digital tube

SECOND EQU P2.6 ; The second digital tube position control

DISPBUFF EQU 5AH; Display buffer is 5AH and 5BH

ORG 0000H

AJMP START

ORG 000BH ;Entry of timer T0

AJMP DISP ;Display program

ORG 30H

START:

MOV SP,#5FH ;Set up the stack

MOV P1,#0FFH

MOV P0,#0FFH

MOV P2, #0FFH ; Initialize, display, LED off

MOV TMOD,#00000001B ; Timer T0 works in mode 1 (16-bit timing/counting mode)

MOV TH0,#HIGH(65536-2000)

MOV TL0,#LOW(65536-2000)

SETB TR0

SETB EA

SETB ET0

MOV Counter,#0 ; Counter initialization

MOV DISPBUFF,#0 ; The first bit always displays 0

MOV A,#0

LOOP:

MOV DISPBUFF+1,A ; The second digit displays 0-9 in turn

INC A

LCALL DELAY

CJNE A,#10,LOOP

MOV A,#0

AJMP LOOP; Any program can be arranged in the middle, this is just a demonstration.

; The main program ends here

DISP: ;Timer T0 interrupt response program

PUSH ACC; ACC is pushed onto the stack

PUSH PSW; PSW is pushed onto the stack

MOV TH0,#HIGH(65536-2000); The timing time is 2000 cycles, about 2170 microseconds (11.0592M)

MOV TL0,#LOW(65536-2000)

SETB FIRST

SETB SECOND ; Turn off display

MOV A,#DISPBUFF ; Display buffer first address

ADD A,Counter

MOV R0,A

MOV A,@R0; Get the corresponding display buffer value according to the counter value

MOV DPTR,#DISPTAB ; font table first address

MOVC A,@A+DPTR; Get font code

MOV P0,A ; send the font code to P0 (segment port)

MOV A,Counter; Get the value of the counter

JZ DISPFIRST ; if it is 0, display the first bit

CLR SECOND ; otherwise display the second digit

AJMP DISPNEXT

DISPFIRST:

CLR FIRST ; Display the first position

DISPNEXT:

INC Counter ;Counter plus 1

MOV A,Counter

DEC A ; If the counter reaches 2, set it back to 0

DEC A

JZ RST COUNT

AJMP DISPEXIT

RSTCOUNT:

MOV Counter,#0 ; The value of the counter can only be 0 or 1

DISPEXIT:

POP PSW

POP ACC

RETI

DELAY: ; Delay 130 milliseconds

PUSH PSW

SETB RS0

MOV R7,#255

D1: MOV R6,#255

D2: NOP

NOP

NOP

NOP

DJNZ R6,D2

DJNZ R7,D1

POP PSW

RET

DISPTAB:DB 28H,7EH,0a4H,64H,72H,61H,21H,7CH,20H,60H

END

From the above MCU program, we can see that the dynamic display is a little more complicated than the static display, but it is worth it. This program has a certain versatility. As long as the value of the port and the value of the counter are changed, more digits can be displayed. The following is a flowchart of the display program.

Click to browse the next page

Click to browse the next page

Keywords:MCU Reference address:51 MCU Tutorial from Scratch - 25 Dynamic Scanning Display Interface Circuit and Program

Previous article:51 MCU Tutorial from Scratch - 24 LED Digital Tube Static Display Interface and Programming
Next article:51 MCU Tutorial from Scratch—— 26 MCU Keyboard Interface Programming

Recommended ReadingLatest update time:2024-11-17 00:45

AVR microcontroller atmega16 automatic watering device Proteus simulation + source program
  The microcontroller source program is as follows: #include iom16v.h #include macros.h #define  key_bz   0b00000111 #define uchar  unsigned char #define  uint_16  unsigned short char smg_zx ={0x3f,0x06,0x5b,0x4f,0x66,0x6d, 0x7d,0x07,0x7f,0x6f,0x37}; // global variables char smg_wx ={0B00000001,0B00000010,0B0000010
[Microcontroller]
AVR microcontroller atmega16 automatic watering device Proteus simulation + source program
Design of digital stopwatch based on 51 single chip microcomputer
   In recent years, with the development of science and technology, the application of single-chip microcomputers is constantly going deeper. This paper briefly describes the design of a digital stopwatch based on a single-chip microcomputer. The main feature of this design is that the timing accuracy reaches 0.01 seco
[Microcontroller]
Design of C8051 microcontroller to realize multi-target ultrasonic ranging
Ultrasonic ranging sensors are widely used in industrial field ranging, mobile robot navigation and positioning due to their high measurement accuracy, fast response and low price. The commonly used method for ultrasonic ranging sensors is that one transmitter corresponds to one receiving head, and there are also mult
[Microcontroller]
Design of C8051 microcontroller to realize multi-target ultrasonic ranging
51 MCU--LCD1602 Programming Introduction
 This time I will share my LCD1602 programming experience: Let me first explain that the chip driver of the LCD1602 I am going to talk about below is HD44780. If your LCD1602 driver chip is not HD44780, then the following content is not applicable. My overall understanding of LCD1602 Here I will talk about my ov
[Microcontroller]
51 MCU--LCD1602 Programming Introduction
Liyuan Semiconductor's first 32-bit MCU product is officially released!
Liyuan Semiconductor (a wholly-owned subsidiary of Liyuan Information, stock code 300184) officially announced today that its first independently developed MCU product based on the Cortex-M0+ core, CW32F030, has been launched. This is also the first 32-bit MCU in Liyuan Semiconductor's CW32F series. It is reported
[Microcontroller]
Liyuan Semiconductor's first 32-bit MCU product is officially released!
Principle of LCD display controller based on PIC microcontroller HT1621
The HT1621 LCD display controller is a display component of a multifunctional fully automatic intelligent switch, which can monitor the operation of the power supply line in real time, accurately and online. Once the line has leakage, overload, short circuit, overvoltage, undervoltage and phase loss, the intellige
[Microcontroller]
Principle of LCD display controller based on PIC microcontroller HT1621
How to measure the stability of the system when developing a single-chip microcomputer system
When developing a microcontroller system, what are the specific standards for measuring the stability of the system?  Answer: From an industrial perspective, there are many standards for measuring system stability, and the standards are different for different products. Below we will briefly introduce the most commonl
[Microcontroller]
Wireless communication system based on MCU and nRF24L01
With the rapid development of microelectronics technology, high-performance MCUs are widely used in embedded systems to complete data collection, analysis, processing and communication functions. The data communication system in wired mode cannot fully meet the execution of tasks under all conditions due to the constra
[Microcontroller]
Wireless communication system based on MCU and nRF24L01
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号