Traffic Light Design Based on 51 Microcontroller

Long press the QR code below to enter the public account

Traffic Light Design Based on 51 Microcontroller

Catalog

1 Introduction…………………………………………. 1

2 System Discussion……………………………………… 2

2.1 Design Background……………………………………………………………………….. 2

2.2 Design Concept……………………………………………………………………….. 2

2.3 System Framework Design………………………………………………………………… 2

3 PWMPulse Width Modulation Principle………………………………. 4

3.1 PWMSpeed Control Principle…………………………………………………………………. 4

3.2 PWMSpeed Control Method…………………………………………………………………. 4

3.3 PWMImplementation Method…………………………………………………………………. 4

4 System Hardware Design………………………………….. 4

4.1 Basic Composition of the System………………………………………………………………… 4

4.1.1Hardware Module Composition…………………………………………………………. 4

4.1.1Microcontroller Control Module………………………………………………. 4

4.2 Introduction to AT89C52 Microcontroller………………………………………………………. 4

4.2.1Main Performance of AT89C52…………………………………………………… 4

4.2.2Main Functions of AT89C52……………………………………………. 4

4.2.3Pin Function Introduction of AT89C52………………………………………… 4

4.2.4Internal Resources of AT89C52……………………………………………….. 4

4.3 L298Motor Driver Module………………………………………………………… 4

4.3.1 L298Introduction to Motor Driver…………………………………………………. 4

4.3.2 L298Internal Schematic Diagram…………………………………………………….. 4

4.3.3 L298Pin Symbols and Functions……………………………………………… 4

4.3.4 L298Logical Functions………………………………………………………… 4

4.4 LEDDigital Tube Display……………………………………………………………… 4

4.4.1 LEDIntroduction…………………………………………………………………. 4

4.4.2 LEDStructure of Seven-Segment Display……………………………………………. 4

4.4.3Common Digit and Character Field Codes……………………………………….. 4

4.4.4 LEDConnection of Digital Tube and Microcontroller…………………………………….. 4

4.4.5Simple Program Flow……………………………………………………… 4

4.4.6Connection of Microcontroller and LED in this System………………………………… 4

4.5 Standalone Keyboard Control Module……………………………………………………… 4

4.5.1Functions and Classification of Keyboard………………………………………………….. 4

4.5.2Standalone Keyboard…………………………………………………………….. 4

4.5.3Connection of Standalone Keyboard and Microcontroller……………………………………. 4

5 System Software Design………………………………….. 4

Conclusion…………………………………………… 5

Acknowledgments…………………………………………… 6

References……………………………………….. 7

Appendix…………………………………………… 8

Appendix1…………………………………………………………………………………… 8

Appendix2…………………………………………………………………………………… 8

1 Introduction

Early DC drive control systems were composed of analog discrete components. Due to the inherent disadvantages of analog devices, such as temperature drift and zero drift voltage, the number of components in the system was large, resulting in low control accuracy and reliability of the analog DC drive system. With the development of computer control technology, microprocessors have been widely used in DC drive systems, achieving fully digital control. Since microprocessors operate with digital signals, the control methods are flexible and convenient, and they have strong anti-interference capabilities. Therefore, the control accuracy, reliability, and stability of fully digital DC speed control are greatly improved compared to analog DC speed control systems. Thus, the control of DC drives using microprocessors has entered a new stage of full digitalization.

Microprocessors were born in the 1970s, and with the rapid development of large-scale and ultra-large-scale integrated circuit manufacturing technology, the cost-performance ratio of microprocessors has become increasingly high. In addition, due to the development of power electronics technology and improvements in manufacturing processes, the performance of high-power electronic devices has rapidly improved. This has made it possible for microprocessors to be widely used in motor control, allowing for various novel and high-performance control strategies to be implemented, fully utilizing the potential of motors and making their performance more aligned with industrial production requirements. It has also promoted motor manufacturers to develop various new types of motors, such as stepper motors, brushless DC motors, and switched reluctance motors, which are easy to control and practical, leading to new changes in motor development.

For simple microprocessor-controlled motors, it is sufficient to use the microprocessor to control relays and electronic switch components to turn the circuit on or off to achieve motor control. Currently, programmable controllers with microprocessors have been widely applied in various machine tools and production lines, allowing for regularized control of motors through programming the programmable controllers. For complex microprocessor-controlled motors, it is necessary to use the microprocessor to control the voltage, current, torque, speed, and angle of the motor to ensure that the motor operates accurately according to the given instructions. Through microprocessor control, the performance of the motor can be significantly improved. Currently, compared to DC motors and AC motors, each has its strengths; for example, DC motors have good speed control performance but have mechanical commutators that suffer from mechanical wear and commutation sparks; AC motors, whether asynchronous or synchronous, have simpler structures than DC motors and are more reliable in operation, but their speed cannot be easily and economically adjusted when running on a constant frequency AC power grid.[2]High-performance microprocessors such as DSP (Digital Signal Processor) provide a good material basis for adopting new control theories and strategies, greatly improving the automation level of motor drives. In advanced CNC machine tools and other CNC position servo systems, high-speed microprocessors such as DSP have been adopted, with execution speeds reaching millions of megahertz per second and suitable for matrix operations.

2 System Discussion

21Design Background

In recent years, with the advancement of technology, power electronics technology has rapidly developed, and DC motors have become increasingly widely used. DC motors have excellent speed control characteristics, smooth and convenient speed adjustment, a wide speed range, and strong overload capacity, allowing them to withstand frequent impact loads. They can achieve frequent stepless rapid starting, braking, and reversing, which requires meeting various special operational requirements of automated production processes. Therefore, higher requirements have been placed on the speed control of DC motors. Techniques such as changing the armature circuit resistance and changing the armature voltage for speed control can no longer meet the requirements. At this time, the method of controlling the speed of DC motors through PWM (Pulse Width Modulation) has emerged.

22 Design Concept

The main functions of the DC motor PWM control system include: achieving acceleration, deceleration, forward and reverse rotation, and emergency stop of the DC motor, as well as adjusting the motor speed, enabling intelligent control of the motor.

Main circuit: the DC motor PWM control module. This part of the circuit mainly consists of the I/O ports of the AT89C52 microcontroller, timer counters, external interrupt expansion, etc., to control the acceleration, deceleration, forward and reverse rotation of the DC motor, and to adjust the motor speed, enabling intelligent control of the motor. The AT89C52 microcontroller generates pulse signals with adjustable pulse width and inputs them into the L298 driver chip to control the operation of the DC motor. The DC motor PWM control system consists of the following circuit modules:

Design input part: This module mainly uses an independent keyboard with interrupts to achieve acceleration, deceleration, forward and reverse rotation, and emergency stop control of the DC motor.

Design control part: mainly consists of the external interrupt expansion circuit of the AT89C52 microcontroller. The DC motor PWM control implementation part mainly consists of some diodes, motors, and the L298 DC motor driver module.

Design display part: LED digital display part, achieving real-time display of the PWM pulse width modulation duty cycle.

23 System Framework Design

DC motor PWM speed control scheme

Scheme description: The DC motor PWM speed control system takes the AT89C52 microcontroller as the control core, consisting of command input module, LED display module, and motor driver module. An independent keyboard with interrupts is used as the command input. Under the control of the microcontroller program, it continuously sends PWM waveforms to the L298 DC motor driver chip at regular intervals, while the H-type driver circuit completes the control of the motor’s forward, reverse, and emergency stop; at the same time, the microcontroller continuously sends the PWM pulse width modulation duty cycle to the LED digital tube for real-time display.

3 PWMPulse Width Modulation Principle

3.1 PWMSpeed Control Principle

It is a method of voltage adjustment that achieves control requirements by adjusting the voltage across the load. PWM can be applied in many areas, such as motor control, temperature control, pressure control, etc.[7]

In the PWM drive control adjustment system, the power supply is turned on and off at a fixed frequency, and the duration of the “on” and “off” times within a cycle is changed as needed. By changing the “duty cycle” of the voltage across the DC motor armature, the average voltage can be adjusted, thereby controlling the motor speed. For this reason, PWM is also referred to as a “switching drive device”.

As shown in Figure 1:

Figure 1 PWM signal duty cycle

Assuming the motor is always powered, the maximum speed of the motor is Vmax, and let the duty cycle be D= t1 / T, then the average speed of the motor is Va = Vmax * D, where Va refers to the average speed of the motor; Vmax refers to the maximum speed of the motor when fully powered; D = t1 / T refers to the duty cycle.

From the above formula, it can be seen that when we change the duty cycle D=t1/T, we can obtain different average speeds of the motor Vd, thus achieving the purpose of speed control. Strictly speaking, the average speed Vd is not a strictly linear relationship with the duty cycle D, but in general applications, we can approximate it as a linear relationship.

3.2 PWMSpeed Control Method

Based on microcontroller software implementation of PWM: In the PWM speed control system, the duty cycle D is an important parameter. Under the condition of constant power supply voltage, the average value of the armature terminal voltage depends on the size of the duty cycle D. Changing the value of D can change the average value of the armature terminal voltage, thus achieving the purpose of speed control. There are three methods to change the duty cycle D:

A. Fixed Width Frequency Modulation: Keeping the width constant while changing t, thus changing the period (or frequency) as well.

B. Width Modulation Frequency Modulation: Keeping t constant while changing the width, thus changing the period (or frequency) as well.

C. Fixed Frequency Width Modulation: Keeping the period T (or frequency) constant while changing the width and t.

The first two methods change the control pulse period (or frequency) during speed control. When the frequency of the control pulse is close to the inherent frequency of the system, it will cause oscillation. Therefore, the fixed frequency width modulation method is commonly used to change the duty cycle to change the voltage across the DC motor armature. This method can simplify the hardware circuit and has strong operability.

3.3 PWMImplementation Method

Scheme 1: Using a timer as the timing method for pulse width control, this method produces pulse widths that are extremely precise, with errors only in the few microseconds.

Scheme 2: Using software delay method, this method is not as precise as Scheme 1, especially after introducing interrupts, there will be some errors. Therefore, Scheme 1 is adopted.

4System Hardware Design

4.1Basic Composition of the System

4.1.1 Hardware Module Composition

(1) Microcontroller Control Module

(2) L298 Motor Driver Module

(3) LED Display Module

(4) Standalone Keyboard Control Module3.3System Hardware Circuit of Each Module

4.1.2 Entire Control Module of Microcontroller

The entire control module of the microcontroller

Here, the timer counter is used to make the P2 port of the microcontroller output square waves with different duty cycles through pins P2.6 and P2.7, which are then amplified by the driver chip L298 to control the DC motor. The input voltage of the driver chip is the voltage difference between the two pins. When adjusting the speed, one pin is low level, and the other pin generates a speed control square wave, so the voltage difference between the two pins can be controlled by controlling one of the pins. When it is necessary to change the direction of the motor rotation, the outputs of the two pins are opposite.

The timer counter interrupts once every certain time (1us), causing P2.6 or P2.7 to produce a high or low level. The speed of the DC motor is divided into 100 levels, so one cycle has 100 pulses, and the period corresponds to the number of high-level pulses in one cycle. The duty cycle is the percentage of the number of high-level pulses to the total number of pulses in one cycle. The voltage applied across the motor is the product of the pulse high voltage and the duty cycle. The larger the duty cycle, the larger the voltage applied across the motor, and the faster the motor rotates. The average speed of the motor equals the maximum speed of the motor at a certain duty cycle multiplied by the duty cycle. When we change the duty cycle, we can obtain different average speeds of the motor, thus achieving the purpose of speed control. Strictly speaking, the average speed is not a strictly linear relationship with the duty cycle, but in general applications, it can be approximated as a linear relationship.

42Introduction to AT89C52

42.1 AT89C52Main Performance

AT89C52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K in-system programmable Flash memory. It is manufactured using Atmel’s high-density non-volatile memory technology and is fully compatible with the instruction set and pinout of the industrial 80C51 products. The on-chip Flash allows program memory to be programmed in-system, making it suitable for conventional programmers. On a single chip, it has a clever 8-bit CPU and in-system programmable Flash, providing a highly flexible and efficient solution for numerous embedded control applications.

Compatible with MCS-51 microcontroller products; 8K bytes of in-system programmable Flash memory; 1000 erase cycles; fully static operation: 0Hz to 33Hz; three-level encrypted program memory; 32 programmable I/O lines; three 16-bit timers/counters; eight interrupt sources; full-duplex UART serial channel; low-power idle and power-down modes; interrupt wake-up after power-down; watchdog timer; dual data pointers; power-down identifier.

42.2 AT89C52Main Functions

1. It has a clever 8-bit CPU and in-system programmable Flash.

2. The chip has an internal clock oscillator (traditional maximum operating frequency can reach 12MHz).

3. The internal program memory (ROM) is 8KB.

4. The internal data memory (RAM) is 256 bytes.

5. 32 programmable I/O lines.

6. 8 interrupt vector sources.

7. Three 16-bit timers/counters.

8. Three-level encrypted program memory.

9. Full-duplex UART serial channel.

42.3 AT89C52Pin Function Introduction

VCC:

Power positive input for AT89C52, connect to +5V.

VSS:

Power ground.

XTAL1:

Inverting amplifier input for the system clock of the single-chip system.

XTAL2:

Inverting amplifier output for the system clock, generally in design, just connecting a quartz crystal oscillator system between XTAL1 and XTAL2 can make it work. Additionally, a small capacitor of 20PF can be added between the two pins and ground to stabilize the system and avoid noise interference.

RESET:

The reset pin of AT89C52, active high. To reset the chip, simply raise this pin to high level and hold for more than two machine cycles, and AT89S51 will complete the reset actions, setting the contents of the internal special function registers to known states and starting to read program code from address 0000H.

EA/Vpp:

“EA” is the abbreviation for “External Access”, indicating access to external program code. It is active low, meaning that when this pin is connected to low level, the system will use external program code (stored in external EPROM) to execute the program. Therefore, in 8031 and 8032, the EA pin must be connected to low level, as there is no internal program memory space. If using 8751 internal program space, this pin should be connected to high level. Additionally, when programming the program code into the 8751 internal EPROM, this pin can be used to input the programming high voltage of 21V (Vpp).

ALE/PROG:

ALE is the abbreviation for “Address Latch Enable”, indicating the address latch enable signal. The AT89C52 can use this pin to trigger an external 8-bit latch (such as 74LS373) to latch the address bus of port 0 (A0~A7) into the latch, as the AT89C52 outputs address and data in a multiplexed manner. During normal program execution, the output frequency of the ALE pin is about 1/6 of the system working frequency, so it can be used to drive the timing input of other peripheral chips. Additionally, when programming the 8751 program code, this pin will be used as a special function for program planning.

PSEN:

This is the abbreviation for “Program Store Enable”, meaning program storage enable. When the 8051 is set to read external program code working mode (EA=0), this signal will be sent to obtain the program code, usually connected to the OE pin of the EPROM. The AT89C52 can use the PSEN and RD pins to enable the external RAM and EPROM, allowing the data memory and program memory to be merged and share a 64K addressing range.

PORT0 (P0.0~P0.7):

Port 0 is an 8-bit open-drain bidirectional output port, with 8 bits in total. P0.0 represents bit 0, P0.1 represents bit 1, and so on. The other three I/O ports (P1, P2, P3) do not have this circuit configuration but have an internal pull-up circuit. When used as I/O, P0 can drive 8 LS TTL loads. If the EA pin is low (i.e., accessing external program code or data memory), P0 will provide the address bus (A0~A7) and data bus (D0~D7) in a multiplexed manner. Designers must add a latch to lock the address output from port 0 to A0~A7, and combine it with the output from port 2 to form a complete 16-bit address bus, addressing the 64K external memory space.

PORT2 (P2.0~P2.7):

Port 2 is a bidirectional I/O port with an internal pull-up circuit, each pin can drive 4 LS TTL loads. When the output of port 2 is set to high level, this port can be used as an input port. In addition to being used as a general I/O port, when expanding external program memory or data memory with the AT89C52, it also provides the high byte of the address bus A8~A15, at which point P2 cannot be used as I/O.

PORT1 (P1.0~P1.7):

Port 1 is also a bidirectional I/O port with an internal pull-up circuit, its output buffer can drive 4 LS TTL loads. Similarly, if the output of port 1 is set to high level, it will be used to input data. If using 8052 or 8032, P1.0 serves as the external pulse input for timer 2, and P1.1 can have T2EX function, which can serve as an external interrupt input trigger pin.

PORT3 (P3.0~P3.7):

Port 3 also has an internal pull-up circuit and is a bidirectional I/O port, its output buffer can drive 4 TTL loads, and it also has other additional special functions, including serial communication, external interrupt control, timer counting control, and control of reading or writing external data memory contents.

The pin assignments are as follows:

P3.0:RXD, serial communication input.

P3.1:TXD, serial communication output.

P3.2:INT0, external interrupt 0 input.

P3.3:INT1, external interrupt 1 input.

P3.4:T0, timer/counter 0 input.

P3.5:T1, timer/counter 1 input.

P3.6:WR: write signal for external data memory.

P3.7:RD, read signal for external data memory.

RST:Reset input. When the oscillator resets the device, the RST pin must be held high for two machine cycles.

ALE/PROG:When accessing external memory, the address latch allows the output level to latch the address byte. During FLASH programming, this pin is used to input programming pulses. Normally, the ALE pin outputs positive pulse signals at a constant frequency, which is 1/6 of the oscillator frequency. Therefore, it can be used for external output pulses or for timing purposes. However, it should be noted that whenever used for external data memory, one ALE pulse will be skipped. To disable the output of ALE, set 0 at the SFR8EH address. At this time, ALE will only take effect when executing MOVX, MOVC instructions. Additionally, this pin is slightly pulled high. If the microprocessor is in an external execution state, disabling ALE will be invalid.

/PSEN: External program memory selection signal. During instruction fetching from external program memory, /PSEN is valid twice per machine cycle. However, this valid /PSEN signal will not appear when accessing external data memory.

/EA/VPP: When /EA is kept low, external program memory (0000H-FFFFH) will be accessed, regardless of whether there is internal program memory. Note that in encryption mode 1, /EA will lock the internal to RESET; when /EA is kept high, internal program memory will be accessed. During FLASH programming, this pin is also used to apply a 12V programming power supply (VPP).

XTAL1: Input for the reverse oscillation amplifier and internal clock working circuit.

XTAL2: Output from the reverse oscillator.

42.4 AT89C52Internal Resources

AT89C52 has 6 interrupt sources: two external interrupts (INT0 and INT1), three timer interrupts (timer 0, 1, 2), and one serial interrupt. Each interrupt source can be enabled or disabled by setting or clearing the corresponding interrupt enable bits in the special register IE. IE also includes a total control bit for interrupt enable, EA, which can disable all interrupts at once.

AT89C52 has a watchdog timer and three 16-bit programmable timers/counters. The 16-bit refers to the fact that they are composed of 16 flip-flops, so the maximum counting modulus is . Programmable means that their operating modes can be set by instructions, either when used as counters or when used as timers, and the counting (timing) range can also be set by instructions. This control function is accomplished through the timer mode controller TMOD.

Memory structure: MCS-51 devices have separate program memory and data memory. Both external program memory and data memory can be addressed up to 64K. Program memory: If the EA pin is grounded, program reading starts only from external memory. For 89S52, if EA is connected to VCC, program read/write starts from internal memory (address 0000H~1FFFH), then from external addressing, with addressing addresses: 2000H~FFFFH.

Data memory: AT89C52 has 256 bytes of on-chip data memory. The high 128 bytes overlap with special function registers. This means that the high 128 bytes have the same addresses as the special function registers, but are physically separate. When an instruction accesses an address above 7FH, the addressing mode determines whether the CPU accesses the high 128 bytes of RAM or the special function register space. Direct addressing mode accesses special function registers (SFR). For example, the following direct addressing instruction accesses 0A0H (P2 port) storage unit:

MOV 0A0H , #data

Using indirect addressing mode accesses high 128 bytes of RAM. For example, in the following indirect addressing mode, the content of R0 is 0A0H, accessing the register at address 0A0H, not the P2 port (which also has the address 0A0H).

MOV @R0 , #data

Stack operations are also in indirect addressing mode. Therefore, the high 128 bytes of data RAM can also be used as stack space.

4. 3 L298Motor Driver Module

4. 3.1 L298Introduction to Motor Driver

L298 is a product of SGS, L298N is a single-chip integrated circuit with 15 pins, high voltage, high current, and four-channel drive, designed to receive DTL or TTL logic levels, driving inductive loads (such as relays, DC and stepper motors) and switching power transistors. It internally contains 4-channel logic driver circuits, with a rated working current of 1 A, maximum up to 1.5 A, Vss voltage minimum 4.5 V, maximum up to 36 V; Vs maximum voltage is also 36 V. L298N can directly control motors without isolation circuits and can drive dual motors.

4. 3.2 L298Internal Schematic Diagram

4. 3.3 L298 Pin Symbols and Functions

Pin

Function

SENSASENSB

Current feedback pins for the two H-bridges, can be directly grounded when not used

ENA ENB

Enable pins, input PWM signals

IN1IN2IN3IN4

Input pins, TTL logic level signals

OUT1OUT2OUT3OUT4

Output pins, same logic as corresponding input pins

VCC

Logic control power supply, 4.5~7V

VSS

Motor drive power supply, minimum must be higher than the input low voltage

GND

Ground

4. 3.4 L298Logical Functions

IN1

IN2

ENA

Motor Status

X

X

0

Stop

1

0

1

Clockwise

0

1

1

Counterclockwise

0

0

0

Stop

1

1

0

Stop

When the enable pin is high, if the input pin IN1 is a PWM signal and IN2 is a low level signal, the motor rotates forward; if IN1 is a low level signal and IN2 is a PWM signal, the motor rotates backward; if IN1 and IN2 are the same, the motor stops quickly. When the enable pin is low, the motor stops rotating.

In controlling and driving the voltage of DC motors, semiconductor power devices (L298) can be divided into two usage methods: linear amplification driving method and switching driving method. In the linear amplification driving method, the advantages of semiconductor power devices working in the linear region are simple control principles, small output fluctuations, good linearity, and minimal interference to adjacent circuits. The disadvantages are low power and serious heat dissipation issues when the power devices work in the linear region. The switching driving method makes semiconductor power devices work in the switching state, controlling the motor voltage through pulse modulation (PWM), thus achieving control of motor speed.

4. 4 LEDDigital Tube Display

4. 4.1 LEDIntroduction

LED (Light Emitting Diode) is a solid-state semiconductor device that can directly convert electricity into light. The heart of an LED is a semiconductor chip, one end of which is attached to a bracket, with one end being the negative electrode and the other connected to the positive power supply, encapsulating the entire chip in epoxy resin. The semiconductor chip consists of two parts: one part is P-type semiconductor, where holes dominate, and the other part is N-type semiconductor, where electrons dominate. When these two types of semiconductors are connected, they form a “P-N junction”.

When current flows through the wire to this chip, electrons are pushed towards the P region, where they recombine with holes, emitting energy in the form of photons, which is the principle of LED light emission. The wavelength of the light, which determines the color of the light, is determined by the materials forming the P-N junction. Except for semiconductor lasers, semiconductor diodes that can emit optical radiation when excited by current are strictly speaking, the term LED should only apply to diodes that emit visible light; diodes that emit near-infrared radiation are called infrared emitting diodes (IRED); diodes that emit peak wavelengths near the shortwave limit of visible light, with some ultraviolet radiation, are called ultraviolet light-emitting diodes; however, habitually, all three types of semiconductor diodes are collectively referred to as light-emitting diodes.

4. 4.2 LEDStructure of Seven-Segment Display

Common Cathode Common Anode Pin Diagram

Where: Figure (a) is the common cathode structure, where the cathodes of the 8 segment LEDs are connected together, and the anodes are separated for control. When used, the common end is grounded, and to light up a specific LED, the corresponding anode is connected to a high level. Figure (b) is the common anode structure, where the anodes of the 8 segment LEDs are connected together, and the cathodes are separated for control. When used, the common end is connected to the power supply. To light up a specific LED, the corresponding cathode is grounded. Among them, the 7 segment LEDs form the character “8”, and one LED forms the decimal point. Figure “c” is the pin diagram, where different 8-bit binary codes are input from pins a-g to display different numbers or characters. The control codes for the LEDs are usually referred to as field codes. Different numbers or characters have different field codes, and for the same number or character, the field codes for common cathode and common anode connections are also different, with common cathode and common anode field codes being inverse codes of each other.

4. 4.3Common Digit and Character Field Codes

Displayed Character

Common Cathode Field Code

Common Anode Field Code

Displayed Character

Common Cathode Field Code

Common Anode Field Code

0

3FH

C0H

C

39H

C6H

1

06H

F9H

D

5EH

A1H

2

5BH

A4H

E

79H

86H

3

4FH

B0H

F

71H

8EH

4

66H

99H

P

73H

8CH

5

6DH

92H

U

3EH

C1H

6

7DH

82H

T

31H

CEH

7

07H

F8H

Y

6EH

91H

8

7FH

80H

L

38H

C7H

9

6FH

90H

8.

FFH

00H

A

77H

88H

Off

00

FFH

B

7CH

83H

……

……

……

4. 4.4 LEDConnection of Digital Tube and Microcontroller

The circuit connection method determines that a digit scanning display method must be used. That is, the character code of a certain LED is sent from the segment selection port, and then that LED is enabled, maintaining a delay time. Then the next LED is enabled until all positions are scanned.

4. 4.5Simple Program Flow

4.5Standalone Keyboard Control Module

4.5.1Functions and Classification of Keyboard

The keyboard is one of the most commonly used input devices, consisting of a set of keys. Functionally, it can be divided into numeric keys and function keys, serving to input data and commands, query and control the system’s working status, and achieve simple human-computer interaction.

Classification of keyboards

(a) Keyboards can be divided into coded keyboards and non-coded keyboards based on interface principles. The main difference between these two types of keyboards is the method of recognizing key symbols and providing corresponding key codes.

Coded keyboards mainly use hardware to achieve key recognition;

Non-coded keyboards mainly use software to define and recognize keys.

(b) Keyboards can be divided into standalone keyboards and matrix keyboards based on their structure.

Standalone keyboards are mainly used in situations with fewer keys, while matrix keyboards are mainly used in situations with more keys, also known as row-column keyboards.

4.5.2Standalone Keyboard

The keys of a standalone keyboard are independent of each other, with each key connected to a separate I/O line. The working state of a key on one I/O line does not affect the working state of other I/O lines. Therefore, by detecting the level state of the I/O lines, it is possible to determine which key on the keyboard has been pressed.

4.5.3Connection of Standalone Keyboard and Microcontroller

5System Software Design

Directly applying the software method of AT89C52 to implement PWM signal output is more cost-effective than hardware implementation of PWM signals, with fewer restrictions and convenient implementation. The flowchart is as follows.

5.1Flowchart

5.1.1Main Program Flowchart

Figure 5.1 System main microcontroller overall program block diagram

Conclusion

Through this graduation design, I have learned many things that cannot be learned from books, and I have also deeply realized the wide application of microcontroller technology. It not only solidified my knowledge of microcontrollers but also increased my interest in this course. During this course design process, I learned how to search for resources related to this design on the internet, including: DC motor PWM speed control, AT89C52 microcontroller, L289 pin diagram and its pin functions, LED digital tube display, providing certain materials for this graduation design.

In the early stages of the graduation design, the difficulty was high, and there was no direction. By seeking help from Teacher Chen, I clarified my thoughts. At the same time, I consulted materials in the library and online, overcoming various difficulties in the graduation design.Through this technological innovation practice, I have learned a lot, realizing that relying solely on what is in books is not enough; additional research is necessary. Whether in hardware or software design, I encountered many problems, and in the process of overcoming difficulties, I learned a lot, especially things that cannot be learned in class, such as PWM. It also trained my protel drawing ability; previously, components were given, and I only needed to find their names in the library and connect them. This time, I had to draw according to my design needs, which felt different. I was able to complete this design independently, which is a significant gain. Overall, I have the following feelings:

1. Through this graduation design, I not only gained a deeper understanding of microcontrollers but also developed a certain understanding of how to draw flowcharts and write programs for a topic.

2. It further strengthened my hands-on ability and the ability to apply professional knowledge, learning how to think and solve problems, as well as how to flexibly change methods to implement design solutions. I particularly realized the importance of the combination of software and hardware, as well as the connection and cooperation between the two.

3. I learned about the importance of microcontroller technology in today’s life. At the same time, this experience of doing the graduation design has benefited me greatly, making me realize that in doing anything, one should be practical and work hard; only in this way can one succeed.

References

[1] Lin Zhiqi. Visualization of Microcontroller Hardware and Software Simulation Based on Proteus [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2006.9

[2] Zhou Runjing, Zhang Lina. Circuit and Microcontroller System Design and Simulation Based on PROTEUS [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2006.5

[3] Zhang Jingwu, Zhou Lingbin. PROTEUS Design and Simulation of Microcontroller Systems [M]. Beijing: Electronic Industry Press, 2007.4

[4] Zhou Runjing, Zhang Lina. Practical Tutorial for PROTEUS [M]. Beijing: Machinery Industry Press, 2007.9

[5] Lou Ranmiao, Li Guangfei. Design Examples of 51 Series Microcontrollers [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2003.3

[6] Lou Ranmiao, Li Guangfei. Guidance for Microcontroller Course Design [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2007.7

[7] Jia Dongyao, Wang Renhuang. Application of Digital Temperature Sensor in Warehouse Temperature Detection System [J]. Sensor World, 2001

[8] DALLAS DS18B20 Data Manual [Z]. http://www.maximic.com

[9] Li Zhaoqing. Principles and Interface Technology of Microcontrollers [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2006.

[10] Kang Huaguang, Chen Daqin. Fundamentals of Electronic Technology (Analog Part) [M]. Beijing: Higher Education Press, 1999.

[11] Kang Huaguang, Zou Shoubin. Fundamentals of Electronic Technology (Digital Part) [M]. Beijing: Higher Education Press, 2000.

[12] Hu Zhubing. Design of DC Motor Speed Control System Based on Microcontroller [J]. Journal of Chengde Petroleum College, 2008 (1).

[13] Lu Chunhua, Yao Haiyan, Zhang Li. Design of DC Motor Speed Control System Based on Microcontroller [J]. Silicon Valley, 2009 (20).

[14] Wu Shouzheng, Qi Yingjie. Pulse Width Modulation Control Technology of Electrical Transmission. Beijing: Machinery Industry Press.

[15] Jia Yuying, Wang Chen. PWM DC Speed Control System Based on Microcontroller. Journal of Baotou Steel College, 2005.

[16] Kang Huaguang, Zou Shoubin. Fundamentals of Electronic Technology (Digital Part, Fourth Edition). Beijing: Higher Education Press, 2004.

[17] San Hengxing Technology. Principles and Application Examples of MCS 51 Microcontroller. Beijing: Electronic Industry Press, 2008.

[18] Pu Longmei, Li Si. Research on DC PWM Speed Control Device Based on Microcontroller. Frequency Converter World, 2006.

[19] Zhang Bo. DC Motor Pulse Width Speed Control Device Controlled by SG3525A. Electrical Manufacturing, 2006.

Leave a Comment