1362 views|0 replies

3836

Posts

19

Resources
The OP
 

The msp430 microcontroller sends floating point numbers to the host computer through the serial port [Copy link]

Assembling data First assemble the data through the sprintf function. Tips for assembling data: length = 0; sprintf(Storage+length, "Rr=%4.3f ", g_StrComm.aSBuf[0]); length = strlen(Storage); //strlen =12 sprintf(Storage+length, "Rh=%4.3f ", g_StrComm.aSBuf[2]); length = strlen(Storage); //strlen =24 sprintf(Storage+length, "B1=Rr/Rh=%2.4f", g_StrComm.aSBuf[0]/g_StrComm.aSBuf[2]); length = strlen(Storage); SendStr(Storage,strlen(Storage)); //Assemble and send data 1 2 3 4 5 6 7 8 It is easier to assemble data in this way, which is convenient for obtaining the array length and updating the array content. The sprintf function can easily convert the floating-point number type to the char type. Each number corresponds to a byte. 2. Send data void SendStr(char SBuf[],int len) { int m = 0; for( m = 0; m < len; m++ ) //Loop to send len bytes { while (!(UCA1IFG&UCTXIFG)); // UART1 transmit register is ready UCA1TXBUF = SBuf[m] ; //Send one byte } }

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list