CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

16F876 Software UART Troubles

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Freddie L
Guest







16F876 Software UART Troubles
PostPosted: Sat Feb 08, 2003 4:40 pm     Reply with quote

<font face="Courier New" size=-1>I'm using a PIC16F876-04 and CCM v3.141. The kbhit() and getc() command are supposed to stop the program and wait for a character on the software UART pin. With the following code, the LED blinks repeatedly, as if data has been read from the software UART PIN_B2, even if PIN_B2 is tied to ground! Is there something I'm missing here?

<code>
#include <16f876.h>
#fuses XT, NOWDT, NOPUT, NOPROTECT
#use delay(clock=4000000)

void main(void)
{

#use rs232(baud=9600, xmit=PIN_B3, rcv=PIN_B2)

while(1)
{
delay_ms(200); //blink LED for debugging
output_high(PIN_C7);
delay_ms(75);
output_low(PIN_C7);
delay_ms(100);

while(!kbhit());
getc();

} // ----- end while(1)

} //----- end main

Freddie.</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 11431
Freddie L
Guest







Re: 16F876 Software UART Troubles
PostPosted: Sun Feb 09, 2003 12:13 am     Reply with quote

After looking at the LIST file it became clear to me that the kbhit() command simply looks for a certain state on the pin (ie, high or low). It is not actually looking for a start bit.

:=<font face="Courier New" size=-1>I'm using a PIC16F876-04 and CCM v3.141. The kbhit() and getc() command are supposed to stop the program and wait for a character on the software UART pin. With the following code, the LED blinks repeatedly, as if data has been read from the software UART PIN_B2, even if PIN_B2 is tied to ground! Is there something I'm missing here?
:=
:=<code>
:=#include <16f876.h>
:=#fuses XT, NOWDT, NOPUT, NOPROTECT
:=#use delay(clock=4000000)
:=
:=void main(void)
:={
:=
:=#use rs232(baud=9600, xmit=PIN_B3, rcv=PIN_B2)
:=
:=while(1)
:={
:= delay_ms(200); //blink LED for debugging
:= output_high(PIN_C7);
:= delay_ms(75);
:= output_low(PIN_C7);
:= delay_ms(100);
:=
:= while(!kbhit());
:= getc();
:=
:=} // ----- end while(1)
:=
:=} //----- end main
:=
:=Freddie.</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 11440
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: 16F876 Software UART Troubles
PostPosted: Sun Feb 09, 2003 12:59 am     Reply with quote

:=<font face="Courier New" size=-1>I'm using a PIC16F876-04 and CCM v3.141. The kbhit() and getc() command are supposed to stop the program and wait for a character on the software UART pin. With the following code, the LED blinks repeatedly, as if data has been read from the software UART PIN_B2, even if PIN_B2 is tied to ground! Is there something I'm missing here?
---------------------------------------------------------

If you look at the 16F87x data sheet, in Figure 10-5,
"Asynchronous Reception", it shows that a Start Bit is
a low-level pulse. So, if you're tying the RCV pin low,
then you're giving it a start bit, followed by 8 low data
bits. The code will blow right through your kbhit() and
get() statements without waiting, because it thinks it
got a RS-232 byte.

Here's the code generated by vs. 3.141 for part of your
program:
<PRE>
0000 00362 .......... while(!kbhit());
0060 1906 00363 BTFSC 06.2
0061 2860 00364 GOTO 060
0000 00365 ........... getc();
0062 2819 00366 GOTO 019
</PRE>

The code is testing Port B, bit 2, which is your RCV pin.
If the RCV pin is "clear" (ie., low), it skips the next
instruction and goes to 019, which is the getc() routine.
If the RCV pin is high, then it executes the GOTO 060, which
means it loops back and tests the RCV pin again.

This code should work OK if you're using a MAX232A chip.
If you're not, then you need to use the INVERT option.
Like this:

#use rs232(baud=9600, xmit=PIN_B3, rcv=PIN_B2, INVERT)

One thing more. If you're not using Low Voltage Programming
mode, then you definitely need to add NOLVP to your fuses
statement. Like this:

#fuses XT, NOWDT, NOPUT, NOPROTECT, NOLVP
___________________________
This message was ported from CCS's old forum
Original Post ID: 11441
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: 16F876 Software UART Troubles
PostPosted: Sun Feb 09, 2003 2:04 am     Reply with quote

:=<font face="Courier New" size=-1>I'm using a PIC16F876-04 and CCM v3.141. The kbhit() and getc() command are supposed to stop the program and wait for a character on the software UART pin. With the following code, the LED blinks repeatedly, as if data has been read from the software UART PIN_B2, even if PIN_B2 is tied to ground! Is there something I'm missing here?
:=
---------------------------------------------------------
Test
___________________________
This message was ported from CCS's old forum
Original Post ID: 11442
R.J.Hamlett
Guest







Re: 16F876 Software UART Troubles
PostPosted: Sun Feb 09, 2003 3:19 am     Reply with quote

:=<font face="Courier New" size=-1>I'm using a PIC16F876-04 and CCM v3.141. The kbhit() and getc() command are supposed to stop the program and wait for a character on the software UART pin. With the following code, the LED blinks repeatedly, as if data has been read from the software UART PIN_B2, even if PIN_B2 is tied to ground! Is there something I'm missing here?
:=
:=<code>
:=#include <16f876.h>
:=#fuses XT, NOWDT, NOPUT, NOPROTECT
:=#use delay(clock=4000000)
:=
:=void main(void)
:={
:=
:=#use rs232(baud=9600, xmit=PIN_B3, rcv=PIN_B2)
:=
:=while(1)
:={
:= delay_ms(200); //blink LED for debugging
:= output_high(PIN_C7);
:= delay_ms(75);
:= output_low(PIN_C7);
:= delay_ms(100);
:=
:= while(!kbhit());
:= getc();
:=
:=} // ----- end while(1)
:=
:=} //----- end main
:=
:=Freddie.</font>
Obvious thing, is that tying the input to GND, will result in a continuous receive...
RS232, as normally transmitted, uses a -ve voltage as the 'idle' state, and a +ve voltage for the signal. However this is inverted by the line drivers, so at the chip, the TTL levels are +5v = idle, and GND = the 'mark' signal. Your chip will be seeing a continuous data stream. Tie the signal to +5v, to stop the reception.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 11444
Darren Logan
Guest







Re: 16F876 Software UART Troubles
PostPosted: Mon Feb 10, 2003 5:15 am     Reply with quote

Hi

Without trying it, at a guess your problem is because B3 is also used as a low-voltage programming pin.

You can turn this off using NOVLP in the #fuses list.

Regards,
Darren
___________________________
This message was ported from CCS's old forum
Original Post ID: 11472
Sherpa Doug
Guest







Re: 16F876 Software UART Troubles
PostPosted: Mon Feb 10, 2003 7:57 am     Reply with quote

:=After looking at the LIST file it became clear to me that the kbhit() command simply looks for a certain state on the pin (ie, high or low). It is not actually looking for a start bit.
:=

How could one possibly tell the difference? It looks for a start bit voltage level as defined by the active use-RS232 statement. Without supernatural powers what else could it do?

"There is no way to paint one electron green or query its intent" - quote from some physicist long ago.

___________________________
This message was ported from CCS's old forum
Original Post ID: 11477
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group