完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,伙计们。我有一个我无法理解的问题,我希望有一个对C更深入的知识的人比我能在这件事上有所启发。首先我用MPLAB V85和HealthCC-V7.6Lite的16F87。我知道它都是旧的,但它通常为我服务!这是问题-我需要发送命令字符串到一个LCD触摸屏显示器,以显示频率为10Hz的分辨率。整个命令字符串是pGo0.0.t1.txt=“x.xxx,xx”0xff0xff0xfff,其中x表示频率,并存储在数组FrqBuf[]中,这工作时间很好。假设从0增加10Hz的频率。一切都很好,它显示正确,直到频率从0.039990赫兹到0.040000赫兹,当垃圾显示在最后三个数字。它在400000 kHz等时是相同的。在调试模式中的单步显示,变量REM(见附加代码)从40000跳到65536,因为它试图在4之后计算第一个零。它将继续显示最后三个数字中的垃圾,直到第四个数字正确地从9翻转到零,所有的工作都在意料之中,直到下一个4出现在第四位。当第五、第六和第七位数字显示为4时,其余的数字都显示为垃圾。它可能不是最有效的,但是对我来说,它是直观的,在任何你选择的数字基础上的计算器上都可以工作。有什么线索可以帮助你吗?我希望我已经包含了足够的信息,如果不是,我相信你会告诉我。
以上来自于百度翻译 以下为原文 Hi guys. I am having a problem that I cannot understand and I was hoping that someone with a more in-depth knowledge of C than I might be able to shed some light on the matter. First off I am using a 16F887 with MPLAB v8.5 and Hi-Tech C v9.6 Lite. I know it is all old but it serves me well usually! Here is the problem - I need to send a command string to an LCD touch screen display to display frequency to a resolution of 10Hz. The entire command string is page0.t1.txt="xx.xxx,xx"0xFF 0xFF 0xFF where x denotes the frequency and is stored in the array freqbuf[] and this works fine some of the time. Let's say I increment the frequency by 10Hz steps from zero. All is well and it displays correctly until the frequency rolls over from 00.039,990 Hz to 00.040,000 Hz when rubbish is displayed in the last three digits. It is the same when it goes to 400,000 KHz and so on. Single stepping in debug mode shows that the variable rem (see attached code) jumps from 40000 to 65536 as it attempts to calculate the first zero after the 4. It will continue to display rubbish in the last three digits until the fourth digit, which behaves properly, rolls over from 9 to zero and everything works as expected until the next 4 occurs in fourth digit. It is the same when the fifth, sixth and seventh digits show 4, the remaining digits show rubbish. The routine I use for the conversion is attached. It may not be the most efficient but to me it is intuitive and works ok on a calculator in any number base you choose. Any clues that might help? I hope I have included enough information, if not I am sure you will let me know. Attachment(s) Encoder.doc (24.00 KB) - downloaded 12 times |
|
相关推荐
7个回答
|
|
不确定,但是你为什么不把每个数据的“数据”除以10呢?
以上来自于百度翻译 以下为原文 Not sure, but why don't you just divide "data" by 10 at each digit? |
|
|
|
这看起来可疑:当“int”是16位时,你不能这样做,例如9×10000。使用10000 UL.HTTP://C-FAQ.COM/ExPR/ItoVeluff1.HTML
以上来自于百度翻译 以下为原文 This looks suspicious:((freqbuf[18] - 0x30) * 10000)You can't do, for example 9 * 10000 when "int" is 16 bits. Use 10000UL. http://c-faq.com/expr/intoverflow1.html |
|
|
|
感谢那些不辞辛劳地发表一个明智的答复的人。所有的整数都被声明为无符号长,但是你所提到的给了我一个想法,当我下一步能回到它的时候。MbEdter,我建议你尝试更多地开发你的社交技巧,当你变老时它会有用。
以上来自于百度翻译 以下为原文 Thanks to those that took the trouble to post a sensible reply. All integers have been declared as unsigned long but what you have mentioned has given me an idea to try when I can next get back to it. MBedder, I suggest you try to get out more to develop your social skills, it will come in useful when you get older. |
|
|
|
不要射杀信使。让每个人下载一个可能被感染的DOC文件不是一个好主意,特别是如果没有必要的话。可能是一个带有DOC扩展名的纯文本文件,然后不分配扩展。我自己不会试图找出,而是跳过这个帖子,这意味着更少的人会读你的代码。我错过了你的帖子标题“ITOA的奇怪行为”和冗长的解释之间的关系。你的算法可能在你的源代码中变得明显。
以上来自于百度翻译 以下为原文 Don't shoot the messenger. It's not a good idea to have everyone download a possibly infected .doc file, especially if there is absolutely no need to. May be it's a plain text file with doc extension, then do not assign that extension. I myself would not try to find out, and instead skip the post, which means less people will read your code. I was missing the relation between your post's title "strange behaviour of itoa" and the verbose explanation your algorithm, may be that becomes evident in your source. |
|
|
|
我根本不需要这些,因为我是一个深信不疑的反社会人物——我才63岁。
以上来自于百度翻译 以下为原文 I do not need them at all because I'm a convinced anti-social person Too late - I'm 63 |
|
|
|
OK Mabter,点。如果你把你的情况清楚地告诉我,我早就明白了。我66岁,所以在那里打败你。
以上来自于百度翻译 以下为原文 Ok MBedder, point taken. Had you made your condition clear in your post I would have understood. I am 66 so beat you there. |
|
|
|
我怎么能弄清楚当已经完全清楚的——错误的论坛和doc文件,你认为每个人都乐意打开?
以上来自于百度翻译 以下为原文 How could I make it clear when it's absolutely clear already - wrong forum and the .doc file which you think everybody will be happy to open? |
|
|
|
只有小组成员才能发言,加入小组>>
5243 浏览 9 评论
2035 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3208 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2258 浏览 5 评论
779浏览 1评论
672浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
598浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
680浏览 0评论
578浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 17:07 , Processed in 1.558701 second(s), Total 90, Slave 73 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号