当前位置:网站首页>Proteus -- Serial Communication parity flag mode
Proteus -- Serial Communication parity flag mode
2022-07-06 06:53:00 【Wonderful drifting of coal】
1. Circuit diagram
2. Code
(1) Machine a sends
#include<reg51.h>// Include access sfr Library function rug51、h
sbitP27=P2^7,// Define the driving end of parity marker lamp
bit F=0;// Define the reply flag of machine B - He Qing 0
unsigned char i;// Define the serial number of sending data i( Global variables )
unsigned char code c[10]=(// Define the sending data array , And the assignment
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0xf8,0xf8,0x80,0x90);//0~9 Gongyang share code
void main(){
// Main function of machine a
unsigned long t;// Define delay parameters t
SCON=0x90;// Set serial mode 2. Allow to receive
PCON=0;// Set up SNOD=0
IE=0x90;// Serial port is open
for(t=0;t<10;t++);// Time delay 0.5ms、 To facilitate serial initialization of machine B
while(1)(
for(i=0;i<10;i++)// Cycle to send 10 Data
ACC=c[i];// Get and send data
TBB=P;// The parity sign is sent TB6
P27=!P;// The parity sign is sent P2.7 Show
P1=ACC;// Send data serially P1 Mouth display
SBUF=ACC;// Send a frame of data in series
while(F==0);// Wait for the reply of machine B
F=0;// Reply 、 Reply sign of cleaning machine
P1=0xff;//P1 Mouth stop display
P27=1;// The parity sign light is off
for(t=0;t<11000;t++);}// Stop display 0.5s after , Return loop , Continue to send the next
for(t=0;t<11000;t++);}}//10 Data has been sent , Delay again 0.5s、 Start from scratch void
void insa() interrupt 4{
// A serial interrupt function
if(TI==1)TI=0;// If serial transmission is interrupted , Clear the serial transmission interrupt flag if(TI==1)TI=0;// Otherwise, the serial reception is interrupted , Clear the serial receive interrupt flag
else{
RI=0;// If the reply signal is FFH, error , Execute the following statement :
if(SBUF==0xff){
// Get and send data
ACC=c[i];// The parity bit is sent to TB8
TB8=P;//P2.7 Display parity bit
P27=!P;
// Resend data
SBUF=ACC;// Resend data to P1 Mouth display
P1=ACC;// If reply 0, No mistakes , Set B machine reply sign
else if(SBUF==0) F=1;}}
(2) Machine B receives
#include<reg51.h>
sbit P10=P1^0;// Define the drive end of the calibration marker lamp
sbit P11=P1^1;// Define the driving end of parity marker lamp
// Define the serial signal receiving flag , He Qing 0
bit f=0;
// Define the parity correct flag , He Qing 0
bit y=0;
void main(){
// Machine B main function
unsigned long t;// Define delay parameters t
SCON=0x90;// Set serial mode 2, Allow to receive
PCON=0;// Set up SMOD=0
IE=0x90;// Serial port is open
while(1){
// Infinite loop
while(f==0);// Wait for serial signal reception
f=0; Clear the serial signal receiving flag
if(y==1){
y=0;// If parity is correct , Clear the parity check correct flag
for(t=0;t<11000;t++);// Keep showing 0.5s
P2=0xff;// Off display
P11=1;P10=1;// The parity sign light is off , The calibration mark light is off
SBUF=0;// Send a signal that replies correctly
else SBUF=0xff;}}// Otherwise, the verification error , Send a reply error signal
void ins() interrupt 4{
// B machine serial interrupt function
if(TI==1)TI=0;// If serial transmission is interrupted , Clear the serial transmission interrupt flag
else(RI=0;// Otherwise, the serial reception is interrupted , Clear the serial receive interrupt flag
ACC=SBUF;// The nail reader sends a signal , And in PSM Generate parity messages for receiving data in
P2=ACC;// Receive data and send P2 Mouth display
P11=!RB8;// The first 9 Bit data is sent to P1.1 Show
P10=!P;// Parity check is sent to P1.0 Show
if(P==RB8)y=1;// If parity is correct , Set the parity correct flag
else y=0;// Otherwise, the verification error , Clear the parity check correct flag
f=1;}}// Set the serial signal receiving flag
边栏推荐
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- mysql的基础命令
- UNIPRO Gantt chart "first experience": multi scene exploration behind attention to details
- Prefix and array series
- SQL Server Manager studio (SSMS) installation tutorial
- 中青看点阅读新闻
- 【Hot100】739. 每日溫度
- BUU的MISC(不定时更新)
- Classification des verbes reconstruits grammaticalement - - English Rabbit Learning notes (2)
- What are the commonly used English words and sentences about COVID-19?
猜你喜欢
CS certificate fingerprint modification
18.多级页表与快表
My seven years with NLP
SQL Server manager studio(SSMS)安装教程
Entity Developer数据库应用程序的开发
同事上了个厕所,我帮产品妹子轻松完成BI数据产品顺便得到奶茶奖励
SAP SD发货流程中托盘的管理
CS passed (cdn+ certificate) PowerShell online detailed version
SQL Server Manager studio (SSMS) installation tutorial
Bitcoinwin (BCW): the lending platform Celsius conceals losses of 35000 eth or insolvency
随机推荐
What is the difference between int (1) and int (10)? Senior developers can't tell!
Attributeerror successfully resolved: can only use cat accessor with a ‘category‘ dtype
医疗软件检测机构怎么找,一航软件测评是专家
Day 246/300 SSH connection prompt "remote host identification has changed!"
On the first day of clock in, click to open a surprise, and the switch statement is explained in detail
[brush questions] how can we correctly meet the interview?
漏了监控:Zabbix对Eureka instance状态监控
Leetcode daily question (1870. minimum speed to arrive on time)
A method to measure the similarity of time series: from Euclidean distance to DTW and its variants
What are the commonly used English words and sentences about COVID-19?
BUU的MISC(不定时更新)
How much is the price for the seal of the certificate
[Yu Yue education] Dunhuang Literature and art reference materials of Zhejiang Normal University
My creation anniversary
编译,连接 -- 笔记 -2
Use shortcut LNK online CS
SAP SD发货流程中托盘的管理
UniPro甘特图“初体验”:关注细节背后的多场景探索
SQL Server Manager studio (SSMS) installation tutorial
机器学习植物叶片识别