嗯,我还是不明白你为什么(或者是谁?)在BMP文件中编码一维LED行的模式。或者它是一个二维矩阵?我也看不出LED行和机械阀之间的关系。这听起来像是一个奇怪的规范。但我可能是太好奇了。首先你必须看看你是否有控制(写固件)在接收MCU上,或者你是否只是为了完成一个给定的协议。也就是说,你没有选择,你必须用所需的串行数据格式“服务”MCU。由于这个原因,如果你现在把你的数据传输到你的TyTalm,这可能不是很有帮助,但是最终你可能需要完全不同的格式。如果您目前只使用PIC和Teraterm来开发对1位单色BMP格式的理解,那么这是一个非常难的方法。我这样说是因为你必须决定是简单地发送二进制字节,还是你必须(或想要)将它编码为(例如)ASCII字符。答案取决于我不知道的几件事。此外,你还必须考虑数据传输中的错误。错误是多么关键,你需要多少努力或投入,使传输无错误(多长时间的电缆,RS485或RS232等PP)。每秒传输多少数据等等。论坛讨论中的其他线程都是二进制编码传输,或者是否使用安全协议。但是由于我有太多的开放性问题,现在我只需跳过我的考虑,只需参考Y。我们的问题。是的,我看了一下。你的代码和传输,也就是结果看起来还好。10101010B是0xAA,这是正确的。既然你已经假设了你的额外ATOI用法是错误的。对我来说,也是混淆的,因为我看不到,你在这里做什么。我没有看到缓冲区的声明,但有可能是它的缓存缓冲区[8 ]。您已经将信息输出为“10101010”,它看起来OK(它是0xAA的二进制表示),如果您喜欢该表示。可能你不是零终止这个数组,直接把它作为字符串在其他函数中使用,我没有检查原始的BMPDekDR.ChanyWoad,如果偶然地被正确地终止,那么这个字符串(表示一个数字)被解释为十进制数,而不是二进制值。如果你的编译器是32位,那么你的结果值可能是0x9a2112。不知道,你的UART2PUTHEX是如何实现的,但是在你的情况下,它只输出最重要的字节,即0x12;卡兰,印象可能是,你不知道比特、字节和数字的内部表示以及它们对用户的表示。完全错了,本身不是问题,我只是这么说,因为错误的理解可能会让你选择一个完全错误的方法来处理你假设的真实任务,即通过串行线传输LED的一些模式信息。
以上来自于百度翻译
以下为原文
Ehmm, I still do not understand why you (or who?) encodes the pattern for a one-dimensional LED row within a BMP file. Or is it a two dimensional matrix? . Also I cannot see the relation between an LED row and a mechanical valve. It sounds like an odd specification. But may be I'm too curious.
First you would have to see whether you have control (write the firmware) over the receiving MCU
or whether you have simply to fulfill a given protocol. I.e. you have no choice, you must 'serve' the MCU with the desired serial data format. Also for this reason it may be not very helpful, if you now transmit your data to your TeraTerm,- but finally you might need a totally different format. If you currently only use your PIC and Teraterm to develop an understanding of the 1-bit monochrome BMP format, then this is a really hard way to do it.
I say this because you have to decide whether you simply send binary bytes, or whether you either must (or want) to encode it as (e.g.) ASCII characters. The answer depends on several things which I do not know. Also you have to think about errors in the transmission of the data. How critical are errors, how much effort do you want or have to invest to make the transmission error free (how long are the cables, RS485 or RS232 etc. pp ..). How much data will be transferred per second etc. There are other threads in the forum discussion pro/cons of binary versa encoded transmission, or whether to use protocols for safety.
But since there are far too many open questions for me, I simply skip my considerations for now and just refer to your questions. Yes, I have had a look.
Your code and transmission, i.e. the results again looks OK. 10101010b is 0xAA, that 's correct. As you already assumed your additional atoi usage is wrong.
Yes confusing for me, too, since I do not see, what you are trying to do here.
I do not see the declaration of buffer, but likely its e.g. char buffer[8] ?
You already have output the information as e.g. "10101010", which looks ok (it is the binary representation of 0xAA), if you like that representation.
Probably you are not zero terminating this array to use it directly as a string in other functions, I did not check the original bmpdecoder.c
Anyway, if by chance it is correctly terminated then this string (representing a number) is interpreted as decimal number, but not as binary value. If your compiler is 32 bit then then your result value likely is 0x9A21
12.
No idea, how your UART2PutHex(ObtainedValue) is implemented, but in your case it just outputs the least significant byte, which is 0x12;
Karan, may impression is, that you are not aware of the internal representation of bits and bytes and numbers and their representation to the user.
This may be completely wrong and is not a problem in itself,- I'm only saying this, because a wrong understanding might let you choose a completely wrong approach to your assumed real task, i.e. transferring some pattern info for LEDs over a serial line.