完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
嗨,我的代码遇到了一个问题。有一个奇怪的行为……我在maquinaTarefaRede和maquinaEnvioReceb.o485变量下面有原始代码,它们是枚举,对于我所有的代码都工作良好。我知道它们的值大于零。但是在statusWatchdog[1]和statusWatchdog[2]中,两者都显示0(零)值。如果我这样做(下面),statusWatchdog将显示正确的值。如果我使用本地变量这样做(下面)也能正常工作。如果我使用PIN调试来测试maquinaTarefaRede和maquinaEnvioReceb.o485,例如,PIN问题似乎是来自外部ENUM的statusWatchdog的属性……但是如果测试ENUM,他不是零。你能告诉我做错了什么吗?提前感谢
以上来自于百度翻译 以下为原文 Hi, I am facing a problem with my code. There is a strange behaviour... I have the original code below void PrecisaReiniciar_B(void) { extern ENUM_ESTADO_MAQUINA_TAREFA_REDE maquinaTarefaRede; extern ENUM_ESTADO_MAQUINA_ENVIO_RECEBIMENTO maquinaEnvioRecebimentoRS485; statusWatchdog[0] = 2; statusWatchdog[1] = maquinaTarefaRede; statusWatchdog[2] = maquinaEnvioRecebimentoRS485; enviaDadosDebug = TRUE; } The maquinaTarefaRede and maquinaEnvioRecebimento485 variables are enumerations and works fine for all my code. I know that they have a value greater than zero. But in the statusWatchdog[1] and statusWatchdog[2] shows 0 (zero) value for both. If I do this (below), the statusWatchdog show the correct values void PrecisaReiniciar_B(void) { extern ENUM_ESTADO_MAQUINA_TAREFA_REDE maquinaTarefaRede; extern ENUM_ESTADO_MAQUINA_ENVIO_RECEBIMENTO maquinaEnvioRecebimentoRS485; statusWatchdog[0] = 2; statusWatchdog[1] = 0x55; statusWatchdog[2] = 0xAA; enviaDadosDebug = TRUE; } If I do this (below) with a local variable works fine also. void PrecisaReiniciar_B(void) { typedef enum{ STATE1 = 1u, STATE2, STATE3 } enumTeste; extern ENUM_ESTADO_MAQUINA_TAREFA_REDE maquinaTarefaRede; extern ENUM_ESTADO_MAQUINA_ENVIO_RECEBIMENTO maquinaEnvioRecebimentoRS485; enumTeste auxTeste; auxTeste = STATE3; statusWatchdog[0] = 2; statusWatchdog[1] = auxTeste; auxTeste = STATE2; statusWatchdog[2] = auxTeste; enviaDadosDebug = TRUE; } If I test maquinaTarefaRede and maquinaEnvioRecebimento485 with PIN debug for example, the PIN always invert the direction void PrecisaReiniciar_B(void) { extern ENUM_ESTADO_MAQUINA_TAREFA_REDE maquinaTarefaRede; extern ENUM_ESTADO_MAQUINA_ENVIO_RECEBIMENTO maquinaEnvioRecebimentoRS485; if (maquinaTarefaRede != 0) { PIN_DEBUG ^= 1; //always enter here } if (maquinaEnvioRecebimentoRS485 != 0) { PIN_DEBUG_2 ^= 1; //always enter here } statusWatchdog[0] = 2; statusWatchdog[1] = maquinaTarefaRede; statusWatchdog[2] = maquinaEnvioRecebimentoRS485; enviaDadosDebug = TRUE; } The problem seems to be the attribution to statusWatchdog from a extern ENUM...but If a test the ENUM he is not zero. Can you tell what I am doing wrong?? Thanks in advance |
|
相关推荐
19个回答
|
|
|
什么是可变状态看门狗的声明?
以上来自于百度翻译 以下为原文 What is the declaration of the variable statusWatchdog? |
|
|
|
|
|
编译过程中你得到的警告是什么?(我绝对肯定你会得到警告,除非你把它们完全关闭。)
以上来自于百度翻译 以下为原文 What are the warnings you're getting during compile ? (I'm absolutely sure you get warnings unless you switched them off completely.) |
|
|
|
|
|
为什么外部函数声明在函数体内部?他们通常是在一个头。
以上来自于百度翻译 以下为原文 Why are the extern declarations inside the function body? They would normally be in a header. |
|
|
|
|
|
大家好,为了快速回复,杰克,statusWatchdog是一个局部变量,声明为持久性BYTE statusWatchdog[MAX_STATUS_WATCHDOG]u at(0x3E6);但是我已经尝试了BYTE statusWatchdog[MAX_STATUS_WATCHDOG]u at(0x3E6)和BYTE statusWatchdog[MAX_STATUS_WATCHDOG];对于alldu0001Thea的结果相同对于这个例程和相关变量没有警告……我只是编译并附加了结果,如果您希望seehttps://dl.dropboxusercontent.com/u/32944129/processCompilation.zipcrosland,那么您是对的,但是我已经尝试过这种方法。我的代码的快照是我最后一次试探,抱歉。
以上来自于百度翻译 以下为原文 Hi guys, tks for your fast reply Jack, the statusWatchdog is a local variable declared as persistent BYTE statusWatchdog[MAX_STATUS_WATCHDOG] __at(0x3E6); but I have tried BYTE statusWatchdog[MAX_STATUS_WATCHDOG] __at(0x3E6); and BYTE statusWatchdog[MAX_STATUS_WATCHDOG]; same result for all du0000001 The are no warnings for this routine and the related variables... I just compiled now and attached the result if you want to see https://dl.dropboxusercontent.com/u/32944129/processCompilation.zip crosland, You are right, but I already tried this approach. This snapshot of my code was my last tentative, sorry. Tks again for your help until now |
|
|
|
|
|
为什么要在绝对地址上声明一个局部变量?
以上来自于百度翻译 以下为原文 Why are you declaring a LOCAL variable at an absolute address? |
|
|
|
|
|
由于我既不知道文件名,也不知道代码的当前状态,所以检查起来有点困难。无论如何:除非您做了一些“不明智”的事情,否则应该有两个类型冲突警告,用于向BYTEstatusWatchdog[]评估枚举值,这通常很容易被类型cas克服。用(字节)显示枚举值
以上来自于百度翻译 以下为原文 As I know neither the file name nor the current state of your code, it is a bit difficult to check. Anyway: unless you did something "not wise", there should be TWO type conflict warnings regarding the assessment of enum values to the BYTE statusWatchdog[]. Which is normally easily overcome by type casting the enum values with (BYTE) |
|
|
|
|
|
你好,杰克和DUO010000。我的回答是,我尝试了不同的方法,同样的结果。这是我迄今为止的最后一次尝试。但原因是……我有一个引导加载程序,可以清除启动代码上的RAM。但是它测试了看门狗位,并且如果出现的看门狗比引导加载程序不能清理这个保留区域。在我的主要应用程序中,我设置了一些值来跟踪应用程序可能中断的位置。如果中断,我通过串行后送数组DU000 00 01,这是不清楚我。你认为这是宣言的问题吗?在这种情况下,我可以将每个枚举更改为一个简单的字节来进行测试。我会这样做,然后返回结果。
以上来自于百度翻译 以下为原文 Hi jack and du000001. My answer Jack, I tried differents approachs, same result. This was my last tentative so far. But the reason is.... I have a bootloader that clear RAM on the start-up code. But it test watchdog bit and if ocurred watchdog than the bootloader doesn´t clean this reserved area. In my main application I put some values to track where my application could break. If breaks I send the array through the serial afterwards. du00000001, It´s not clear for me. Do you think it´s a matter of declaration? In this case I can change every enum to a simple byte just to test. I will do this and return with the results. Tks again |
|
|
|
|
|
嗨,我能看到一些亮光吗?你的枚举不是字节而是单词??????????对于它们来说,低字节是否为零,这是拷贝到目的字节的原因吗??????????
以上来自于百度翻译 以下为原文 Hi - can I see some light shining ? Your enums are NOT bytes but words ??????? Could it be the low byte is ZERO for them and this is what's copies to the destination bytes ??????? |
|
|
|
|
|
MMMMM,一个字节或一个词中的“1”总是在“第一个字节”中,除非改变了字节数。
以上来自于百度翻译 以下为原文 Mmmmm, a "1" in a byte or in a word will always be in "first byte" - unless endianness is changed .. |
|
|
|
|
|
你好,CinziaG,你可以创建这样的枚举:(不一定要编译——只是为了给人一种感觉)。现在我们有了一个需要16位存储的枚举。当把这些枚举值写到字节位置时,在50%的情况下,这个字节只占零。而且我觉得tpicon正在做类似的事情。@tpicon:忘记提及:是——让枚举只占字节,然后再试一次!!!!
以上来自于百度翻译 以下为原文 Hi CinziaG, you can create enums like this: enum { eBit15 = 0x8000, eBit14 = 0x4000, eBit13 = 0x2000, eBit12 = 0x1000, .... eBit02 = 0x0004, eBit01 = 0x0002, eBit00 = 0x0001 }; (not necessarily compiling - just to give the feeling). Now we've got an enum that requires 16 bits of storage. When writing these enum values to a byte location, in 50 % of all cases this byte will hold only a zero. And I feel that tpicon is doing exactly something like that. @tpicon: Forgot to mention: YES - make the enums occupy only bytes and try again!!! |
|
|
|
|
|
噢,是的,我当然知道,但我的意思是这不是这个帖子中出现的情况。我们等一下……
以上来自于百度翻译 以下为原文 Oh yes sure I know Let's wait... |
|
|
|
|
|
发布所有测试用例的解体。很容易看到这个问题。
以上来自于百度翻译 以下为原文 Post the disassembly of all your test cases. It'll be easy to see the problem. |
|
|
|
|
|
你好,du0000001,CinziaG和NothGuy非常想帮助我。du0000001,这些是我的枚举,这是我的枚举ESTADO_AGUARDA_FIM_ENVIO_断裂}ENM_ENVIO_ENVIO_破坏}ENUM_EST_ESTADO_ESTAD_ESTADO_OUVINDO_A_RE_A_REDE=0u,ESTADO_RECEBE_RECEBE_ENDEDEDEDEDEDEDEDERERERERERERE_DEDEDEDEDEDEDEDEDEDEDEDEDEDERERERERERERERERE_ENDEDEREREREREREREREBE_NUMERERERO_BYTES_RS485,ESTADO_RECEBEBE_BYTE_BYTES_RS485,ESTADO_READO_RECEBE_BYTE_BYTES_RS485,ESTENVIA_BYTE_1_RESPOSTA_POLLING,ESTADO_ENVIA_BYTE_2_RESPOSTA_ESTADO_LIBERA_LINHA_LINHA_RESPOPOSTA_极化,ESTADO_VERIFICA_LINHA_ENVIA_ENVIA_极化,ESTADO_ENVIA_ENVIA_BYTE_BYTE_2_ENVIA_极化,ESTADO_LIBERA_LIBERA_LINHA_ENHA_ENHA_ENVIA_极化,ESTADO_AGUARDA_PRI_PRI_ENVIA_PRI_ENVIA_极化,ESTADO_AAGUARDA_PRI_PRI_ENVIA_PRI_ENVIA_极化_极化,ESTADO_AAAAGUARDA_PRI_PRI_ENVIPOSTA_POLLING,ESTADO_VERIFICA_LINHA_ENVIA_COMANDO,ESTADO_VERIFICA_ENDERE_ENDERECO_DEDEDEINO_ENVIA_COMANDO,ESTADO_VERIFIFICA_NNNNNNNNNNNNBYTES_ENVIA_COMANDO,ESTADO_VER_VERIFIFIFIFICA_ENDEDERERERERERE_ENDEDEDEDEDERERECO_DEDEDEDEDEDEDEDERECOENVIA_ENINVIA_ENVIA_COMANANDO,ESTADO_AGUARDA_AAAGUARDA_RESPOSTA_RESPOSTA_COMANSTA_COMANSTA_COMANDO,ESTADO_PROPROPROPRO_PROSTA_COMANSTA_COMANSTA XIMO_COMANDO,ESTADO_ENVIA_BYTE_1_RESPOSTA_OK,ESTADO_ENVIA_BYTE_2_RESPOSTA_OK,ESTADO_LIBERA_LINHA_RESPOSTA_OK,ESTADO_VERIFICA_LINHA_ENVIA_BREAK,ESTADO_POLARIZA_LINHA_ENVIA_BREAK,ESTADO_LIBERA_LINHA_ENVIA_BREAK}ENUM_ESTADO_MAQUINA_ENVIO_RECEBIMENTO,因此我不认为这是我的问题。所有的值都是字节类型。使用字节替代EnUM的结果是相同的…如果我只是测试变量是否与0不同,它返回true,但是当我复制值时,它似乎变为零(0)。它“固定”了这个问题,但我不明白为什么…我的变量MaqaNeNeViReCeimimTrrss48和MaqTaTaReaFrEDE并没有在启动代码中初始化。我知道我应该初始化(我的错误),但是为什么会这样呢?为了使思路清晰,我的主要循环是:如果某些东西不是预期的,函数PrimeSeRixARIXB()返回true。因此,我做了一个温暖的重新启动,打破了循环,并发送到另一个循环,你可以看到,初始化所有变量在我的程序,除了STATUS看门狗,持有重要的价值为我的调试。在我看来,在SimeSeReNICIARARB中,AtditStastStaseWestRe狗[1 ] = MaqTaTaRealDeaStutuStWistBoe[9]=MaqNeaNeViReCeBeimiTrrsSt55的工作原理在我开始初始化两个枚举时都很好。如果不是,statusWatchdog变为0(0),除非我输入一个字面值,比如this statusWatchdog[1]=0x55;statusWatchdog[2]=0xAA;在这种情况下,值仍然是0x55和0xAA。问题只发生在属性变量并且不在启动时初始化这些变量时。看起来,这个属性成了一个指针。我知道我的声明听起来很奇怪,但是我不能理解目前为止发生了什么。我在这两种情况下都查看了拆卸过程。他们是平等的。你能告诉我一些测试来理解这种行为吗?或者如果还不清楚,你想要什么样的信息?再次为你的时间!
以上来自于百度翻译 以下为原文 Hi du0000001, CinziaG and NothGuy tks very much for help me. du0000001, these are my enums typedef enum { ESTADO_SELECIONA_TAREFA = 0u, ESTADO_RESPONDE_POLLING, ESTADO_AGUARDA_FIM_ENVIO_RESPOSTA_POLLING, ESTADO_ENVIA_COMANDO, ESTADO_AGUARDA_FIM_ENVIO_ENVIA_COMANDO, ESTADO_ENVIA_BREAK, ESTADO_AGUARDA_FIM_ENVIO_BREAK }ENUM_ESTADO_MAQUINA_TAREFA_REDE; typedef enum { ESTADO_OUVINDO_A_REDE = 0u, ESTADO_RECEBE_ENDERECO_DESTINO_RS485, ESTADO_RECEBE_NUMERO_BYTES_RS485, ESTADO_RECEBE_BYTES_RS485, ESTADO_VERIFICA_LINHA_RESPOSTA_POLLING, ESTADO_ENVIA_BYTE_1_RESPOSTA_POLLING, ESTADO_ENVIA_BYTE_2_RESPOSTA_POLLING, ESTADO_LIBERA_LINHA_RESPOSTA_POLLING, ESTADO_VERIFICA_LINHA_ENVIA_POLLING, ESTADO_ENVIA_BYTE_1_ENVIA_POLLING, ESTADO_ENVIA_BYTE_2_ENVIA_POLLING, ESTADO_LIBERA_LINHA_ENVIA_POLLING, ESTADO_AGUARDA_PRIMBYTE_ENVIA_POLLING, ESTADO_AGUARDA_RESPOSTA_POLLING, ESTADO_VERIFICA_LINHA_ENVIA_COMANDO, ESTADO_VERIFICA_ENDERECO_DESTINO_ENVIA_COMANDO, ESTADO_VERIFICA_NUMERO_BYTES_ENVIA_COMANDO, ESTADO_ENVIA_BYTES_ENVIA_COMANDO, ESTADO_LIBERA_LINHA_ENVIA_COMANDO, ESTADO_AGUARDA_PRIMBYTE_ENVIA_COMANDO, ESTADO_AGUARDA_RESPOSTA_COMANDO, ESTADO_PROXIMO_COMANDO, ESTADO_ENVIA_BYTE_1_RESPOSTA_OK, ESTADO_ENVIA_BYTE_2_RESPOSTA_OK, ESTADO_LIBERA_LINHA_RESPOSTA_OK, ESTADO_VERIFICA_LINHA_ENVIA_BREAK, ESTADO_POLARIZA_LINHA_ENVIA_BREAK, ESTADO_LIBERA_LINHA_ENVIA_BREAK }ENUM_ESTADO_MAQUINA_ENVIO_RECEBIMENTO; So I don´t believe it is the problem in my case. All values are BYTE type. The result using BYTE instead ENUM was the same...if I just test if my variable is different from zero it returns TRUE, but when I copy the value it seems that become zero (0). I did another test with a interesting result. It "fixed" the problem but I can´t understand why... My variables maquinaEnvioRecebimentoRS485 and maquinaTarefaRede wasn´t initialized at the start-up code. I know that I should initialize (my fault), but why this interfere?? Just to make thinks clear My main loop is: void main(void) { InicializacaoVariaveisWatchdog_B(); VerificaWatchdogPorTravamento_B(); while (1) { Inicializacao_B(); for(;;) { CLRWDT(); VerificaFlags_B(); if (PrecisaReiniciar_B()) { break; } } } } The function PrecisaReiniciar_B() return TRUE if something isn´t as expected. So I made a kind of warm reboot, breaking the loop and send to a another loop as you can see, initializing all variables in my program, except statusWatchdog that holds important values for my debug. It seems to me that the attributions statusWatchdog[1] = maquinaTarefaRede statusWatchdog[2] = maquinaEnvioRecebimentoRS485 in the PrecisaReiniciar_B works fine just when I initialize both enumerations in the beginning. If I don´t, the statusWatchdog become zero (0), except if I put a literal value, like this statusWatchdog[1] = 0x55; statusWatchdog[2] = 0xAA; In this case, the values still 0x55 and 0xAA. The problem occurs only when attribute the variables and don´t initialize this variables on the start-up. Looks like the attribution become a pointer. I know my statement sounds weird, but I can´t understand what is happening so far. I´ve looked the disassembly in both cases. They are equal. Can you tell me some tests to do to understand this behavior?? Or if was not clear, what kind of information do you want? Tks again for your time! |
|
|
|
|
|
神圣的狗屎,一切都可以,但是“U”后缀可能会迫使UntEnUM类型。删除“u”(在枚举中不是必需的)并重试。尽管剩余的代码在某种程度上也是“不祥的”……无论如何:如果变量的初始化解决了问题,我会坚持这样做,因为这是“标准编码风格”。(在某些情况下,需要未初始化的变量,但在大多数情况下,这被认为是“废料编程”。)
以上来自于百度翻译 以下为原文 Holy shit, everything could be fine, but the 'u' suffix might force a uint enum type. Delete the 'u's (not necessary in enums) and try again. Though the remaining code is also 'ominous' to some extend ... Anyway: if initializing of the variables solves the problem, I'd stick to that as this is "standard coding style". (There are some cases where uninitialized variables are required, but in most cases this is regarded 'scrap programming'.) Regards |
|
|
|
|
|
也许,但是如果使用.LST文件可能会更容易。
以上来自于百度翻译 以下为原文 Perhaps, but it may be easier if one uses the .LST file. |
|
|
|
|
|
如果你不初始化这些变量,你期望它做什么?
以上来自于百度翻译 以下为原文 What do you expect it to do if you don't initialize these variables? |
|
|
|
|
|
嗨,TPICON,你如何定义来源中的枚举?如果碰巧使用PIC18FXXK40芯片并用一些非零值对其进行初始化,由于错误,除非使用链接器选项errata=+NVMREG和XC8 v1.40,否则无法正确初始化它。
以上来自于百度翻译 以下为原文 hi tpicon, how do you define the ENUM_ESTADO_MAQUINA_TAREFA_REDE maquinaTarefaRede in the source? if you happen to use the PIC18FXXK40 chip and initialize it with some nonzero value, due to the errata, it will not be initialized correctly unless you use linker option errata=+NVMREG with XC8 v1.40. |
|
|
|
|
|
大家好,我不在办公室,不能做测试…明天我会回来,做测试,并张贴结果。
以上来自于百度翻译 以下为原文 Hi guys, I´m out of the office and couldn´t do the tests...Tomorrow I will return, do the tests and posts de results tks |
|
|
|
|
|
大家好,000001,谢谢大家的建议,我不知道把“u”放入枚举中是没有必要的。但是结果是相等的:(MPL我用2片LST文件附加一个ZIP文件。lst是当我初始化变量时,而notWork.lst是当我不初始化并且得到奇怪的行为rhttps://dl.dropboxusercon.../32944129/lstFiles.zipNorthGuy时,我意识到不初始化这两个变量是一个错误,但是因为在我的状态机中,标准值是0,我的应用程序l工程运作良好。如果这些变量初始化错误,什么都不会起作用。所以我冒着风险不交流,但事实并非如此。当我输入例程并获得奇怪的行为时,我的代码已经工作了一段时间……所以初始化不是通信的问题。timijk,我在*.h文件中定义了枚举,并在*.c文件asENUM_ESTADO_MAQUINA_TAREFA_REDE maquinaTarefaRede中声明变量;使用PIC16F1939只是提醒您,我的应用程序现在正在工作,但我想理解为什么没有初始化会导致这种行为。再次感谢您的耐心
以上来自于百度翻译 以下为原文 Hello everybody du000001, tks for your advice, I didn't´t know that wasn´t necessary to put 'u' in the enums. But the result is equal :-( mpl I´m attaching a zip file with 2 pieces of LST files. The work.lst is when I initialize the variables and the notWork.lst is when I don´t and got the strange behavior https://dl.dropboxusercon.../32944129/lstFiles.zip NorthGuy, I realize that was a mistake not initializing both variables, but because the standard value is 0 in my state machine, my applications works fine. If this variables were initialized wrong, nothing would work. So I was taking the risk to not communicate, but it was not the case. When I enter in the routine and got the strange behavior my code is already working for a while...so didn´t initialize wasn´t the problem for communication. timijk, I defined the enum in the *.h file and declare the variable in *.c file as ENUM_ESTADO_MAQUINA_TAREFA_REDE maquinaTarefaRede; and I´m working with PIC16F1939 Just to remind you, my application is working now, but I would like to understand why didn´t initialize was leading to that behavior. Tks again for your patience |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475 浏览 0 评论
5795 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1126浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1098浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-3 06:58 , Processed in 1.024460 second(s), Total 111, Slave 93 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
4471