当前位置:网站首页>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 internationalization of domestic games is inseparable from professional translation companies
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models. common‘ from ‘/home/yolov5/models/comm
- 接口自动化测试框架:Pytest+Allure+Excel
- E-book CHM online CS
- Bitcoinwin (BCW): the lending platform Celsius conceals losses of 35000 eth or insolvency
- Phishing & filename inversion & Office remote template
- Development of entity developer database application
- Py06 dictionary mapping dictionary nested key does not exist test key sorting
- Office doc add in - Online CS
- Day 245/300 JS foreach data cannot be updated to the object after multi-layer nesting
猜你喜欢
How effective is the Chinese-English translation of international economic and trade contracts
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
Introduction and underlying analysis of regular expressions
详解SQL中Groupings Sets 语句的功能和底层实现逻辑
Leetcode daily question (971. flip binary tree to match preorder traversal)
Reflex WMS中阶系列3:显示已发货可换组
雲上有AI,讓地球科學研究更省力
At the age of 26, I changed my career from finance to software testing. After four years of precipitation, I have been a 25K Test Development Engineer
Reflex WMS medium level series 3: display shipped replaceable groups
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 high frequency interview 20 questions, necessary (important)
The registration password of day 239/300 is 8~14 alphanumeric and punctuation, and at least 2 checks are included
SSO process analysis
Chapter 7 - thread pool of shared model
What are the characteristics of trademark translation and how to translate it?
Use shortcut LNK online CS
Office doc add in - Online CS
从autojs到冰狐智能辅助的心里历程
Database basics exercise part 2
When my colleague went to the bathroom, I helped my product sister easily complete the BI data product and got a milk tea reward
C语言_双创建、前插,尾插,遍历,删除
UWA Pipeline 2.2.1 版本更新说明
Prefix and array series
Pallet management in SAP SD delivery process
pymongo获取一列数据
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models. common‘ from ‘/home/yolov5/models/comm
Due to high network costs, arbitrum Odyssey activities are suspended, and nitro release is imminent
18.多级页表与快表
19.段页结合的实际内存管理
漏了监控:Zabbix对Eureka instance状态监控