51 Serial Communication Proteus

We first need to build up in the environment Proteus. I used here is version 8.8.
Here Insert Picture Description

We can use two components to establish a connection VIRTUAL TERMINAL and COMPIM of. As shown above, the two VIRTUAL TERMINAL COMPIM RXD and TXD and the RXD is connected. TXD and RXD and TXD and RXD corresponds COMPIM connected microcontroller.
VIRTUAL TERMINAL is the serial monitoring instrument, the waveform can capture it will conform to the RS232 protocol data lines, and displayed, the waveform may be transmitted to the data line RS232 protocol; COMPIM serial port elements, may be provided on the computer which occupies a serial port. It will then set the communication rate and communication format, provided to achieve the same properties on the list box. Such a data communication can be achieved. The figure below shows VIRTUAL TERMINAL and COMPIM settings.

Here Insert Picture Description
Here Insert Picture Description
Next step is to install the virtual serial port. Run program virtual serial port, configure virtual serial port, here I added COM2, COM4 two virtual serial ports.

Here Insert Picture Description
After the increase, the left will appear COM2, COM4, ​​and can also see the two ports interconnected in Port Device Manager, in which case our virtual serial port configured.

Here Insert Picture Description
Here Insert Picture Description
Then you can open the serial debugging assistant debugging and testing serial port is working properly. Two serial debugging assistant opens the window, a set COM2 port, another port to COM4, ​​to send information to each other. Information received normal, it indicates that virtual serial port can have a normal work.

Here Insert Picture Description
Then the frequency of the oscillator in microcontroller Proteus to 11.0592MHz.

Here Insert Picture Description
Here Insert Picture Description
Click to run the simulation after importing the corresponding hex file. At this point microcontroller serial Proteus is COM2, set the serial debugging assistant to COM4. Transmission scheme in a transmission AA hexadecimal, can light the corresponding LED. In the virtual terminal may also be displayed in hexadecimal received.

Here Insert Picture Description
Here Insert Picture Description

测试代码:/*控制LED的亮灭*/
#include <reg52.h> 
#define uchar unsigned char
uchar a; 
void uart_init();
void main() 

{ 

    uart_init();
    while(1)  { 		
            	 } 

} 

void serial() interrupt 4   // 串口中断服务函数
{ 
    if(RI)
		{
 		   a=SBUF; // 读出接收到的数据
   		   RI=0; // 清零接收标志位 
           P0=a;  //将接受到的数据给P0端口	
		}

} 

void uart_init()

{

	  SCON = 0x50;//配置SM0/1,并允许接收
     TMOD=0x20; // 设置定时器1 为方式2
     TH1=0xfd;  //装入初值 对应波特率9600
     TL1=0xfd; 
    TR1=1; //启动定时器1 
    EA=1; // 打开总中断开关
    ES=1; // 打开串口中断开关 

}

Published an original article · won praise 3 · Views 171

Guess you like

Origin blog.csdn.net/weixin_43728814/article/details/104390838