The first chapter preface
Chapter II Overview of Single Chip Microcomputer
2. 1 Definition of Single Chip Microcomputer 4
2.2 the development direction of single-chip microcomputer ......................................................................................................................................................................
2.3 Application of Single Chip Microcomputer
2.4 MCS-5 1 Introduction
Chapter III Traffic Light Control of Single Chip Microcomputer
3. 1 hardware circuit
3. 1. 1 chip selection
3. 1.2 Hardware Circuit Diagram
3. 1.3 system working principle
3.2 Software design
3.2. 1 second setting ...
3.2.2 Calculation of initial counter value
3.2.3 Comprehensive calculation
3.2.4 Method of setting one second
3.2.5 Program planning
3.3 Software delay
3.4 Time and signal light display
3.5 Program ................................................ 13
The fourth chapter summarizes ................................. 12.
Refer to ................................... 13.
Thank you ...................................................................... 14.
The first chapter preface
Urban traffic is the most important infrastructure to maintain urban vitality, the artery of urban life, and it restricts the development of urban economy. Looking forward to the urban traffic in 2 1 century, we have put forward higher requirements. Developing a multi-level, three-dimensional and intelligent transportation system will be the universal goal of urban construction and development. It will be an important technical decision-making measure to realize the above long-term goal to develop a variety of passenger transport forms with large, medium and low passenger volumes matching each other.
Since the reform and opening up, China's urban scale and economic construction have developed rapidly. With the gradual acceleration of urbanization, the urban population has increased sharply, and a large number of floating population has poured into cities, and people travel and exchange materials frequently, which makes urban traffic face a severe situation. At present, the phenomenon of road congestion, traffic jam and traffic disorder is widespread in large and medium-sized cities across the country. How to solve the urban traffic problem has become the focus of the whole society and the urgent voice of the public.
Nowadays, installing traffic lights on main roads has become the most common, fundamental and effective way to alleviate traffic problems. The appearance of traffic lights can effectively control traffic, which has obvious effects on diverting traffic flow, improving road capacity and reducing traffic accidents.
Single chip microcomputer is an integrated microcomputer. Compared with microprocessor, it can independently complete the intelligent control functions required by modern industrial control. It has a unique architecture and instruction system designed for embedded applications. Traffic lights are controlled by PLC, single chip microcomputer and other methods. With the maturity of the technology of controlling traffic lights by single chip microcomputer in recent years, single chip microcomputer has brought great convenience to traffic.
Chapter II Overview of Single Chip Microcomputer
In the 1970s, microelectronics technology was in the development stage, integrated circuits were in the medium-scale development stage, all kinds of new materials and new technologies were not yet mature, and single-chip computers were still in the primary development stage. 1974, the United States developed the world's first single-chip computer F8, which was welcomed and valued by the field of household appliances and instruments, and opened the prelude to the development of single-chip computers.
2. The definition of1single chip microcomputer
The so-called single chip microcomputer is to integrate all the functional components that make up a microcomputer, such as central processing unit (CPU), random access memory (RAM), read-only memory (ROM), input/output interface circuit (I/O port), timer/counter, serial communication interface, etc., on one chip to form a complete microcomputer. Under the control of software, these circuits can accurately, quickly and efficiently complete the tasks specified by programmers in advance. Compared with microprocessor, it can independently complete the intelligent control functions required by modern industrial control, and has a unique architecture and instruction system specially designed for embedded applications, which is the biggest feature of single chip microcomputer.
Modern single-chip microcomputer has added more complex and perfect circuits such as alto unit, timing unit and A/D conversion circuit, which makes the function of single-chip microcomputer more and more powerful and widely used. Therefore, the single chip microcomputer can be understood as a single chip microcontroller.
Single chip microcomputer is an embedded application of single chip microcomputer. It has a unique architecture and instruction system, specially designed for embedded applications. In addition, it also has the advantage of chip-level volume and can run reliably at high speed in the field environment, so it is also called embedded microcontroller.
2.2 the development direction of single-chip microcomputer
The development trend of single chip microcomputer will be towards high performance, large capacity, small capacity, low price and built-in peripheral circuits.
(1) High performance of single chip microcomputer: mainly refers to further improving the performance of CPU, speeding up instruction operation and improving the reliability of system control, and strengthening the functions of bit processing, interrupt and timing control; Using pipeline structure, instructions appear in the CPU in the form of queues, which has high operation speed.
(2) Large-capacity on-chip memory: In the past, the on-chip ROM of single chip microcomputer was 1 to 4KB, and the RAM was 64 to 128B. Therefore, in some complex application systems, the memory capacity is not enough, so we have to expand the memory. In order to meet the requirements of this field, the application of new technology greatly increases the capacity of on-chip memory, and the memory has to be expanded. In order to meet the requirements of this field, the capacity of on-chip memory is greatly increased by adopting new technology, and the on-chip ROM can reach 12KB.
(3) Small capacity and low price: Contrary to the above, 4-bit and 8-bit single-chip computers with small capacity and low price are also one of the development directions. This single-chip microcomputer is mainly used in small control systems such as children's toys.
(4) Built-in peripheral circuits: With the continuous improvement of integration, it is possible to integrate a variety of peripheral functional devices into the chip. Except CPU, RAM, ROM, timer/counter, etc. The integrated components on the chip include A/D, D/A converter, DMA controller, sound generator, monitor timer, LCD driver, phase-locked circuit of color TV and video recorder, etc.
(5) Enhance the I/O interface function: In order to reduce the number of external driving chips and further increase the driving ability of the parallel port of single chip microcomputer, some single chip microcomputers can directly input large current and high voltage to directly drive the display.
(6) Speed up the transmission speed of I/O interface: Some single-chip computers have set up high-speed I/O interfaces to trigger peripheral devices and read data faster.
2.3 Application of Single Chip Microcomputer
Single-chip microcomputer is widely used in intelligent management and process control of instruments, household appliances, medical equipment, aerospace and special equipment, which can be roughly divided into the following fields:
The application of 1. in computer network and communication field;
2. Operation in industrial control;
3. Application in household appliances;
4. Application in intelligent instruments:
5. Application in the field of medical equipment;
2.4 MCS-5 1 Introduction
MCS-5 1 series single-chip computers are basically the same in structure, but individual modules and functions are different. MCS-5 1 MCU integrates an 8-bit CPU, 128B RAM, 4KB ROM, two 16-bit timers/counters, 32 programmable I/O ports, a programmable full-duplex serial interface, five interrupt sources and an on-chip oscillator.
1. Central Processing Unit (CPU): The CPU is the core part of the single chip microcomputer. It is an 8-bit central processing unit and processes data in bytes. CPU is mainly composed of arithmetic unit, controller and register array.
2. Data memory (on-chip RAM): The data memory is used to store changing data. In 805 1 single chip microcomputer, control and management registers (referred to as "special registers" for short) are usually logically divided into on-chip RAM because their addresses are continuous with RAM. The address space of 805 1 single chip microcomputer data memory is 256 RAM units, but only the front 128 can be used as the user's data memory, and the back 128 is occupied by special registers.
3. Program memory (on-chip ROM): The program memory is used to store programs, fixed constants, tables, etc. Read-only memory is usually used, and there are many kinds.
4. Timer/counter: Timer/counter is used to realize timing and counting functions. 805 1 MCU * * has two 16-bit timers/counters, and 8052 MCU * * * has three 16-bit timers/counters.
5. Parallel I/O ports: 805 1 MCU * * * has four 8-bit parallel I/O ports (P0, P 1, P2, P3), and each port consists of a latch and a driver. Parallel I/O ports are mainly used to realize data parallel input/output with external devices, and some I/O ports also have other functions.
6. Serial port: 805 1 MCU has a full-duplex asynchronous serial port to realize asynchronous serial data transmission between MCU and other devices with corresponding interfaces.
7. Clock circuit: The function of the clock circuit is to generate the clock pulse sequence required by the single chip microcomputer.
8. Interrupt system: The main function of the interrupt system is to manage and handle external or internal interrupt requests. The interrupt system of 805 1 single chip microcomputer can meet the needs of general control applications: * * There are five interrupt sources, including two external interrupt sources INT0 and INT 1 and three internal interrupt sources (two timer/counter interrupts and one serial interrupt); In addition, the 8052 single chip microcomputer also added the interrupt source of timer 2.
Chapter III Single Chip Microcomputer Control of Traffic Lights
3. 1 hardware circuit
3, 1. 1 Chip selection:
Choose a single-chip microcomputer 803 1, a parallel universal interface chip 8255, a watchdog 74LS07 and MAX692, two seven-segment digital tubes with * * * cathodes, several bidirectional thyristors, a 7805 three-terminal regulated power supply, two red, yellow and green traffic lights, several switch keyboards and wires.
3. 1.2 Hardware circuit diagram:
3. 1.3 system working principle:
1. Switch the keyboard to input the initial time of the traffic lights, and input it into the system through 805 1 single chip microcomputer P 1.
2.805 1 the timer of single-chip microcomputer transmits information to the data port of 8255 through P0 port every second, and the PA port of 8255 displays red, green and Huang San lights; The lighting time of each lamp is displayed by the PC port of 8255.
3.805 1 By setting the lighting time of each signal, the green light time and red light time are 60 seconds respectively, and the period of 80 seconds is output from the P0 port of 805 1 to the data port of 8255.
4. Work or set the initial value through P3.0 bit control system of 805 1 single chip microcomputer. When the card position is 0, the system will be initialized, and when it is 1, the system will start to work.
5. Red light countdown time, when the vehicle runs a red light, start the buzzer to give an alarm and return to normal after 3 seconds.
6. Add the function of detecting the traffic flow at each green light time, query whether the level of P2.0 port is low, and press the switch to be low, and the two-digit digital tube displays the traffic flow until the next green light time is recorded again.
7. The countdown to the green light time is completed, and the cycle is repeated.
3.2 Software design
+0 settings per second:
The overflow interrupt of MCS-5 1 internal timing equipment is used to determine the time of 1 second.
3.2.2 Calculation of initial counter value:
When the timer works, the initial value of the counter must be sent to the counter, and the initial value of the counter is sent to TH and TL. It can automatically generate overflow interrupt requests from all 1 to all 0s by adding and counting. Therefore, we can set the count value that the counter needs to be filled to zero as C and the initial count value as TC, namely:
TC = M-C; Where m is the counter modulus, which is related to the working mode of the counter. In mode 0, m is 213; The value of m in mode 1 is 216; 28 in mode 2 and mode 3.
3.2.3 Comprehensive calculation:
T=(M-TC)T 1 or TC=M-T/T 1, where T 1 is twice as long as the clock cycle of the single chip microcomputer; TC is the timing initial value. Unfortunately, this method exceeds the maximum fixed time of the counter, so the combination of timer and software is adopted.
3.2.4 Method for setting one second:
We set a software counter with an initial value of 20 in the main program and make the T0 time 50 milliseconds, so that whenever T0 to 50 milliseconds, the CPU will respond to its overflow interrupt request and enter its interrupt service subroutine. In the interrupt subroutine, the CPU first subtracts 1 from the software counter, and then judges whether it is zero, indicating that 1 second has arrived and can return to the output time display program.
3.2.5 Program design:
1. Main program:
The timer is 50ms, so T0 works in 1 mode, and the initial value is:
Tc = m-t/t1= 216-50ms/1us=3CBOH.
ORG 1000H
Starting: MOV TMOD, # 01h; Let T0 be the timer mode 1.
MOV TH0, # 3CH load timer initial value
MOV TL0,# BOH;
MOV IE, # 82H opens the T0 interrupt.
SEBT TR0; Start T0 counter
MOV R0,# 14H; Initial value of software counter
Loop: SJMP's; Waiting for interrupt
2. Interrupt service subroutine:
ORG 000BH
AJMP BRT0
Tissue 00BH
BRT0:DJNZ R0, the next AJMP time; Jump to time and signal light display subroutine
DJNZ:MOV R0,# 14H; Restore R0 value
MOV TH0, # 3CH reload timer initial value
MOV TL0,# BOH;
MOV IE, number 82H
RET 1
end
3.3 Software delay
The working frequency of MCS-5 1 is 2- 12MHZ, and the working frequency of 805 1 single chip microcomputer is 6MHX. The machine cycle is 12 times of the main frequency, so the time of a machine cycle is 12 * (1/6m.
3.4 Time and signal light display
When the timer is 1 sec, the program jumps to the subroutine of time display and signal light display, which will display the signal light time in turn and always display the color of the signal light. At this time, when the timer returns to the subroutine, the accounting time is one second. When the yellow light is displayed next time, the time of all light colors is displayed in turn, and then an initial value is given to the time counter to re-enter the cycle. Because the LEDs are connected through the anode, the output port is at a low level, and the corresponding diodes emit light, red, green and yellow LEDs can be lit by resetting.
3.5 procedure
The alternate control of traffic lights and the passage of special situations (such as ambulances) should be realized through external interruption;
North _ south _ red position P 1.0
North _ south _ yellow position P 1. 1
North _ south _ green position P 1.2
East _ west _ red position P 1.3
East _ west _ yellow position P 1.4
East _ west _ green bit P 1.5
SCD EQU 30H; second
Organization 0000H
JMP starting point
ORG 0003H
JMP initialization 0
ORG 000BH
JMP time 0
When the traffic lights work alternately, the red, green and yellow lights alternate: the red light lights up for 33 seconds, then the green light lights up for 27 seconds, then flashes for 3 seconds, and finally the yellow light lights up for 3 seconds, and so on.
Time 0:
MOV TH0,#30H
MOV TL0,#0B0H
INC 3 1H
MOV A,3 1H
N: CJNE A, #20, exit; Judge whether it is a second.
MOV 3 1H,#0
Company Scd
MOV A,Scd
CJNE A,#27,next 1; Judge whether the green light reaches 27s.
SETB F0
JMP exit
Next 1: MOV A, Scd
CJNE A, #30, NEXT2 determines whether the green light is on for 30 seconds.
CLR F0
MOV P 1,#0EEH
JMP exit
Next 2:
MOV A,Scd
CJNE A,#33,NEXT3
MOV P 1, # 0F3H initialization
Next 3:
MOV A,Scd
CJNE A,#60,NEXT4
SETB 00H
JMP exit
Next scene: MOV A, Scd
CJNE A, number 63, next 5
CLR 00H
MOV P 1,#0F5H
JMP exit
Next 5: MOV A, Scd
CJNE A, exit 66
MOV P 1,#0DEH
MOV Scd,#0
Exit: RETI
External interruption: when there are special circumstances in the east-west direction, the north-south red light is on, and the east-west green light is on, with a delay of 10s.
INIT0:
Push PSW
Push ACC
CLR EA
MOV R2,p 1; save data
MOV P 1,#0F6H
Call DELLAY 10S.
MOV P 1,R2; recover
SETB Electronic Arts Circle
Popular ACC
POP PSW
Retty
Main program:
Start:
MOV Scd,#00H
MOV 3 1H,#00H
MOV P 1,#0FFH
CLR 00H
CLR F0
MOV TMOD,# 0 1H; Set timer 1
MOV IE, # 83H sets interrupt enable timer interrupt 0, external interrupt 0 and 1.
MOV SP,#60H
MOV TH0,#30H
MOV TL0,#0B0H
SETB TR0
Cycle:
JNB F0,N0
CPL east _ west _ green; The green light flashes for three seconds.
Call delay 500 milliseconds
JMP N 1
No:
JNB 00H,N 1
CPL north _ south _ green; The green light flashes for three seconds.
Call delay 500 milliseconds
N 1:
JMP loop
Chapter IV Summary
The system realizes the function of red light and green light on time, the traffic lights are lit circularly, and the yellow light flashes to warn when there are 5 seconds left in the countdown. The vehicle runs a red light and gives an alarm; The green light time can detect the traffic flow and can be displayed by double digital tubes. The disadvantage of this system is that it can't control the car to turn left and right, and it can't automatically change the traffic light time according to the traffic flow. This is determined by its geographical location and traffic flow, and can be realized by designing and expanding the original system if necessary.
Through the research of this topic, I have a deeper understanding of some functions of single chip microcomputer and the application of single chip microcomputer in daily life. In the process of research, I also found that I don't understand the single chip microcomputer, and I read relevant books and other materials to solve the problem. Combining the practice in practical work and the writing of this graduation thesis, I have learned a lot, and I have also learned a lot. At the same time, it further deepened and consolidated the previous professional knowledge.
refer to
Zhang Guofeng. Principle and application of single chip microcomputer [J]. Higher education research, 200.9.8.
[2] Zhang Yikun. Principle and Application of Single Chip Microcomputer, xidian university Publishing House, 1998.
[3] Hu. Principle of single chip microcomputer and its interface technology [M]. Beijing: Tsinghua University Publishing House, May 2004.
[4] Hu Ganbin. Principle and application of single chip microcomputer [M]. Huazhong University of Science and Technology Press. 2006
[5] Zhang. Principle and interface technology of single chip microcomputer [M]. Harbin: Harbin Institute of Technology Press, 1990
Lei Liwen. Principle and Interface Technology of Microcomputer, Beijing: Electronic Industry Press, 1997.2.
[7] Cao Guohua in Yuxi Village. Principle and Interface Technology of Single Chip Microcomputer, Shaanxi: xidian university Press, July 2000.
Express gratitude/gratitude
Through this period of research and design study, I learned a lot of knowledge that I didn't know before, cultivated meticulous attitude and patience in my study, and laid a solid foundation for my future work.
Here, I would like to express my heartfelt thanks to the instructor of our thesis. I can learn the related knowledge of single chip microcomputer systematically through this opportunity, and I can complete the design of traffic lights in combination with real life. His humorous, witty and rigorous teaching style will be an example for me to learn.