完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
ALL,用指针初始化来面对问题。当我用const unSchar char消息初始化一个指针,并使用这个指针来转换我的数据到LCD和UART(类似于Prtff()语句的语句)。将我的信息打印到LCD/UART。
以上来自于百度翻译 以下为原文 @all, Facing issue with initialization of pointer. when i initialize a pointer with const unsigned char *message, and using this pointer for conversion of to display my data to lcd and uart(something similar to printf() statement). message = "Shivanand"; when i debug this code line, message ptr having only first character into that pointer and i am unable to print my message to lcd /uart.. |
|
相关推荐
19个回答
|
|
|
对不起,你的解释很难跟上。最好是展示你的真实代码,说出你到底做了什么测试,你期望看到什么,以及你看到了什么。
以上来自于百度翻译 以下为原文 Sorry, your explanation is very hard to follow. It would be much better to show your real code, and say what exactly you did to test, what you expected to see, and what you did see. |
|
|
|
|
|
包含和lt;Stry.H.G.T.Hy& Gt;Hy.G.T.L.&G.L.H.& Gt;包括“String .h”const无符号CHAR*消息;γ-PracMaMatch-confg FExtScC= Xt*PrimaMig.confg RSTOSC= ExtOCX-PracMa配置文件WDTE=Office主(空){Metrase=“SHIVA”;同时(1){}调试C时,{ }}γODE,*消息只有“S”,我想用STRCYPY()将整个*消息复制到我的缓冲区;---gt;StrucPy(LCD-Buff,消息);但是它正在发生。
以上来自于百度翻译 以下为原文 #include #include #include #include #include "string.h" const unsigned char *message; #pragma config FEXTOSC = XT #pragma config RSTOSC = EXTOSC #pragma config WDTE = OFF void main(void) { message = "Shiva"; while(1) { } } while debugging this code, *message have only 'S', I want to copy the whole *message to my buffer using strcpy(); --> strcpy(Lcd_Buff,message); But its happening.. |
|
|
|
|
|
你怎么知道的?你会发现写“不做”代码的常见错误,然后不希望编译器扔掉那些没有任何用处的东西。
以上来自于百度翻译 以下为原文 How do you know? You're falling for the common mistake of writing "do nothing" code, then not expecting the compiler to throw away things that don't do anything useful. |
|
|
|
|
|
此外,当编译器对char的指针进行引用时,只能看到1个字符。为了看到整个字符串,指针必须一次一个地沿着字符串递增以得到一个字符。这就是“StrcPy”这样的函数,它们一次处理一个字符直到NU为止。HelHead关于JurrGE的终结
以上来自于百度翻译 以下为原文 Hi Besides any issue with the compiler optimizing code away. When you dereference a pointer to char you only see 1 char. To see the whole string, the pointer must incremented along the string to get one char at a time. This is what functions like "strcpy" do, they handle one char at a time until the null terminator. HIH Best regards Jorge |
|
|
|
|
|
@ JorgeF,是的,你是礼仪,但我面临的问题是*消息=“SHIVAND”,首先它应该有完整的字符串在消息礼仪中使用StrcPy复制?这种类型的铸造是必需的,因为我的旧固件是这样的。
以上来自于百度翻译 以下为原文 @JorgeF, Yes you are rite, But the issue i am facing is that *message = "Shivanand", first it should have that complete string in message rite to copy using strcpy? this type casting is required because my old firmwares are like that.. |
|
|
|
|
|
我怀疑你误解了你的调试。请给我们演示真正的代码。
以上来自于百度翻译 以下为原文 I suspect you are misinterpreting your debugging. Please show us the REAL code that is mi***ehaving. |
|
|
|
|
|
如果这是XC8 const字符串和k系列PIC18S,这是NVMRG问题吗?它会影响这张照片吗?
以上来自于百度翻译 以下为原文 If this is XC8 const strings and K series pic18s is this the NVMREG issue? Does it affect this PIC? |
|
|
|
|
|
答对了。我应该注意到提到“K40”。
以上来自于百度翻译 以下为原文 Bingo. I should have noticed the mention of "K40". |
|
|
|
|
|
在编译器文档或FULUM中查找“NVMeRG勘误表”。
以上来自于百度翻译 以下为原文 Look up "NVMREG Errata" in the compiler docs or the fourum. |
|
|
|
|
|
感谢答复,我修正了NVMeRG,正如我在HTTP://www. McCHIP.COM/FUMMS/M9875 71.ASPXI所看到的那样,它仍然面临这个问题的指针。
以上来自于百度翻译 以下为原文 Thanks for the replies, I fixed that NVMREG as i saw in http://www.microchip.com/forums/m987571.aspx I made it still facing that issue of pointer.. |
|
|
|
|
|
谢谢你的回复。我的要求是,我想连接我的LCD显示器,我将把我的DAT写入指针LyMeMease=“Strug1”;消息=“StrugABC”;消息=“Strsixz”;这些消息将使用SrcPy复制到一个数组中,然后写入LCD或UART。我希望问题得到理解。
以上来自于百度翻译 以下为原文 Thanks for your replies.. My requirement is i want to interface my lcd display where i will be writting my dat to pointer like message = "String1"; message = "Stringabc"; message = "Stringxyz"; these message will be copied to one of array using strcpy and then write to lcd or UART.. I hope problem is understood.. |
|
|
|
|
|
好主意,设置一次常量,没有2点Copi.Cistar char HW=“Hlleo Wlrod”的意义;为什么当你可以提供一个指针时,将一个常量复制到LCD的一些缓冲区中显示。
以上来自于百度翻译 以下为原文 Good idea to setup your constants once, there is no point in having 2 copies. const char *hw="Hlleo Wlrod"; Why copy a constant to some buffer for the lcd to display when you can provide a pointer. lcd_puts(Message,0,1,hw); lcd_sendtofront(Message); lcd_refresh(); tdel(5*2);//2 sec lcd_sendtoback(Message); lcd_refresh(); |
|
|
|
|
|
@ GOT2015CONST CHAR*HW=“Hlleo Wlrod”;这个*W将在调试时只有H,并且该指针不分配内存,因为地址将是这样的……Exo HW ADDR是0x020,对于“H”另一个变量,一些X将从0x00 21开始,那么我该如何复制或处理它?
以上来自于百度翻译 以下为原文 @ Gort2015 const char *hw="Hlleo Wlrod"; this *hw will be having only H while debugging, and that pointer is not allocating memory itseems because address will be like this... ex For hw addr is 0x0020 for 'H' another variable some x will start from 0x0021 then how shall i copy or handle it? |
|
|
|
|
|
读豪尔赫的POST 5,编辑地址>0x20包含“h”,地址0x21包含“L”,地址0x22包含“L”等。
以上来自于百度翻译 以下为原文 Read Jorge's Post #5. |
|
|
|
|
|
如果你想要有一个消息表,并且能够通过索引选择其中一个,你需要有一个带有每个指针指针的辅助数组。类似的://----消息:无符号char *MSG0=“消息0”;未签名的char MSG1=“消息1”;未签名的char *MSG2=“消息2”。无符号char *MSG3=“消息3”;未签名的CHAR*消息[] = {MSG0,MSG1,MSG2,MSG3};然后您可以做一些类似于StrucPy(命运,消息[X]);免责声明:上面的示例代码是通用的“C”,它不考虑ROM/RAM指针的细节和XC编译器的访问。你必须调整这些细节。很抱歉,我现在不能更具体,但是我没有手头的个人代码来作为更好的例子。
以上来自于百度翻译 以下为原文 Hi If you want to have a table of messages and be able to select one of them by index, you will need to have an auxiliary array with the pointers to each message. Something like: // ---- Messages --- unsigned char * msg0 = "Message 0"; unsigned char * msg1 = "Message 1"; unsigned char * msg2 = "Message 2"; unsigned char * msg3 = "Message 3"; unsigned char * messages[] = {msg0, msg1, msg2, msg3}; Then you can do something like strcpy(destiny, messages[x]); Disclaimer: The sample code above is generic 'C', it doesn't take into account specifics on ROM/RAM pointers and access of the XC compiler. You have to adjust those details. I'm sorry I can't be more specific at the moment but I don't any personal code at hand to use for a better example. HIH Best regards Jorge |
|
|
|
|
|
我认为它更像:/const un签署char *MSG0=“消息0”;CistunChar Car *MSG1=“消息1”;CistunSchar Car *MSG2=“消息2”;SconunSchar Car *MSG3=“消息3”;SconunSchar char *消息[] = {MSG0,MSG1,MSG2,MSG3};这一切都在Flash中。
以上来自于百度翻译 以下为原文 I think it is more like: // ---- Messages --- const unsigned char * msg0 = "Message 0"; const unsigned char * msg1 = "Message 1"; const unsigned char * msg2 = "Message 2"; const unsigned char * msg3 = "Message 3"; const unsigned char * messages[] = {msg0, msg1, msg2, msg3}; That puts everything in flash |
|
|
|
|
|
是的,正如你所说的那样,我正在努力工作,但是那个未签名的CHAR*MSG0=“消息0”;它的数据只有M不完整的消息0……这可能是编译器还是硅问题?我不知道挣扎的命运来解决这个问题。一个更多的暗示相同的LCD库是工作良好的其他微控制器,如PIC18F452,PIC18F4620,PIC18F46K80等。
以上来自于百度翻译 以下为原文 yes as you said in that way i am trying to work, but that unsigned char * msg0 = "Message 0"; its having data of only M not complete Message 0... Is that might be compiler or silicon issue? I don't know struggling lot to fix this issue.. one more hint the same lcd library is working fine for other microcontrollers like PIC18f452, pic18f4620,pic18f46k80 etc.. |
|
|
|
|
|
不,如果它有一个它就有整个东西。你担心MPLab没有给你看吗?MSG0不是字符串。它是字符串的地址。不是复制品。C就是这样工作的。如果你想看到字符串点击表,将有一个指针指向字符串的选项。将其配置为监视变量。用你的代码前进,你会发现它是有效的。
以上来自于百度翻译 以下为原文 No if it has one it has the whole thing. Are you concerned that MPLab is not showing it to you? Msg0 is not the string. It is the address of the string. Not a copy of it. That is how C works. If you want to see the string click on the watch and there will be an option for pointer to a string. Configure it for the watched variable. Move forward with your code, you will find it works. |
|
|
|
|
|
这浪费了RAM,每个字符串都有一个不必要的中间指针,它还把“消息”数组放在RAM中而不是ROM.,字符串是“char”,而不是“unChar char”。尝试
以上来自于百度翻译 以下为原文 const unsigned char * msg0 = "Message 0"; const unsigned char * msg1 = "Message 1"; const unsigned char * msg2 = "Message 2"; const unsigned char * msg3 = "Message 3"; const unsigned char * messages[] = {msg0, msg1, msg2, msg3};This wastes RAM with an unnecessary intermediate pointer for each string, and it also puts the "messages" array in RAM instead of ROM. And strings are "char", not "unsigned char". Tryconst char * const messages[] = { "Message 0", "Message 1", "Message 2", "Message 3"}; |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
485 浏览 0 评论
5806 浏览 9 评论
2346 浏览 8 评论
2234 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3540 浏览 3 评论
1145浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1114浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
883浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
489浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-9 15:17 , Processed in 1.432076 second(s), Total 109, Slave 91 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1612