8362 views|4 replies

1379

Posts

0

Resources
The OP
 

Parallel I/O Port Programming [Copy link]


The most typical application of single-chip I/O is to form a display circuit through the I/O port and the 7-segment LED digital tube. We start with the commonly used LED display principle and explain in detail the circuit and programming principle of using a single-chip microcomputer to drive the LED digital tube. The purpose is to let beginners understand the programming principle of the I/O port through this programming example, and to draw inferences from one example and play a role in attracting others.
The principle of LED light emission is very clear to people with a little electronic technology foundation. We don’t want to introduce it too much. The 7-segment LED digital tube uses a single LED combination to arrange into an "8"-shaped digital tube on a certain shape of insulating material, and leads out their electrodes respectively, and lights up the corresponding dots and dashes to display the numbers 0-9.

LED digital tubes are divided into two categories: common cathode and common anode according to the different connection methods of LEDs. It is very important to understand these characteristics of LEDs for programming, because different types of digital tubes have different programming methods in addition to their hardware circuits. The right picture shows the internal circuits of common cathode and common anode digital tubes. Their light-emitting principles are the same, but their power supply polarities are different.
Connecting the cathodes of multiple LEDs together is the common cathode type, and connecting the anodes of multiple LEDs together is the common anode type. Taking the common cathode type as an example, if the cathode is grounded and the anode of the corresponding segment is connected to the positive power supply, the segment will light up. Of course, the current of LED is usually small, and generally a current limiting resistor is required in the circuit. If we connect the "b" and "c" segments to the positive power supply, and the other ends are grounded or left floating, then the "b" and "c" segments will light up, and the digital tube display will show the number "1". If the "a", "b", "d", "e" and "g" segments are all connected to the positive power supply, and the other pins are left floating, the digital tube will display "2". The display principles of other characters are similar, and readers can analyze them on their own.
LED digital tube structure diagram
LED display circuit The left figure is the experimental circuit diagram. We use the 80C51 single-chip computer. The capacitors C1, C2 and CRY1 form the clock oscillation circuit. This part basically does not need to be debugged. As long as the components are reliable, it will start normally. C3 and R1 are the reset circuit of the single-chip computer. The parallel port P1.0-P1.7 of the 80C51 is directly connected to the "af" pin of the LED digital tube, and the current-limiting resistors R3-R10 are connected in the middle. It is worth mentioning that the output drive current of the 80C51 parallel port is not very large. In order to make the LED have enough brightness, the LED digital tube should use high-brightness devices.
In addition, the 80C51 in the figure can also use other single-chip computers in the C51 series. As long as their instruction systems are compatible with C51, they can run normally and the program can be directly transplanted. For example, the low-cost Flash type AT89C1051 or 2051 (detailed technical manual) can be used. Their ROM can be repeatedly erased and written, which is very suitable for experimental purposes.
· Program list:
01 START: ORG 0100H ; program start address
02 MAIN: MOV R0,#00H ; start display from "0"
03 MOV DPTR,#TABLE ; table address to data pointer
04 DISP: MOV A,R0 ; send to display
05 MOVC A,@A+ADPTR ; point to table address
06 MOV P1,A ; data to LED
07 ACALL DELAY ; delay
08 INC R0 ; point to next character
09 CJNE R0,#0AH,DISP ; not finished displaying, continue
10 AJMP MAIN ; next loop
11 DELAY: MOV R1,#0FFH ; delay subroutine, delay time assignment
12 LOOP0: MOV R2,#0FFH
13 LOOP1: DJNZ R2,LOOP1
14 DJNZ R1,LOOP0
15 RET ; Subroutine returns
16 TABLE: DB 0C0H ; Font code table
17 DB 0F9H
18 DB 0A4H
19 DB 0B0H
20 DB 99H
21 DB 92H
22 DB 82H
23 DB 0F8H
24 DB 80H
25 DB 90H
26 END ; Program ends

In most applications, we do not want to use a microcontroller with multiple I/O ports. In principle, we prefer to use devices with as few pins as possible. In the absence of extra ports, how can we achieve the desired purpose by expanding the circuit? We hope that this example will help designers understand the principle of circuit expansion in actual applications and help them with actual applications.

The left picture is the display circuit. Since AT89C2051 has 15 external I/O pins, namely P1 and P3, P3.6 of P3 is not brought out. It is obviously not enough to drive 8-bit LED directly with 15 I/O ports. We use a 74LS273 to latch the address. If P1 port is only used for display drive and does not exchange data with other peripherals, this latch can be omitted, and the connected LED can be driven directly or through other drive circuits. We use a 74LS138 three-to-eight decoder to time-select the 8-bit LED for the address line. In this way, at any time, only one LED is lit, but as long as the scanning frequency is high enough (generally greater than 25Hz), due to the visual persistence characteristics of the human eye, it feels like it is continuously lit. This is what we often call a dynamic scanning circuit.
8-bit LED display circuit
In this circuit, 74LS273 is used to drive the 8-bit segment code of the LED. The corresponding "a"-"g" segments of the 8-bit LED are connected together, and their common ends are connected to the output ends driven by 74LS04 after decoding selection. In this way, when a certain LED is selected, the corresponding address line (output end of 74LS04) outputs a high level, so our LED uses a common anode LED digital tube.
There are certain requirements for the frequency of dynamic scanning. If the frequency is too low, the LED will flicker. If the frequency is too high, since the time for each LED to light up is too short, the brightness of the LED is too low and it cannot be seen by the naked eye, it is generally appropriate to take a few ms. This requires that when writing a program, a certain LED should be selected to light up and keep it for a certain time. The program often uses a delay subroutine. In C51 instructions, the delay subroutine is quite simple, and the delay time is also easy to change. See the DELAY delay subroutine in the program list.
For simplicity, we just program the 8-bit LED to synchronously display the numbers "00000000" - "11111111" until "99999999", and repeat the cycle. The program is very simple, and the flow chart is omitted. Program

List :


The number of parallel I/O ports of a single-chip microcomputer is always limited. Sometimes the parallel port needs to be used for other more important purposes. Generally, a large number of parallel I/O ports are not used to drive the display circuit. Can the serial communication port of 80C51 plus a small amount of I/O and expansion chips be used for the display circuit? The answer is yes. The
serial communication port of 80C51 is a powerful communication port, and it is a very easy-to-use communication port. It is very suitable for display drive circuits. Now we will design a 4-bit LED display circuit based on this need using two serial communication port lines plus two ordinary I/O ports. Of course, as long as two more I/O port lines are added, an 8-bit LED display circuit can be easily realized.
Serial port dynamic scanning display circuit
The left picture is the electrical schematic. We still use the C2051 microcontroller, and use the cheap and easily available 74LS164 and 74LS138 as expansion chips. The 74LS164 (detailed technical manual) is an 8-bit serial-input and parallel-output shift register. Its function here is to decode the serial data output by the C2051 serial communication port and output it on its parallel port line, thereby driving the LED digital tube. The 74LS138 is a 3-8 decoder, which decodes the address signal output by the microcontroller and dynamically drives the corresponding LED. However, the current driving capacity of the 74LS138 is relatively small, so we use the final drive transistor 2SA1015 as the address driver.
Connect the segments of the four LEDs together, and their common ends are time-selected by 74LS138, so that at any time, only one LED is lit, which is the dynamic scanning display mode. Its advantages have been explained in the previous section. Using the serial port for LED communication, the program writing is quite simple. The user only needs to send the data to be displayed directly to the serial port send buffer and wait for the serial interrupt. Take a look at the following program.
Program List
This post is from MCU

Latest reply

Bamboo is so handsome  Details Published on 2006-7-8 22:41
 

2

Posts

0

Resources
2
 
Good, very clear
This post is from MCU
 
 

1379

Posts

0

Resources
3
 
Thank you for your support
This post is from MCU
 
 
 

9

Posts

0

Resources
4
 
Bamboo is so handsome
This post is from MCU
 
 
 

1379

Posts

0

Resources
5
 
I've praised you there. I hope we can have more exchanges if we have the chance.
This post is from MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list