Proteus and Keil Cx51 microcontroller simulation (serial port simplex communication 2)

Publisher:NexusDreamLatest update time:2015-12-25 Source: eefocusKeywords:proteus  keil  Cx51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The serial ports of the microcontrollers U1 and U2 both work in mode 3, with U1 as a receiver and U2 as a transmitter. The baud rate is 9600. After U1 receives the data sent by U2, it sends it to ports P1, P0 and P2 in turn for running light display. Write a program and simulate it with Proteus.

Circuit Diagram:



U1 Program:

#include//Includes the header file of the microcontroller register
sbit p=PSW^0;
unsigned char receive(void)//Receive a byte of data
{
unsigned char dat;
while(RI==0);
RI=0;//As long as the receive interrupt flag RI is not set to 1, wait until the reception is completed (RI1)
ACC=SBUF;//Store the data in the receive buffer in dat
if(RB8==P)//Odd parity
{dat=ACC;return dat;}
}
void main(void)
{
unsigned char i;
TMOD=0x20;//Timer T1 works in mode 2
SCON=0xd0;//SCON=1101 0000B, serial port working mode 1, allow reception (REN=1)
PCON=0x00;//PCON=0000 0000B, baud rate 9600
TH1=0xfd;TL1=0xfd;//Assign initial value to timer T1 according to regulations
TR1=1;//Start timer T1
REN=1;//Allow receiving
while(1)
{
for(i=0;i<9;i++)P1=receive();//Send data to P1 port
for(i=0;i<9;i++)P0=receive();//Send data to P0 port
for(i=0;i<9;i++)P2=receive();//Send data to P2 port
}
}

U2 Program:

#include//Header file including microcontroller registers
sbit p=PSW^0;
unsigned char code Tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff};//Flowing light control code, the data is defined as a global variable
void send(unsigned char dat)//Send a byte of data to PC
{
ACC=dat;
TB8=p;
SBUF=dat;
while(TI==0);//Send and wait for
TI=0;
}
void delay(void)//delay about 150ms
{
unsigned char m,n;
for(m=0;m<200;m++)for(n=0;n<250;n++);
}
void main(void)
{
unsigned char i;
TMOD=0x20;//TMOD=0010 0000B, timer T1 works in mode 2
SCON=0xc0;//SCON=1100 0000B, serial port works in mode 3, SM2 is set to 0, multi-machine communication is not used, TB8 is set to 0
PCON=0x00;//PCON=0000 0000B, baud rate 9600
TH1=0xfd;TL1=0xfd;//assign initial value to timer T1
TR1=1;//start timer T1
while(1)
{
for(i=0;i<27;i++)//simulate detection data
{
send(Tab[i]);//send data i
delay();//send detection data once every 50ms
}
}
}


Keywords:proteus  keil  Cx51 Reference address:Proteus and Keil Cx51 microcontroller simulation (serial port simplex communication 2)

Previous article:Proteus and Keil Cx51 microcontroller simulation (serial port simplex communication)
Next article:Proteus and Keil Cx51 microcontroller simulation (serial port output expansion)

Latest Microcontroller Articles
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号