Design of Bidirectional Communication Controller Based on CPLD and Single Chip Microcomputer

Publisher:MagicalSerenadeLatest update time:2012-09-17 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In traditional control systems, people often use single-chip microcomputers as the control core. However, this method has complex hardware connections and poor reliability. In addition, the number of ports, internal timers and interrupt sources of single-chip microcomputers are limited, and in practical applications, external expansion chips are often required. This undoubtedly brings many inconveniences to the design of the system.

Now many systems use programmable logic devices (CPLD) as the control core. Compared with traditional designs, it not only simplifies the interface and control, improves the overall performance and reliability of the system, but also creates conditions for system integration. However, the D flip-flop resources of programmable logic devices are very limited, and programmable logic devices are not as convenient as single-chip microcomputers in controlling timing. Many unfamiliar users often find it very difficult to use. The two-way communication controller composed of programmable logic devices and single-chip microcomputers overcomes the shortcomings of both and maximizes the advantages of both.

1 Principle of bidirectional serial communication between CPLD and MCU AT89C51

1.1 Serial communication from MCU to PLD

The serial communication interface circuit from the microcontroller to the CPLD is designed in the CPLD using the VHDL language to design an eight-bit shift register with serial input and parallel output, and its port is connected to P1.4~P1.7 of the microcontroller, as shown in Figure 1. CS is the microcontroller selection signal, and when it is low, the eight-bit register is enabled; when the rising edge of the DCLOCK signal reaches the clk port, the eight-bit shift register will shift in one bit of data output by the microcontroller to cxin; when the eight-bit data in the microcontroller A register is to be transmitted to the CPLD, eight consecutive rising edges are generated at P1.6, and the microcontroller will sequentially shift the data in A to cxin, and after eight times, the data segment in A will appear in cxout of the CPLD.

The VHDL source program is as follows:

entity cuanxing is

port (clk, cxin, cs: in std_logic;

cxout:out std_logic_vector(7 downto 0));

end;

architecture rtl of cuanxing is

signal shift:std_logic_vector(7 downto 0) ; parallel output of eight-bit temporary variables

begin

process(clk)

begin

if (cs = '0') then

shift <= (others=>'0'); if not selected, output all zeros

elsif(clk'event and clk='1')then ;If the rising edge reaches clk, it is selected.

shift(7 downto 1)<=shift(6 downto 0) ; eight bits of data are shifted forward one bit

shift(0)<=cxin; the lowest bit is input by cxin

end if;

end process;

cxout<=shift; send eight-bit variable to port

end rtl;

The corresponding single-chip microcomputer control subroutine is as follows (the data to be sent is stored in A):

CS EQU P1.4

EN EQU P1.5

DCLOCK EQU P1.6

DOUT EQU P1.7

CONV: PUSH 07H

MOV R7, #8; store the shift number 8 in R7

CLR DCLOCK

SETB CS ; Select shift register

CLR EN

CLR C

JXL: RLC A; shift left one bit and send the data to be sent to CY

MOV DOUT, C ; send to port

ACALL YS1MS

SETB DCLOCK; Give a rising edge to shift data into the shift register

ACALL YS1MS

CLR DCLOCK

DJNZ R7, JXL; if it is less than 8 times, send the next one

SETB EN; All eight bits of command words are shifted in, giving EN a rising edge to make the CPLD perform the corresponding operation

ACALL YS1MS

POP 07H

RET[page]

1.3 Serial communication from PLD to MCU

The serial communication from PLD to MCU is similar to the serial communication from MCU to PLD, except that the eight-bit register is changed to parallel input and serial output, and its port is shown in Figure 2. When the MCU's cs=1, the register is selected; when load=1, the data to be sent is loaded to bxin; when the clk rising edge arrives, the data is shifted out to bxout one bit at a time, and at the same time, the MCU receives the data from bxout one bit at a time. After eight rising edges of clk, the data loaded into bxin is transmitted to the A register of the MCU (the VHDL and MCU source program are not given due to space limitations).

2 Implementation principle of dual control system

Since the microcontroller has limited ports, most of the peripheral device connections are completed by CPLD, while those peripheral devices with higher requirements for timing control are indirectly controlled by the microcontroller. The so-called indirect control means that the user can customize many command words, and each command word corresponds to one or a series of operations of CPLD. When the microcontroller wants an external device to implement a certain function, it can transmit the command word to the programmable logic device CPLD through serial communication. After the CPLD receives the command word and judges the command word, it will perform the corresponding operation after the rising edge of EN arrives. It is worth mentioning here that after the command word is transmitted to the CPLD, the CPLD can only perform the corresponding operation after the rising edge of EN arrives. This is to prevent the command word from causing the CPLD to malfunction during the word transmission.

When an external device has an interrupt signal fed back to the controller, a specific command word can also be sent from CPLD to AT89C51, causing AT89C51 to generate an interrupt for processing. However, no matter how many peripheral devices need to generate interrupt control. In the AT89CF51 interrupt subroutine, the serial communication program from CPLD to the microcontroller is run, and the specific command word is read into the A register, so that it can be known whether it is an interrupt generated by a peripheral device (defined by the user), and then what kind of external operation is required.

This dual control system is very flexible and convenient to use in project design. Here, an eight-bit command word is used, and up to 256 command words can be customized. Since both a single-chip microcomputer and a CPLD are used, programming is very flexible and convenient, and engineers can choose accordingly according to their own characteristics. For example, some people's single-chip microcomputer programming ability is slightly better than CPLD language programming, so he can define the operation corresponding to the command word in VHDL language programming to be simpler (the simplest is to make a certain pin high or low); if you want to simplify the programming of the single-chip microcomputer, you can make the operation corresponding to the specific command word in VHDL language programming more complicated.

The programming process of the microcontroller is to write different command words to the A register and then call the serial communication subroutine. If it is a VHDL command word, then call the serial communication subroutine. If the VHDL command word corresponds to a simpler program, then more command word calls will be required to complete the operation of a specific peripheral device. Vice versa, that's all.

In short, it is much easier to develop projects using a dual controller consisting of a single-chip microcomputer and a CPLD than to use them separately.

Keywords:MCU Reference address:Design of Bidirectional Communication Controller Based on CPLD and Single Chip Microcomputer

Previous article:Garbage weighing and charging control system based on AT89S51
Next article:Traffic light assembly original program based on 51 single chip microcomputer

Recommended ReadingLatest update time:2024-11-16 15:27

MCU programmer learns Arduino in one day
Some people may say that one day is too fast, and of course some people may say that one day is too slow. Yes, it is true, because for people on Earth who have learned 51 and STM, One day is indeed too long. But for those who have not learned it, As long as you are a qualified programmer, you can learn it in one day.
[Microcontroller]
51 single chip smoke alarm production + program
  Smoke alarm production process and related programs //Program header function #include reg52.h   //Macro definition #define uint unsigned int #define uchar unsigned char #define Data_ADC0809 P1 //Pin declaration sbit Feng = P3^0; //ADC0809 sbit ST=P3^3; sbit EOC=P3^4; sbit OE=P3^2; //Button sbit
[Microcontroller]
51 single chip smoke alarm production + program
Single chip microcomputer dynamic scanning interface and program design
  In the single-chip system, the dynamic scanning display interface is one of the most widely used display methods in the single-chip system. Its interface circuit connects the same-named ends of the 8 stroke segments ah of all displays together, and the common pole COM of each display is independently controlled by th
[Microcontroller]
Distributed battery management system based on single chip microcomputer design
1 Introduction     With the rapid development of high technology and its industry, battery energy systems with large storage capacity have been increasingly valued by people and have been widely used in many fields. For example, in the new direction and new hot spot of the development of the automobile industry - th
[Microcontroller]
Distributed battery management system based on single chip microcomputer design
Conversion between MCU system time and Unix time
Implementation on LPC1778/1788 /******************************************************************************************************** * FunctionName   : GetSecondTime() * Description    : 日期格式转化为unix time * EntryParameter :  * ReturnValue    :  **********************************************************************
[Microcontroller]
Design of sound and light control circuit and energy-saving lighting system based on single chip microcomputer
  1 Introduction The sound and light control circuit is an electronic switch that works with sound and light control circuits. It converts sound (such as clapping) and light into electrical signals, amplifies and shapes them, and outputs a switch signal to control the operation of various electrical appliances. It has
[Microcontroller]
Design of sound and light control circuit and energy-saving lighting system based on single chip microcomputer
PIC microcontroller serial port transmission and key press
This is a PIC microcontroller serial port transmission experiment that I tried while learning PIC microcontroller debugging. When the button RB0 is pressed, num is incremented, and the LED connected to the RC0 port flips, and the number num is passed to the transmission register and sent to the computer end. The baud
[Microcontroller]
Design of Arbitrary Waveform Generator Based on CPLD and Single Chip Microcomputer
introduction In electronic engineering design and testing, some complex signals with special requirements are often needed, requiring that their waveforms can be generated arbitrarily and the frequency can be easily adjusted. It is difficult for ordinary signal generators to meet the requirements, and the arbit
[Microcontroller]
Design of Arbitrary Waveform Generator Based on CPLD and Single Chip Microcomputer
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号