完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,我们正在研究PIC24FJ,在程序中我们取了一个可变的距离,现在这个距离为65536,必须转换为十六进制(0xFFFF),然后我想先把它逐个字节地传输到串行(0xFF),然后再传输到串行(0xFF)。这如何实现?????
以上来自于百度翻译 以下为原文 Hi, We are working on PIC24FJ, in the program we have taken a variable as int Distance; Now this Distance for ex is 65536 has to be converted to Hex (0xFFFF) then I want to transmit it byte by byte to serial(0xFF)first and (0xFF) next. How this can be achieved???? |
|
相关推荐
8个回答
|
|
森德托托厄萨特(距离& 0xFF);森德托托乌萨特(距离& gt;gt;8);
以上来自于百度翻译 以下为原文 Send_to_USART(Distance & 0xff); Send_to_USART(Distance >> 8); |
|
|
|
对于变量,十六进制、DEC或二进制没有区别。只有用不同的方式来显示它的值。如果你想用串行端口发送变量(原始二进制)值,你可以按照达里奥所说的去做(但是要注意字节数),或者你可以把它转换为ascistIn。您可以使用StastFF()将其转换为字符串。字符串需要两个字节来表示一个二进制字节。0FFF-和“FF”或“FF”。我猜这取决于接收机端您必须如何做。/ Ruben
以上来自于百度翻译 以下为原文 There is no difference between hex, dec or binary for a variable. It is only different ways to show its value. If you want to send the variable (raw binary) value with a serial port you can do as Dario says (but watch out for endianness) or you can convert it to an ASCII string. You can use sprintf() to convert it to a string. A string will need two bytes to represent one binary byte. 0xff -> "ff" or "FF". I guess it depends on the receiver end how you must do. /Ruben |
|
|
|
|
|
|
|
我花了太长时间写这个,所以al_bin在我前面……一个int是PIC24上的16位,所以它不能达到65536……一个int的最高数字是32767.0xFFFF实际上是-1。使用长int或无符号int来达到您65536的目标(只有几乎无符号int)。o建议不要将数据作为十六进制发送,因为您节省的传输空间非常小,但是根据端点性和有符号/无符号增加了值的不确定性。
以上来自于百度翻译 以下为原文 I spent too long writing this so al_bin got in before me... An int is 16 bits on a PIC24, so it cannot reach 65536... The highest number possible for an int is 32767. 0xFFFF is actually -1. Use a long int or an unsigned int to reach your goal of 65536 (only almost with unsigned int). But that aside I too would advice against sending the data as hex because you save very little transmission space but add the uncertainty of the value depending on endianness and signed/unsigned. Instead convert to regular decimal numbers in ASCII and send that. This is what the NMEA GPS protocol uses for instance. |
|
|
|
|
|
|
|
|
|
|
|
~(128)/H3>?是的,您可以用UART在原始中发送一个字节。但是,您不仅可以传输可打印字符,还可以传输控制代码,如XON、XOFF、BELL等。其他方法如其他人所解释的那样,发送“无符号int”或“int”值-作为字符串的“0”、“1”、“9”、“A”、“B”、“F”来表示十六进制中的整数。示例:45841dez->B3。11个十六进制->UART字符:'B'、'3'、'1'、'1'、'1'、'1'、'9'、'+'、-'表示整数的字符串。示例:45841dez->UART字符:'+'、'4'、'5'、'8'、'4'、'1'。传输的字符数取决于th的值。e整数。小整数在线上需要较少的字符。这需要终止字符,如CR>或
以上来自于百度翻译 以下为原文 ~µ<|&128/h3> ? yes, you can send one byte in raw by UART. But then you not only transfer printable characters but also control code like XON, XOFF, BELL etc.. The other methods are, as explained by others, sending the 'unsigned int' or 'int' value -as a string of characters '0','1'...'9','A','B'...'F' representing the integer in hex. Example: 45841dez -> B311 hex ->UART characters: 'B', '3', '1', '1' Each integer transmission requires 4 character on line. - a string of characters '0','1', '9','+',-' representing an integer. Example: 45841dez -> UART characters: '+','4','5','8','4','1' The number of transmitted characters depends on the value of the integer. Small integer require less characters on line. This requires a terminating character like CR> or each positive number (start of new value). Atherwise the receiver doesn't understand what you mean by transmitting 3469876094. ( you also could do your own coding for the last character: Maybe for the last character ( from '0' to '9' ) you add 32dez which converts the characters to the range 'P','Q',...'Y'. Instead of sending '+','4','5','8','4','1' you would then send '4','5','8','4','P' and when the 'P' arrives the receiver knows that you have finished with sending the value and can convert the last char from 'p' to '1'.) |
|
|
|
这取决于接收机。二进制协议在处理时间和传输速度上总是更有效。很容易分配几个框架字符,哦,看!ASCII定义ETX和STX,当它们出现在数据流中时,使用DLE来逃避它们。
以上来自于百度翻译 以下为原文 That depends on the receiver. A binary protocol will always be more efficient both in processing time and transmission speed. It's very easy to allocate a couple of framing characters, Oh, look! ASCII define ETX and STX, and use DLE to escape them when they appear in the data stream. |
|
|
|
只有小组成员才能发言,加入小组>>
5166 浏览 9 评论
2000 浏览 8 评论
1929 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3175 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2227 浏览 5 评论
736浏览 1评论
619浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
507浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
633浏览 0评论
530浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 08:04 , Processed in 1.506593 second(s), Total 61, Slave 54 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号