MCS-51 single chip microcomputer realizes interaction with the Internet

Publisher:脑力驿站Latest update time:2017-12-26 Source: eefocusKeywords:MCS-51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Implement the MCS-51 MCU embedded access to the Internet technology. The MCU interacts with the Internet through the ATL8019AS Ethernet controller. Use the open source TCP/IP protocol stack uIP to drive the underlying devices, and implement various application services through the uIP protocol application interface. Give the hardware design diagram and write the MCU main program. Apply this technology to realize a city center parking monitoring system.


In recent years, embedded systems represented by microcontrollers (MCU) have been widely used in industrial detection systems, intelligent instruments, security systems, smart home appliances and information appliances.


If the embedded system can be connected to the Internet, users can remotely control, monitor and transmit information through the network conveniently, quickly and cheaply. The integration of Internet technology and embedded technology not only brings unprecedented development space and opportunities for the design and development of embedded systems, but also makes Internet applications enter the era of embedded Internet. According to experts' predictions, 45% of the new services and applications on the Internet in the future will come from small embedded systems. Therefore, the Internet access technology of embedded systems will have extremely broad application prospects. How to use single-chip microcomputers to access the Internet network will become one of the hottest technologies in the future.


1 MCU Embedded Internet Access Technology


In Internet network communication, the TCP/IP protocol cluster is very large and requires a lot of system resources. The disadvantage of single-chip microcomputers is that they have limited resources and cannot accommodate the TCP/IP protocol cluster of the Internet. Therefore, the key to implementing embedded Internet access technology with single-chip microcomputers is how to implement the Internet network communication protocol stack on the limited resources of embedded devices such as single-chip microcomputers. The difficulty lies in how to use the limited resources of the single-chip microcomputer itself to process the information with the TCP/IP protocol and turn it into an IP data packet that can be transmitted on the Internet. At present, many research institutions are actively exploring the use of MCU to implement Internet access technology, and a variety of single-chip microcomputer embedded Internet technology solutions have emerged. These technical implementation solutions can be classified into the following categories.


(1) Use dedicated embedded chips. Dedicated embedded chips are single-chip microcomputers with built-in communication and control functions that can realize real-time multi-tasking operations. They provide greater system design flexibility than traditional single-chip microcomputer hardware. Such chips include Ubicom's IP2022 chip and MOXA's Nport Express chip. These chips are powerful and can implement multiple network protocols. They generally provide corresponding TCP/IP network protocol stacks. However, the price of such chips is relatively high, and users need to pay for software and hardware fees, which makes it difficult to achieve widespread market application.


(2) Embedded systems form a dedicated network and access the Internet through a PC gateway. Small embedded systems form a dedicated network through bus technology and use a PC as a gateway. The PC converts the information sent from the dedicated network into TCP/IP protocol data packets through dedicated software and then sends them to the Internet to achieve remote communication. This solution was widely used in the early days. However, the disadvantage of this solution is that it requires the use of a dedicated PC. Obviously, it is only suitable for some industrial data acquisition systems and is not easy to promote to fields such as information appliances and networked intelligent instruments.


(3) Use ordinary single-chip microcomputer and network control chip. This method is relatively simple to implement and can be expanded according to actual needs. However, it is necessary to implement the embedded TCP/IP network protocol on the single-chip microcomputer, and the workload of software programming is relatively large. Since ordinary single-chip microcomputer is used, its advantages are low cost and small size, and it is easy to promote to many occasions where embedded access to the Internet is required with extremely high cost performance. The system designed in this paper adopts this technical solution. The following will focus on analyzing its hardware and software design.


2 Interface circuit between single chip microcomputer and network card


2.1 Overall system design

Figure 1 System overall design

Figure 1 Overall system design.


The system uses the most commonly used MCS 8051 series microcontroller, which is inexpensive and widely used. The network card uses the ATL8019AS Ethernet controller chip produced by Taiwan Realtek . Since the program code of the Internet network protocol is large, the system has added some peripheral circuits in addition to the microcontroller and the network card. Including RAM memory used as data cache  and RS232 interface, the former is used as a data buffer, and the latter is used as an interface for data interaction between the microcontroller and the field equipment. The overall functional design of the system is shown in Figure 1.


In the above system design, the microcontroller mainly completes the unpacking of Internet data and the packaging of serial port RS232 data. The data packet transmitted by the remote PC reaches the Ethernet control chip RTL8019AS through the physical medium of the Internet. RTL8019AS executes the address resolution protocol and then hands it to the C8051 microcontroller. The microcontroller executes the TCP/IP protocol module, removes the TCP/IP header and hands the data to the field equipment of the data acquisition system through the RS232 serial port. On the contrary, if the field equipment sends data to the microcontroller, the microcontroller will package the data according to the TCP/IP protocol format and send it to RTL8019AS, which will be transmitted to the Internet by the network card chip. In the above way, the microcontroller completes the interaction with the Internet, thereby realizing the Internet remote control of the data acquisition system.


2.2 Interface circuit between microcontroller and network card


The single-chip microcomputer is the core of this system, so the interface circuit between the single-chip microcomputer and the network card is very critical. This system uses the 8051 series single-chip microcomputer because the 8051 single-chip microcomputer is the most commonly used single-chip microcomputer. It is inexpensive and widely used, and it is easy to reduce system costs in industrial equipment applications. At the same time, the 8051 program is concise and easy to debug. The connection circuit between the 8051 single-chip microcomputer and the Ethernet controller chip is shown in Figure 2.

Figure 2 Connection diagram between MCU and Ethernet control chip.

Figure 2 Connection diagram between MCU and Ethernet control chip.

The 8-bit data bus D0-D7 of the 8051 microcontroller P0 port, the 5 address lines A8-A12 of the P2 port, the read signal line RD, the write signal line WR, and the 2 timer control terminals T0 and T1 are respectively connected to the corresponding signal lines of Realtek8019AS.

The Realtek8019AS chip works in 8-bit bus mode. The 8051 microcontroller drives the network control chip RTL8019AS, and the Internet access is realized after the network isolation filter HR901170A.


3 Implementation of TCP/IP protocol stack on MCU


3.1 Embedded TCP/IP Protocol Stack


The TCP/IP protocol is the core protocol of the Internet. To realize embedded access to the Internet, the TCP/IP protocol must be implemented on the microcontroller. Since the TCP/IP protocol cluster is extremely large and the resources on the microcontroller are limited, it is impossible to fully implement the TCP/IP protocol on the microcontroller. At present, many companies have developed commercial embedded TCP/IP protocol stacks based on different embedded devices. The disadvantage of these protocol stacks is that they are aimed at chips produced by specific companies and require expensive software usage fees. If this type of protocol stack is used, the designed microcontroller embedded Internet system will not have a cost-effective advantage. After comparison, the open source TCP/IP protocol stack uIP0.9 was finally selected as the design core in this system. uIP0.9 is a small embedded TCP/IP protocol stack suitable for 8/16-bit microcontrollers. Interested users can download its source code on the Internet for free and modify it to meet different application needs. The uIP0.9 protocol stack adopts a modular design, retains the protocol mechanism necessary for network communication, greatly reduces the amount of protocol code (the amount of code is about several thousand bytes), and only requires a few hundred bytes of memory to run smoothly, reducing the protocol's requirements for system resources. uIP0.9 is fully adapted to current microcontroller embedded systems.


3.2 uIP Architecture


According to the needs of embedded systems, the uIP protocol removes many uncommon functions in the TCP/IP protocol, and retains the core parts such as ARP (optional), IP, ICMP, TCP, and UDP (optional) required in network communication. The protocol is written entirely in C language, and its code occupies very little space and requires very low RAM resources. For example, the IP/ICMP/TCP core module code size is 3304 bytes, and only 360 bytes of RAM are used. Its application layer interface and device driver layer interface are very simple.


The uIP protocol focuses on the implementation of IP, ICMP and TCP protocols, and takes UDP and ARP protocols as optional modules. The architecture of the uIP protocol is shown in Figure 3.

Figure 3 uIP protocol stack structure diagram

Figure 3 uIP protocol stack structure diagram.


3.3 uIP's underlying device driver interface and application programming interface


uIP is a protocol stack that only contains three layers of network layer core protocols. uIP itself does not contain any type of underlying network drivers and upper layer applications. It only provides interface functions for users to develop and use. Therefore, in order to complete the interaction with network devices, users must implement the driver of the underlying network device in uIP according to the type of network device. For this example, the network device is the RTL8019AS network card, so the driver of the RTL8019AS network card needs to be implemented in uIP. If users need to browse and obtain field data through the http protocol on the Internet, they must also implement the WEB application service based on the HTTP protocol on uIP.


The RTL8019AS network card driver first initializes the network card chip through the function init_8019as(), which is used to set the physical address of the network card, the location and size of the send and receive buffers, etc. The second is the data sending function eth_send() and the data receiving function eth_rcve().


The uIP protocol stack implements the driver for the underlying network device through the uip_input() function in the kernel, which is the underlying device entry of the uIP protocol. It contains two global variables uip_buf and uip_len. The former is used to store the received data packets, and the latter indicates the data length in the receiving and sending buffer. The uip_input() function processes the IP packets sent from the network device driver. After processing, it returns the variable uip_len. If uip_len is 0, there is no data to be sent. If it is not 0, the network device driver eth_send() function is called to send the data of uip_len length in uip_buf to the Ethernet. The eth_rcve() function stores the received data in the buffer specified by the cache uip_buf. The system calls the uip_input() function and calls the application when necessary.


uip_periodic() can be understood as a periodic clock function, which is usually executed once a second. The microcontroller uses it to periodically poll each connection. Because the uIP protocol has to handle many timing events, such as packet retransmission and ARP table entry update. When the periodic timing is triggered, each TCP connection calls uip_periodIC(), and its TCP connection number is passed as a parameter to the uip_periodic() function. The uip_periodic() function checks the status of the connection specified by the parameter. When the uip_periodic() function returns, it checks the value of uip_len. If it is not 0, the data packet in the uip_buf buffer is sent to the network.


The application interface of the uIP protocol is used to implement application services such as web. uIP defines a macro UIP_APPCALL() as the interface for users to use. When users want to program to implement a certain application service, they only need to define the macro UIP_APPCALL() as the actual application function name. After receiving the data packet from the bottom layer, if uIP needs to send it to the upper layer application for processing, it calls UIP_APPCALL(). Different connections are determined by judging the port number of the current connection. At the same time, uIP also provides some application interface functions for users to use when programming. Commonly used uIP application interface functions are: closing connection interface function uip_close(); polling interface function uip_poll(); opening connection interface function uip_connect(), etc. By calling different application interface functions, users can implement corresponding functions.


4. Design of MCU Main Program


After adding the underlying device driver module and application service program module and correctly configuring uIP, the main part of the software writing is the MCU main program function. The main program depends on what functions the user needs to achieve. For this example of connecting to the Internet through an Ethernet card to realize WEB application services, the MCU main program first starts the initialization work, including timer initialization, network card chip initialization, UIP protocol stack initialization, user application initialization, etc. [5]. After completing the initialization, the main program will continue to query. If a new IP data packet arrives on the network card, it will be sent to the uip_input() function for processing; if no new data packet arrives, the uip_priodic() function will process the timer event. Since the uIP protocol stack is written in C language, in order to facilitate the interaction between the MCU main program and the uIP protocol, the MCU main program also uses C language as the development language. The following is part of the design code of the MCU main program.

The link layer part of the TCP/IP protocol stack is completed by the network controller RTL8019AS, and the network layer and transport layer are processed by the microcontroller.


The application layer can be completed in the MCU according to the needs, or it can be transferred from the MCU to the user or terminal device. In addition to WEB services, other application layer services such as SMTP protocol support functions can also be written in corresponding codes according to needs.


5 System Testing


On the basis of completing the above work, we designed a parking monitoring and management system for the downtown parking lot. Since the downtown parking lot has a very busy business volume and the parking spaces are often saturated, not only managers but also customers often need to grasp the parking space vacancy information of the parking lot in real time. The front end of the data acquisition system monitors the vacancy status of each parking space through sensors. And timely feedback information to the single-chip microcomputer, the feedback information includes the parking space vacancy status, parking start time and duration, etc. Based on this, the monitoring system calculates the number of vacant parking spaces in the entire parking lot, and returns the information to the client, and displays it on the LED display screen at the entrance and exit of the parking lot in the form of announcement information. It is convenient for customers to make decisions. The billing information calculated according to the parking duration can also be displayed on the client. Combined with the above requirements, we implemented an embedded Web server on the single-chip microcomputer. Http web pages can complete applications such as receiving data, sending web page data, closing connections, and can dynamically update data in real time. The client uses the most commonly used Windows operating system and Internet Explorer browser, and the client does not need to install other special service programs. The system is only set to a maximum of 4 concurrent clients to access the single-chip microcomputer Web server. Figure 4 is the result of accessing the single-chip microcomputer Web server.

Figure 4. Client accessing the MCU Web server.

Figure 4. Client accessing the MCU Web server.


6 Conclusion


Embedded network communication is an emerging application field of embedded industry in recent years. Since the MCS-51 series of single-chip microcomputers have a long history and wide application, their low price, and the uIP protocol stack can be used for free, the products using this design scheme have low cost and less auxiliary hardware, so that the terminal price will not increase too much due to embedded access to the Internet. It has a very high cost performance and is easy to market. At present, the system developed based on this technology has been successfully applied in the busy parking lot monitoring system in the urban area. It can be applied to other single-chip microcomputer systems based on the 51 core with only a little improvement. This system can help industrial applications such as intelligent information appliances and production equipment monitoring to realize embedded Internet with a good cost performance.


Keywords:MCS-51 Reference address:MCS-51 single chip microcomputer realizes interaction with the Internet

Previous article:Wireless transmission system efficiency detection based on 51 single chip microcomputer wireless power supply module
Next article:The realization of data display of common anode digital tube using 51 single chip microcomputer

Recommended ReadingLatest update time:2024-11-16 12:46

The future of MCS-51 microcontroller
The part about the development history of Intel is taken from Baidu. Microcontroller is a computer system that uses very large scale integrated circuit technology to integrate CPU, RAM, ROM, IO, interrupt system, timer/timer and other circuit modules onto a silicon chip. The picture below is a 51-core STC Actual pictu
[Microcontroller]
The future of MCS-51 microcontroller
Analysis of arithmetic operation instructions of MCS-51 microcontroller
MCS-51 has four powerful arithmetic operation instructions: addition, subtraction, multiplication and division. 1. Program status word PSW MCS-51 has a program status word register PSW, which is used to save the flag of the instruction execution result for program inquiry and judgment. PSW is one of the special functi
[Microcontroller]
An example of the working mode and baud rate calculation of the serial port of MCS-51 single-chip microcomputer
1) Mode 0  Mode 0 is an external serial shift register mode. When working, data is serially input/output from RXD, and TXD outputs shift pulses to shift the external shift register. The baud rate is fixed at fosc/12 (that is, when TXD outputs a parity pulse per machine cycle, RXD receives or sends one bit of data). W
[Microcontroller]
Memory Classification of MCS-51
  Memory is a memory device used to store information in modern information technology. The concept is very broad and has many levels. In digital systems, anything that can save binary data can be a memory; so what types of memories are there in the MCS-51 microcontroller? How to classify it?   program memory   A micr
[Microcontroller]
Memory Classification of MCS-51
MCS-51 microcontroller hardware structure
MCS-51 basic structure ØCPU:8 bit Ø Memory: 128 bytes RAM; 4K bytes ROM memory Ø Parallel port: 4 8-bit parallel ports Ø Serial port: 1 full-duplex serial port Ø 21 dedicated special function registers Ø Timer/counter: 2 16-bit timers/counters Ø Interrupt system: 5 interrupt sources, two interrupt priorities Ø Address
[Microcontroller]
MCS-51 microcontroller hardware structure
Four working modes and functions of T0 and T1 of mcs-51 single chip microcomputer and calculation of timing initial value
1. Mode 0 When bit M1M0=00. T is a 13-bit counter, THi is the high 8 bits, and TLi is the low 5 bits.  The design value is N, then the initial value of the count is X=2^13-N; 2^13=8192=2000H  Example 1: Assume fosc=6MHz, and use T1 mode 0 for 10ms. Find the initial values ​​of TH1 and TL1.  The design initial value
[Microcontroller]
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号