Learning MCU 8

Publisher:技术掌门Latest update time:2015-12-14 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Commonly used interface circuits and their programming

Connection and programming of LED digital display

In the single-chip microcomputer system, LED digital display is usually used to display various numbers or symbols. It is widely used because of its clear display, high brightness, low voltage and long life.

Eight-segment LED display

Introduction: Do you remember the "matchstick game" we played when we were young? A few matchsticks can be combined to form various shapes. The LED display is actually such a thing. The eight-segment LED display is composed of 8 light-emitting diodes. Among them, 7 long strips of light-emitting diodes are arranged in the shape of "日", and another dot-shaped light-emitting diode is used as a decimal point in the lower right corner of the display. It can display various numbers and some English letters. There are two different forms of LED displays: one is that the anodes of the 8 light-emitting diodes are connected together, which is called a common anode LED display; the other is that the cathodes of the 8 light-emitting diodes are connected together, which is called a common cathode LED display. As shown in the figure below. The names and arrangement positions of the stroke segments of the LED displays with common cathode and common anode structures are the same. When the diode is turned on, the corresponding stroke segment lights up, and various characters are displayed by the combination of the illuminated stroke segments. The 8 stroke segments hgfedcba correspond to one byte (8 bits) of D7 D6 D5 D4 D3 D2 D1 D0, so the glyph code of the character to be displayed can be represented by an 8-bit binary code. For example, for a common cathode LED display, when the common cathode is grounded (zero level) and the anode hgfedcba segments are 0111011, the display displays the "P" character, that is, for a common cathode LED display, the glyph code of the "P" character is 73H. If it is a common anode LED display, the common anode is connected to a high level, and the glyph code for displaying the "P" character should be 10001100 (8CH). It must be noted here that many products, in order to facilitate wiring, often do not follow the rules to correspond to the relationship between fields and bits. At this time, the glyph code must be designed according to the wiring. We will give an example later.

  1. Static Display Interface

In the single-chip microcomputer application system, there are two common display methods: static display and dynamic scanning display. The so-called static display means that each display must occupy a separate I/O interface with a latching function for the stroke segment glyph code. In this way, the single-chip microcomputer only needs to send the glyph code to be displayed to the interface circuit, and then it will not care about it until new data is to be displayed, and then send the new glyph code. Therefore, using this method, the CPU overhead in the single-chip microcomputer is small. There are many I/O interface circuits that can provide separate latches. Here, taking the commonly used serial-to-parallel conversion circuit 74LS164 as an example, a commonly used static display circuit is introduced to give everyone a certain understanding of static display. The serial port mode of the MCS-51 single-chip microcomputer is replaced by the shift register mode. Six external 74LS164s are used as the static display interface of the 6-bit LED display. The RXD of 8031 ​​is used as the data output line and the TXD is used as the shift clock pulse. The 74LS164 is a TTL unidirectional 8-bit shift register that can realize serial input and parallel output. Among them, A and B (pins 1 and 2) are serial data input terminals. The two pins input signals according to the logic and operation rules. They can be connected in parallel when there is a common input signal. T (pin 8) is the clock input terminal, which can be connected to the TXD terminal of the serial port. When the rising edge of each clock signal is added to the T terminal, the shift register shifts one bit. After 8 clock pulses, all 8-bit binary numbers are shifted into 74LS164. R (pin 9) is the reset terminal. When R=0, each bit of the shift register is reset to 0. Only when R=1, the clock pulse works. The parallel output terminals of Q1...Q8 (pins 3-6 and 10-13) are connected to the corresponding pins of each segment of hg---a of the LED display. The following can also be introduced about 74LS164: the so-called clock pulse end actually requires high, low, high, low pulses, no matter how the pulse comes from. For example, we use a wire, one end is connected to T, and the other end is held by hand, connected to high level and low level respectively, that is also to give a clock pulse. At the moment when 74LS164 obtains the clock pulse (to be clear, it is at the edge of the pulse), if the data input end (pins 1 and 2) is high level, then there will be a 1 entering the inside of 74LS164, if the data input end is low level, then there will be a 0 entering its inside. After giving 8 pulses, the first data that first enters 74LS164 reaches the highest bit, and then what will happen with another pulse? With another pulse, the first pulse will be moved out from the highest bit, just like queuing to buy tickets at the station, the railing is so long, if one person enters from the back, one person must walk out from the front. After clarifying this, let's look at the circuit. Six 7LS164s are connected end to end, and the clock ends are connected together. In this way, when 8 pulses are input, the data output from the RXD end of the microcontroller enters the first 74LS164, and when the second 8 pulses arrive, this data enters the second 74LS164, and the new data enters the first 74LS164. In this way, when the sixth 8 pulses are completed, the first data sent is sent to the leftmost 164, and the other data appears in the first, second, third, fourth, and fifth 74LS164 in turn. There is a question. When the first pulse arrives, except for the first 74LS164 receiving data, what are the other chips doing? They are also receiving data because their clock ends are connected together, but the data has not been sent to the other chips. What data are they receiving? . . . . . . . . In fact, the so-called data is just a way of saying it. It actually refers to the level. When the first pulse arrives, the first 164 receives data from the microcontroller, and the other chips are also connected to Q8 of the previous chip. Q8 is a wire. In the digital circuit, it can only have two states: low level or high level, that is, "0" and "1". So its next 74LS164 is also equivalent to receiving data. It's just that all it receives are 0 or 1. This question is put here to explain. Some friends may disdain it, and some friends may still not understand it. This actually involves the nature of numbers. If you don't understand it, please think carefully, find some numbers of digital circuits, understand the working principle of 164, and then look at this question, or go and see my other article "Concepts that are easy to grasp for beginners of microcontrollers". Be sure to understand it. If you understand this, your level will be higher than that of a beginner. Entrance: Put the numbers to be displayed in the display buffer 60H-65H, a total of 6 units, and correspond to each digital tube LED0-LED5 respectively. Export: Convert the 6 numbers preset in the display buffer into corresponding display font codes, and then output them to the display for display. The display program is as follows: DISP: MOV SCON,#00H; Initialize serial port mode 0 MOV R1,#06H; Display 6 digits MOV R0,#65H; 60H-65H is the display buffer MOV DPTR,#SEGTAB; Entry address of font table LOOP: MOV A,@R0; Take the highest bit of data to be displayed MOVC A,@A+DPTR; Look up the table to get the font code MOV SBUF,A; Send to the serial port for display DELAY: JNB TI,DELAY; Wait for the transmission to be completed CLR TI; Clear the transmission flag DEC R0; The pointer moves down one bit, ready to take the next number to be displayed DJNZ R1,LOOP; Until all 6 data are displayed. RET SETTAB:; The font table has been introduced before, and we will introduce the production of the font table later. DB 03H 9FH 27H 0DH 99H 49H 41H 1FH 01H 09H 0FFH ; 0 1 2 3 4 5 6 7 8 9 Main program for blanking code test ORG 0000H AJMP START ORG 30HSTART: MOV SP,#6FH MOV 65H,#0 MOV 64H,#1 MOV 63H,#2 MOV 62H,#3 MOV 61H,#4 MOV 60H,#5 LCALL DISP SJMP $ If the digital tubes are arranged as shown, the main program above will display 543210. Think about it, how to send the number if you want to display 012345? Let's analyze the problem of making the font table. Let's take a look at the above "standard" graphics. Write out the corresponding relationship between data bits and glyphs and list them in a table as follows (set to common positive type, that is, the pen segment is bright when the corresponding output bit is 0)

Data bits

D7

D6

D5

D4

D3

D2

D1

D0

Glyph Code

Pen level

A

B

C

D

E

F

G

H

0

0

0

0

0

0

0

1

1

03H

1

1

0

0

1

1

1

1

1

9F

2

0

0

1

0

0

1

1

1

27H

3

0

0

0

0

1

1

0

1

0D

4

1

0

0

1

1

0

0

1

99H

5

0

1

0

0

1

0

0

1

49H

6

0

1

0

0

0

0

0

1

41H

7

0

0

0

1

1

1

1

1

1FH

8

0

0

0

0

0

0

0

1

01H

9

0

0

0

0

1

0

0

1

09H

How about it? You can make a glyph table, right? Just make a table and write the corresponding 0 and 1 according to the requirements (0 is on or 1 is on), and you are done. Do an exercise and write the glyph code of AF. If the order of wiring is disrupted for the convenience of wiring, how should the glyph table be connected? It is also very simple, just list it in the same way. Take the new experimental board as an example, common anode type. The wiring is as follows: P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0C EHDGFAB Then the font code is as follows: 0 00101000 28H; 1 01111110 7EH; 2 10100100 0A4H; 3 01100100 64H; 4 01110010 72H; 5 01100001 61H; 6 00100001 21H; 7 01111100 7CH; 8 00100000 20H; 9 01100000 60H As an exercise, you can write out the font code of AF. Originally, this is to explain the static interface of the display, which should be the end, but I would like to talk a little more about the nature of the number mentioned above. There are some terms and nouns in the microcontroller that are supposed to help us understand things, but sometimes we are confused by the relevant semantics of these terms, so that we cannot further recognize their essence, and thus often fall into a state of confusion. Only by deeply understanding the working characteristics of 74LS164 can we truly understand what serial data is. Interested friends can also take a look at the article "Design of Bank Interest Rate Screen" in "Other Materials" on my website.

Dynamic Scan Display Interface

The dynamic scanning display interface is one of the most widely used display modes in single-chip microcomputers. Its interface circuit connects the same-named ends of the eight stroke segments ah of all displays, 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 experimental 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 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

As can be seen from the above example, dynamic scanning display requires the CPU to continuously call the display program 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. [page]

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 program, we can see that the dynamic scanning program 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.

Keywords:MCU Reference address:Learning MCU 8

Previous article:Learning MCU 7
Next article:Learning MCU 9

Recommended ReadingLatest update time:2024-11-15 14:54

PIC16F15323 microcontroller (interrupt and timer Timer0)
The development environment selected is MPLAB X IDE v5.50 and xc8-v2.32-full-install-windows-x64-installer. 1 Basic principles 2 Implementation Code The code is mainly written based on FIGURE 25-1 and the interrupt logic block diagram, so that the code is readable and easy to understand. However, some registe
[Microcontroller]
PIC16F15323 microcontroller (interrupt and timer Timer0)
IAR+Proteus7.6 simulates MSP430 MCU PORT1 external interrupt function
1. Proteus circuit   2. msp430 program #include msp430x23x.h #define uint unsigned int #define uchar unsigned char / Function: void delay_1ms(void) void delay_nms(uint n) Function: Delay 1ms Delay Nms */ void Delay_1ms(void) //1ms delay function  {     uint i;     for (i=0;i 80;i++);  }     vo
[Microcontroller]
IAR+Proteus7.6 simulates MSP430 MCU PORT1 external interrupt function
Why do we need chip select control and address selection for microcontrollers?
Answer: In the single-chip microcomputer application system, all peripheral chips are connected to the single-chip microcomputer through the bus. The single-chip microcomputer data bus transmits data with the peripheral chips in a time-sharing manner. In order to make this transmission reliable, chip selection control
[Microcontroller]
Microcontroller Exercise - I2C Bus Protocol
This time, the microcontroller is used to simulate the I2C bus protocol through software, and read and write the AT24C02 EEPROM based on the I2C protocol. For specific instructions and functions, see the code comments. The connection circuit diagram of AT24C02 and the microcontroller is as follows: The microcontrol
[Microcontroller]
Microcontroller Exercise - I2C Bus Protocol
Research on online detection system of special-shaped curved surface based on single chip microcomputer
  This paper introduces an intelligent online real-time control system for special-shaped surface detection based on single-chip microcomputer control. It uses optical elements to take online photos to build a complex three-dimensional model. The model has good value retention in the control system of the system, and t
[Microcontroller]
Design of cycle drop simulator based on 8051 microcontroller
introduction Electromagnetic compatibility (EMC) requires that electronic and electrical devices must have the ability to work normally in a certain electromagnetic environment. Testing and researching anti-electromagnetic interference are inseparable from electromagnetic interference simulators that comply with natio
[Microcontroller]
Design of cycle drop simulator based on 8051 microcontroller
Anti-lock Braking System (ABS) Solution Based on Freescale MCU
Description of the program: Anti-lock Braking Systems ( ABS ) assist the driver with control and vehicle stability in emergency braking situations. Locking the wheels slows the vehicle down, but it results in a loss of steering flexibility. ABS prevents 'steering loss' while applying maximum braking force. ABS does
[Automotive Electronics]
Anti-lock Braking System (ABS) Solution Based on Freescale MCU
The enhanced single-chip microcomputer STC12C5A60S2 outputs square wave signals of various frequencies
Assume the clock frequency Fosc = 18.432MHz, design the program to output a clock with a frequency of 124.540KHz from the P1.0/CLKOUT2 pin; output a clock with a frequency of 125KHz from the T0 (P3.4) pin; and output a clock with a frequency of 38.4KHz from the T1 (P3.5) pin. Solution: Use the programmable clock out
[Microcontroller]
Latest Microcontroller 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号