当前位置:网站首页>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
边栏推荐
- To create a high-quality geek for human beings, cloud + community starts the competition "discovery plan"
- Figure 1 understand Tencent reassurance platform
- Distributed background task load balancing
- Flutter - date of birth calculation age tool class
- Tidb massive region cluster tuning practice
- Some common IPv6 problems!
- How do fixed assets intensive enterprises manage fixed assets effectively?
- Best practices for building a distributed Domain Driven Architecture Based on data mesh
- How to use a Chinese domain name? Would you prefer a Chinese domain name or an English domain name?
- Script updates CLB type ingress Certificate in tke cluster
猜你喜欢
随机推荐
New core and new speed - next generation standard O & M engine
Havip+keepalived high availability building
What is domain name registration? Do you still need to purchase ECS after domain name registration?
How to get the website domain name? Does it cost money to apply for a website domain name?
What enlightenment does it consulting giant Accenture get from the blackmail attack?
How to register an enterprise domain name? Can an enterprise domain name be directly registered by individuals?
How to buy a domain name? Do you need to file a domain name purchase?
The instrument industry builds the supplier SRM mode to manage the development of manufacturers + users
NoClassDefFoundError and classnotfoundexception exceptions
Explain thoroughly and learn rotten binary tree (4): storage structure of binary tree - build heap - Search - sort
How do users in the insurance upgrade industry choose?
How about the online domain name? Is it easy to use from the current market
Test development knowledge map
How to build a website with a domain name? Is the website domain name free to use?
The basic concept of network is the relationship among services, protocols, processes and ports.
When we talk about zero trust, what are we talking about?
Kubernetes configures two ways of hot update
[Tencent cloud] enterprise micro marketing, private domain traffic value growth and operation efficiency improvement
[experience sharing] 1.39 million problem solving report of Tencent's internal track
Why should the domain name be filed? What materials are needed for the filing of enterprise domain names?