当前位置:网站首页>Realization of data transmission between a and B computers by using single chip microcomputer serial port
Realization of data transmission between a and B computers by using single chip microcomputer serial port
2022-06-24 05:51:00 【Distant stars】
subject : The serial port of single chip microcomputer is used to realize the data transmission between machine a and machine B .
requirement :
- ① Machine a continuously sends 0-F, Co recording 16 Characters , And display it on the nixie tube ;
- ② Machine B receives the content of machine a and sends it back after displaying it with nixie tube ;
- ③ After receiving the content returned by machine B, machine a compares it with the current content , If consistent, send the next ;
- ④ Crystal vibration is 11.0592Mhz, The baud rate of data communication is 2400.
1、 Virtual circuit diagram
2、 To achieve the effect of
3、 Related codes
- ① Transmitter section
#include<reg51.h>
#define uchar unsigned char
char code map[]={
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7c,0x39,0x5e,0x79,0x71
};
void delay(unsigned int time){
unsigned int j = 0;
for(;time>0;time--)
for(j=0;j<125;j++);
}
void main(void){
uchar counter=0; // Define counters
TMOD=0x20; //T1 Timing mode 2
TH1 = TL1 = 0xf4;//2400b/s
PCON=0; // Baud rate does not double
SCON = 0X50; // Serial port mode 1,TI and RI Zero clearing , Allowable convergence
TR1=1; // start-up TI
while(1){
SBUF = counter;// Send a contact signal
while(TI==0); // Wait for the send to complete
TI=0; // clear TI Sign a
while(RI==0); // Wait for machine B to answer
RI=0;
if(SBUF == counter){ // If the return value is the same as the sending value , Organize new data
P2 = map[counter];// Show sent values
if(++counter>15) counter=0;// Correct the counter value
delay(1000);
}
}
}- ② Receiver part
#include<reg51.h>
#define uchar unsigned char
char code map[]={
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7c,0x39,0x5e,0x79,0x71
};
void main(void){
uchar receive; // Define the receive buffer
TMOD=0x20; //TI Timing mode 2
TH1=TL1=0xf4; //2400b/s
PCON=0; // Baud rate does not double
SCON=0x50; // Serial port mode 1,TI and RI Zero clearing , Allow to accept
TR1=1; // start-up TI
while(1){
while(RI==1){ // Wait for reception to complete
RI = 0; // clear RI Sign a
receive = SBUF; // Get the received value
SBUF = receive; // The result is returned to the host
while(TI==0); // Wait for the end of sending
TI = 0; // clear TI Sign a
P2 = map[receive]; // Displays the received value
}
}
}If there is any deficiency , Please leave a message in the comments area or send me a private letter , I will add .
Thank you for your support , I hope you can praise , Focus on , Collection , Three times with one click .
author : Stars in the distance CSDN:https://blog.csdn.net/qq_44921056
边栏推荐
- PV and PVC analysis and use in kubernetes
- How do virtual hosts bind domain names? Can binding failure be used normally?
- Flutter - date of birth calculation age tool class
- The instrument industry builds the supplier SRM mode to manage the development of manufacturers + users
- How do users in the insurance upgrade industry choose?
- What happened to the JVM locking on Tencent ECS?
- How to set the secondary domain name of the website? What should I pay attention to when setting the domain name?
- Build ZABBIX on Tencent ECS
- Net domain name? Net domain name?
- Where to check the computer domain name and where to buy the domain name is more reliable
猜你喜欢
随机推荐
How to build a website with a domain name? Is the website domain name free to use?
How to use a Chinese domain name? Would you prefer a Chinese domain name or an English domain name?
Deleting a data table in a command prompt window
What does it mean that the domain name is being walled? How to solve the problem of domain name by wall?
How to record the purchased domain name? Why should the purchased domain name be filed?
Supply chain innovation of industrial Internet cloud computing
How do users in the insurance upgrade industry choose?
How to buy a website domain name? How to select a website domain name?
"Adobe international certified" graphic designer! How to break through the creative barrier and gain both fame and wealth?
Massif tool of Valgrind
How to register a secondary domain name? What are the precautions when registering?
What is a Chinese domain name? What are the types of Chinese domain names?
Is the prospect of cloud computing in the security industry worth being optimistic about?
Net domain name? Net domain name?
The joint network security laboratory of runlian technology and Tencent security was officially unveiled
Spirit breath development log (6)
Best practices for building a distributed Domain Driven Architecture Based on data mesh
How to apply for a company domain name? Does it cost money to apply for a company domain name?
Kubernetes configures two ways of hot update
Tamp the foundation, step into the cloud and rise to the original cloud Devops