Method of transmitting floating point data using serial port of single chip microcomputer

Publisher:清新家园Latest update time:2019-10-08 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

We all know that the unit of transmission of the microcontroller serial port is byte, and the floating point number occupies four bytes. The simple idea is to use a char pointer to point to the floating point data, and use the pointer addressing to split the floating point number into four char data. The receiving end receives four char numbers. In order to restore them to float data, using a union is a good way. The test code is as follows:

      

The program running results are as follows:

      

 

Note: If you use signed character data in the structure, there will be some problems when printing with printf. You can try it.


Of course, there is also the big-endian and small-endian problem that is often mentioned in embedded systems. I believe everyone understands what is going on.


Keywords:MCU Reference address:Method of transmitting floating point data using serial port of single chip microcomputer

Previous article:Commonly used IO port levels
Next article:Processing of float data in serial communication

Recommended ReadingLatest update time:2024-11-15 13:40

A fast code generation method based on single chip microcomputer
With the continuous development of software and hardware technology, the system development cycle is becoming more and more important, but there is a certain conflict between the development time and system security. If the traditional way of writing code is still used, the company will obviously lose a lot of opportun
[Microcontroller]
A fast code generation method based on single chip microcomputer
How to upgrade from single chip microcomputer to DSP
  In the past few decades, the widespread application of single-chip microcomputers has realized simple intelligent control functions. With the progress of informatization and the rapid development of computer science and technology, signal processing theory and methods, the amount of data that needs to be processed i
[Embedded]
A car can be packed with 100 MCUs, and the market size in my country can reach hundreds of billions of yuan
"China is the world's largest automobile producer and seller, and also has the world's largest automotive MCU market. Currently, an average car uses about 100 MCUs. According to this estimate, the total volume of my country's automotive MCU market is about 2 billion, with a market size of hundreds of billions of yuan.
[Automotive Electronics]
A car can be packed with 100 MCUs, and the market size in my country can reach hundreds of billions of yuan
Let you use 51 microcontroller to make a simple electronic clock
I. Introduction Today I would like to recommend a small experiment with 51 microcontroller to you, using the 51 microcontroller to make a simple electronic clock. The timing module uses the DS1302 hardware module, and the display uses an LCD display. Let’s take a look at how to implement it! 2. Introduction to DS1
[Microcontroller]
Let you use 51 microcontroller to make a simple electronic clock
Microcontroller basketball scorer program and simulation diagram
1. Basic requirements (1) Independently design the circuit required by the system according to the requirements of the topic, and complete the production and debugging of the hardware circuit. (2) Be able to score normally in combination with the hardware         (3) Be able to display the score normally.         (
[Microcontroller]
Course Design: Single Chip Microcomputer DA Conversion
  //Here we use a single buffer mode, the microcontroller sends the DAC0832 every 1s //The output voltages of the five data 3FH, 7FH, F0H, 0FFH, and 00H change cyclically. //This program must set up the circuit diagram, and all DA pins are set in working state      ORG 0000H        AJMP MAIN      ORG
[Microcontroller]
Course Design: Single Chip Microcomputer DA Conversion
Introduction to C51 MCU Timer
Introduction The timer and counter in C51 are supported by the same hardware circuit. By configuring the registers differently, it can be used as a timer or a counter. To be precise, the difference between a timer and a counter is the signal that causes the count memory behind them to increase by 1. When configured
[Microcontroller]
Research on LCD Display Technology of Low-cost Single-Chip Microcomputer System
  1 Introduction   With the rapid development of electronic technology, the design of electronic circuits has become increasingly complex. Microcontrollers have been increasingly widely used in electronic design because of their high integration, high stability and low cost.   First, although the use of digital di
[Microcontroller]
Research on LCD Display Technology of Low-cost Single-Chip Microcomputer System
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号