Microchip
直播中

刘军

7年用户 1391经验值
私信 关注
[问答]

RCIF不会变为零

大家好!我在一个接收USAT数据的程序中工作。我不需要使用中断。目的是通过监视RCIF位来保持一个循环。当它被设置时,我将处理每一个收到的字节。从我理解的USAT中,每次读取RCREG时,RCIF位都被清除,然后我返回到循环的开始,等待一个新字节。这就是问题所在!RCIF位不会达到0!我已经做了所有的事情…我尝试读RCREG几次,我尝试零RCIF直接(PrI1BITS RCIF=0),但没有什么导致RCIF到零!……()PiL1ReC= GETCUTART();PutsCART(BytEyReC)ReD1=!LeD1……正在发生的事情是RCIF一直被清除。有人会对什么是错误的有什么建议吗?附加信息:C18汇编语言18F2520非常感谢蚂蚁提示。

以上来自于百度翻译


      以下为原文

    Hello guys!

I am working in a program that receives USART data. I do not need to use the interrupt. The intent is to stay in a loop by monitoring the RCIF bit. When it's set, I'll handle every received byte. From what I understand from USART, every time I read RCREG the RCIF bit is cleared and then I go back to the beginning of the loop to wait for a new byte. That's the problem! The RCIF bit is not going to 0! I've done everything ... I try read RCREG several times, I try to zero RCIF directly (PIR1bits.RCIF = 0) but nothing causes RCIF to go to zero!


.

.

.

while (! PIR1bits.RCIF);

byte_rec = getcUSART ();
putcUSART (byte_rec)
LED1 =! LED1

.

.

.


What is happening is that RCIF is kept cleared all the time.


Would anyone have any tips on what could be wrong?


Additional Information:

C18 compiler

PIC18F2520

Thanks so much for ant hint.

回帖(5)

吴键洪

2018-11-28 16:56:30
这是对的,别费心了。数据表告诉您,该位是只读的。为什么调用函数只是为了读取寄存器?同样,您没有显示LeD1的定义。如果它正在处理一个PORTX寄存器,那么将其更改为等效的LATX寄存器。

以上来自于百度翻译


      以下为原文

   
This is correct.

Don't bother. As the datasheet tells you, that bit is read only.
 
while (! PIR1bits.RCIF);
byte_rec = getcUSART ();
Why call a function just to read a register?
Try:
while (! PIR1bits.RCIF)
    byterec  = RCREG;
    TXREG  byterec;
    LED1 =! LED1

Also, you did not show the definition for LED1.
If it is addressing a PORTx register, change it to the equivalent LATx register.
 
举报

吴键洪

2018-11-28 17:06:18
如果您仍然无法解决,请张贴您的整个测试程序。

以上来自于百度翻译


      以下为原文

    If you still can't solve it, please post your ENTIRE test program.
 
举报

张云

2018-11-28 17:23:49
嗨,Q!B!非常感谢。我找到了问题所在。我的硬件使用了Mx85来从一个PIC通信到另一个PIC。我发现,当发射机PIC完成发送每个字节时,它将把它的Max55置于接收状态(将Re/DE置零)。这导致接收器的MAX55将其数据输出设为零。因此,在每个接收字节之后不久,接收PIC就已经知道新起始位和零位的所有字节的到达,但是没有停止位。但是,这又保持了RCIF位再次设置。你的答案是很重要的,我确认我的理解是在正确的轨道上,即使在那个时候,我仍然没有意识到这一特点运行McAc4.5谢谢。

以上来自于百度翻译


      以下为原文

    Hi qɥb!

Thanks so much.

I found where the problem was. My hardware used the MAX485 to communicate from one PIC to another. I found that when the transmitter PIC finished sending each byte, it would put its MAX485 in the receive state (putting RE / DE to zero). This caused the receiver's MAX485 to put its data output at zero. Thus, shortly after each received byte, the receiving PIC already understood the arrival of a new start bit and an all byte at zero, but without stop bits. But this then kept the RCIF bit set again.

Your answer was important for me to confirm that my understanding was on the right track, even though at that time I still did not realize this feature of running the MAX485.

Thanks.
举报

吴键洪

2018-11-28 17:42:02
通常情况下,真正的问题是在最初的描述中没有提到的问题。:)

以上来自于百度翻译


      以下为原文

    So often, the real problem is something that wasn't mentioned in the initial description. :)
 
举报

更多回帖

发帖
×
20
完善资料,
赚取积分