当前位置:网站首页>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
边栏推荐
- What are the characteristics of trademark translation and how to translate it?
- Briefly describe the differences between indexes, primary keys, unique indexes, and joint indexes in mysql, and how they affect the performance of the database (in terms of reading and writing)
- pymongo获取一列数据
- Fedora/rehl installation semanage
- Erreur de type résolue avec succès: type de données « catégorie» non sous - jacente
- Entity Developer数据库应用程序的开发
- What is the difference between int (1) and int (10)? Senior developers can't tell!
- Windows Server 2016 standard installing Oracle
- Today's summer solstice
- 云上有AI,让地球科学研究更省力
猜你喜欢
[advanced software testing step 1] basic knowledge of automated testing
26岁从财务转行软件测试,4年沉淀我已经是25k的测开工程师...
Chapter 7 - thread pool of shared model
19.段页结合的实际内存管理
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
【每日一题】729. 我的日程安排表 I
Leetcode daily question (971. flip binary tree to match preorder traversal)
[daily question] 729 My schedule I
Entity Developer数据库应用程序的开发
【刷题】怎么样才能正确的迎接面试?
随机推荐
Every API has its foundation when a building rises from the ground
Reflex WMS medium level series 3: display shipped replaceable groups
[ 英语 ] 语法重塑 之 英语学习的核心框架 —— 英语兔学习笔记(1)
The difference between get and post request types
Huawei equipment configuration ospf-bgp linkage
雲上有AI,讓地球科學研究更省力
Biomedical English contract translation, characteristics of Vocabulary Translation
云上有AI,让地球科学研究更省力
My creation anniversary
librosa音频处理教程
SQL Server manager studio(SSMS)安装教程
[Yu Yue education] Dunhuang Literature and art reference materials of Zhejiang Normal University
Day 245/300 JS foreach data cannot be updated to the object after multi-layer nesting
18.多级页表与快表
Apache DolphinScheduler源码分析(超详细)
顶测分享:想转行,这些问题一定要考虑清楚!
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
指尖上的 NFT|在 G2 上评价 Ambire,有机会获得限量版收藏品
SAP SD发货流程中托盘的管理
基于购买行为数据对超市顾客进行市场细分(RFM模型)