完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
亲爱的各位,我有一些困难来检查MPLAB和谐中一些变量的值。所有变量的值为“null”或“0”。我不明白怎么回事。请检查以下状态:情况APP_UART_STATE_READ_MESSAGE_PWM_2:{if(!DRV_USART_接收器_在接收到运输返回{appUart数据.rxt数据rx_rx_rx_rx_rx_rx_rx_数据编号_编号_编号_pwm2_ppwm2_pwm2.{{{appUart数据_rx_rx_rx_rx_xxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxx_pwm2.{appUVVVVVVTDataDataDatatData.usartData.usartData.usartDatausarartDatausartHandtHand手手柄处理程序处理程序处理程序)));//读取接收字节如果(appUsks();APP_Ini如果((appUartData.rx_xxx_tex_文本_pwm2>((appUartData.rx_tex_文本_pwm2>='0’”””””)&;(appUartData.rx_rx_textData_xxxxxxxxxxxxxxxxxxxxx_appUUartData.appUartData.appUartData_UART_UART_UART_STARTRTRTRTRTRTRTAT_STATE_STATE_STATE_STA_STATE_STATE_STATE_INIT;APP_APP_APP_APP_APP_APP_APP_APP_您需要提供范围检查ppUartData.state=APP_UART_STATE_SEND_READ_MESSAGE_PWM_2;}.{appUartData.state=APP_UART_STATE_READ_ERROR;//非数字条目}break;}NOTES:A)该状态允许通过USART读取字节并将其转换为整数;B)该状态正在运行而appUartData.rx_rx_编号是以以下状态打印的:情况APP_UART_STATE_SEND_READ_MESSAGE_PWM_2:{//处理编号if(!(DRV_USART_USART_TRATRANSFER_TRANSFER_TRANSFER_TRANSFER_TRANSFER_TATATE_TRATRATRA_FU_FU_FU_FU_FU_FU_TRANSMIT_FU_FU_FU_TRANSTE_TRASTSTSTSTSTTE_TRATRANSMIT_TRATE_TRATE_TRANSMIT_FU_FU_FU_FU_FU_FU_FU_FU_DRV_USART_USART_USARTRTRTRTRTRT_USartData.usartHand.usartHand.usartData.usartHand.usartHand,appUartData.usartData.rx__STATE_R我开始了“App.c”函数的AppyTasks-()和AppMixIrimalIZE()。我还试图给appUartData.rx_number_pwm2=100强加一个值,但是这个值在“0”中(请查看附件)。谁能帮我理解出什么问题吗?谢谢您
以上来自于百度翻译 以下为原文 Dear all, I have having some difficulties to check the value of some variables in MPLAB HARMony. All the variables are with the value "NULL" or "0". I don't understand what is going wrong. Please check the following state: case APP_UART_STATE_READ_MESSAGE_PWM_2: { if (!DRV_USART_ReceiverBufferIsEmpty(appUartData.usartHandle)) { appUartData.rx_text_pwm2 = DRV_USART_ReadByte(appUartData.usartHandle); // Read received byte if (appUartData.rx_text_pwm2 == 'r') // go to next state on receipt of a carriage return { appUartData.rx_number_pwm2 = 100; APP_Tasks(); APP_Initialize(); appUartData.state = APP_UART_STATE_INIT; } else if ((appUartData.rx_text_pwm2 >= '0') && (appUartData.rx_text_pwm2 <= '9')) // make sure it's a number { appUartData.rx_number = (appUartData.rx_number * 10) + appUartData.rx_text_pwm2; // you'll need to provide range checking appUartData.state = APP_UART_STATE_SEND_READ_MESSAGE_PWM_2; } else { appUartData.state = APP_UART_STATE_READ_ERROR; // non-numeric entry } } break; } NOTES: A) This state allows the Reading bytes through USART and convert to an integer; B) This state it is running without errors and the appUartData.rx_number it is printed in the following state: case APP_UART_STATE_SEND_READ_MESSAGE_PWM_2: { // process the number if (!(DRV_USART_TRANSFER_STATUS_TRANSMIT_FULL & DRV_USART_TransferStatus(appUartData.usartHandle))) { DRV_USART_WriteByte(appUartData.usartHandle, appUartData.rx_number); } appUartData.state = APP_UART_STATE_READ_MESSAGE_INIT_PWM_2; // prepare for next message break; } C) In the state APP_UART_STATE_READ_MESSAGE_PWM_2, I started the APP_Tasks() and APP_Initialize() of the "app.c" function. I also tried to impose a value to appUartData.rx_number_pwm2 = 100, but this value it is in "0" (please check in attachment). Can anyone help me to understand what is going wrong? thank you Attached Image(s) |
|
相关推荐
6个回答
|
|
如果此变量从未实际读取过您的代码,那么优化编译器将丢弃它。如果您添加了代码来实际使用该变量,那么它将被填充。您可以通过在声明该变量时添加“volatile”属性来防止这种情况的发生。
以上来自于百度翻译 以下为原文 If this variable is never actually read again your code, then the optimising compiler will discard it. If you added code to actually use the variable, then it would get populated. You can prevent this happening by adding the "volatile" attribute when you declare the variable. |
|
|
|
每次收到“r”时,调用AppyTasks-()和AppInIrimalIZE()似乎很不寻常。通常,在程序的开头附近调用APP_Initialize()一次,在主循环中调用APP_Tasks()。你确信你的变量不是在AppInILLIZIZE()中重新初始化的吗?我注意到您的代码还有几个其他问题。我已经做了一些修改:
以上来自于百度翻译 以下为原文 It seems unusual to call APP_Tasks() and APP_Initialize() every time you receive a 'r'. Typically, APP_Initialize() is called once near the beginning of your program and APP_Tasks() is called in your main loop. Are you sure that all your variables aren't getting reinitialized in APP_Initialize()? I noticed several other issues with your code. I've made some corrections: case APP_UART_STATE_READ_MESSAGE_PWM_2: if (!DRV_USART_ReceiverBufferIsEmpty(appUartData.usartHandle)) { appUartData.rx_text_pwm2 = DRV_USART_ReadByte(appUartData.usartHandle); // Read received byte if (appUartData.rx_text_pwm2 == 'r') // go to next state on receipt of a carriage return { // now you have received the entire number appUartData.state = APP_UART_STATE_SEND_READ_MESSAGE_PWM_2; } else if ((appUartData.rx_text_pwm2 >= '0') && (appUartData.rx_text_pwm2 <= '9')) // make sure it's a number { // convert ASCII to binary appUartData.rx_number = (appUartData.rx_number * 10) + (appUartData.rx_text_pwm2 - '0'); // you'll need to provide range checking // stay in same state to get next character // appUartData.state = APP_UART_STATE_SEND_READ_MESSAGE_PWM_2; } else { appUartData.state = APP_UART_STATE_READ_ERROR; // non-numeric entry } } break; case APP_UART_STATE_SEND_READ_MESSAGE_PWM_2: // process the number if (!(DRV_USART_TRANSFER_STATUS_TRANSMIT_FULL & DRV_USART_TransferStatus(appUartData.usartHandle))) { // can't do this is and be able to read the number on the console. number is binary, not ASCII // DRV_USART_WriteByte(appUartData.usartHandle, appUartData.rx_number); } appUartData.state = APP_UART_STATE_READ_MESSAGE_INIT_PWM_2; // prepare for next message break; |
|
|
|
请使用代码标签。否则,很难遵循您的代码。首先,在APP_UART_STATE_READ_MESSAGE_INIT_PWM_2中没有中断。在这种情况下,它没有任何区别,但是除非有真正的需要,否则用中断结束所有状态是很好的编码实践。第二,在接收到“r”后,你将去APPUUARTARSTATEIGITIN。这真的是你的消息处理的地方吗?第三,看起来您试图通过在接收到每个字符之后移动到APP_UART_STATE_SEND_READ_MESSAGE_PWM_2状态来将字符回显到控制台。但是,在该状态下,您将返回到APP_UART_STATE_READ_MESSAGE_INIT_PWM_2状态,该状态正在重新初始化所有内容。我更喜欢使用缓冲区和中断,但是因为此时您没有忙于发送其他任何东西,所以在您接收到每个字符之后,我只需要将字符发回。-比尔
以上来自于百度翻译 以下为原文 Please use code tags. It is difficult to follow your code otherwise. First, there is no break in the case APP_UART_STATE_READ_MESSAGE_INIT_PWM_2. In this case, it won't make any difference but unless there is a real need, it is good coding practice to end all states with a break. Second, you are going to APP_UART_STATE_INIT after receiving the 'r'. Is this really where your message processing is taking place? Third, it looks like you are trying to echo the characters to the console by moving to the APP_UART_STATE_SEND_READ_MESSAGE_PWM_2 state after each character is received. However, in that state, you are moving back to the APP_UART_STATE_READ_MESSAGE_INIT_PWM_2 state which is re-initializing everything. I would prefer to use buffers and interrupts, but since you aren't busy sending anything else at this time, I would just send the character back out after you receive each character. case APP_UART_STATE_READ_MESSAGE_PWM_2: if (!DRV_USART_ReceiverBufferIsEmpty(appUartData.usartHandle)) { appUartData.rx_text_pwm2 = DRV_USART_ReadByte(appUartData.usartHandle); // Read received byte DRV_USART_WriteByte(appUartData.usartHandle, appUartData.rx_text_pwm2); // Echo it back if (appUartData.rx_text_pwm2 == 'r') // go to next state on receipt of a carriage return { appUartData.rx_number_pwm2 = appUartData.rx_number; appUartData.state = APP_UART_STATE_INIT; // is this where you are processing the received data??? } else if ((appUartData.rx_text_pwm2 >= '0') && (appUartData.rx_text_pwm2 <= '9')) // make sure it's a number { appUartData.rx_number = (appUartData.rx_number * 10) + (appUartData.rx_text_pwm2 - '0'); // you'll need to provide range checking // don't go here - stay in this state // appUartData.state = APP_UART_STATE_SEND_READ_MESSAGE_PWM_2; } else { appUartData.state = APP_UART_STATE_READ_ERROR; // non-numeric entry } } break; -Bill |
|
|
|
对于W.Lang:1-关于APP_UART_STATE_READ_MESSAGE_INIT_PWM_2的中断:是的,我忘记复制代码行并越过代码行到这里。你是对的。2——关于在接收到“r”后进入AppuUARTARSTATEYITY。是的,你是对的。正确的状态应该是:现在,我唯一的问题就是把OC1 PWM与我从UART接收的“脉冲宽度”一起工作!现在,“appUartData.rx_number_pwm2=appUartData.rx_number”,所以“appUartData.rx_number_pwm2”拥有脉冲数。案例APP_STATE_INIT:{/*启用OCMP模块并启动计时器*/DRV_OC0_Start();DRV_OC1_Start();DRV_OC1_PulseWidthSet(appUartData.rx_text_pwm2);DRV_TMR0_Start();appData.state=APP_STATE_SERVICE_TASKS;break;}NOTE:OC1创建的PWM仍然没有运行该代码。我担心:状态APP_UART_STATE_READ_MESSAGE_PWM_2属于文件“app_uart.c”,状态APP_STATE_INIT属于文件“app.c”。我能将一个文件中的值(在这个CasePaPARDATABATION.RXXUnByPur.PWM2)从一个文件发送到另一个文件吗?4我如何从我的源代码的复制/过去使用代码标签?非常感谢你。
以上来自于百度翻译 以下为原文 For W. Lang: 1- Regarding the break in the case APP_UART_STATE_READ_MESSAGE_INIT_PWM_2: Yes, I forgot to copy and past the code line to here. You are right. 2- Regarding the going to APP_UART_STATE_INIT after receiving the 'r'. Yes, you are right. The right state should be: APP_STATE_INIT. 3- For now, my unique issue it is to put the OC1 PWM to work with the "pulse width" that I receive from the UART! Right now, the "appUartData.rx_number_pwm2 = appUartData.rx_number", so "appUartData.rx_number_pwm2" owns the pulse number. case APP_STATE_INIT: { /* Enable the OCMP module and start the timer */ DRV_OC0_Start(); DRV_OC1_Start(); DRV_OC1_PulseWidthSet(appUartData.rx_text_pwm2); DRV_TMR0_Start(); appData.state = APP_STATE_SERVICE_TASKS; break; } NOTE: The PWM created by OC1 still not running with this code. I am affraid that: The state APP_UART_STATE_READ_MESSAGE_PWM_2 belongs to the file "app_uart.c" and the state APP_STATE_INIT belongs to the file "app.c". Can I "send" values (in this caseappUartData.rx_number_pwm2) from one file to another? 4- How can I use code tags here from copy/past of my source code? Thank you a lot |
|
|
|
从app_uart.c到app.c获得PWM值有几种方法。
以上来自于百度翻译 以下为原文 There are several ways to get the PWM value from app_uart.c to app.c. One is to declare a function in app.c and then reference it in app_uart.c as follows: // this is in a common .h file void UpdatePwm(UINT32 newPwmValue); // this is in app.c void UpdatePwm(UINT32 newPwmValue) { if (readyForNewValue) // this is an optional test in case there are times you don't want to update the PWM { appData.pwm_value = newPwmValue; // create a new element in your appData structure appData.state = APP_STATE_INIT; } else { // do some kind of error processing if desired } } /* UpdatePwm() */ // part of the app.c state machine case APP_STATE_INIT: /* Enable the OCMP module and start the timer */ DRV_OC0_Start(); DRV_OC1_Start(); DRV_OC1_PulseWidthSet(appData.pwm_value); DRV_TMR0_Start(); appData.state = APP_STATE_SERVICE_TASKS; break; // this is in app_uart.c // part of the app_uart.c state machine if (appUartData.rx_text_pwm2 == 'r') // update the PWM on receipt of a carriage return { UpdatePwm(appUartData.rx_number); appUartData.state = APP_UART_STATE_INIT; // get ready for next value } -Bill |
|
|
|
非常感谢。我从你身上学到了很多东西
以上来自于百度翻译 以下为原文 Thank you a lot. I learnt a lot from you. It worked |
|
|
|
只有小组成员才能发言,加入小组>>
5231 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3200 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
770浏览 1评论
658浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
587浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
668浏览 0评论
570浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-19 03:56 , Processed in 1.249201 second(s), Total 91, Slave 74 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号