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

GETC() not working??

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







GETC() not working??
PostPosted: Mon Feb 10, 2003 4:52 pm     Reply with quote

<font face="Courier New" size=-1>I'm trying to test some code but it doesn't seem to be working. I thought with the GETC() command, it is supposed to wait indefinitely until it gets a character. But my code does not seem to do this. It seems to just skip over the getc(). Here is my code:

#include <16F84a.H>

#fuses XT,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B4)

main() {
getc(); //wait for an input to start buzzer
while (TRUE) {
output_high (PIN_B3);
delay_ms(500);
output_low(PIN_B3);
delay_ms(500);
}
}

When I run this, it immediately start oscillating PIN B3 but I thought getc() was supposed ot make it wait. Any idea why this happens? Am I doing something wrong? When I power it on, I have nothing connected to the receive or transmit pins (B4 & B5). Does that make any difference?

Another little thing. I see some example codes that don't have the #fuse XT command but when I tried running some code without it, it does nothing. Is the #fuse absilutely necessary? Thanks for all the help. </font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 11495
dyeatman



Joined: 06 Sep 2003
Posts: 1810
Location: Norman, OK

View user's profile Send private message

Re: GETC() not working??
PostPosted: Mon Feb 10, 2003 5:23 pm     Reply with quote

You will either need to pull B4 low or add the Invert switch to the Use RS232 line. The software is looking for the input to be high for a Start bit and B4 is floating high...

Dave


:=<font face="Courier New" size=-1>I'm trying to test some code but it doesn't seem to be working. I thought with the GETC() command, it is supposed to wait indefinitely until it gets a character. But my code does not seem to do this. It seems to just skip over the getc(). Here is my code:
:=
:=#include <16F84a.H>
:=
:=#fuses XT,NOWDT,NOPROTECT
:=#use delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B4)
:=
:=main() {
:= getc(); //wait for an input to start buzzer
:= while (TRUE) {
:= output_high (PIN_B3);
:= delay_ms(500);
:= output_low(PIN_B3);
:= delay_ms(500);
:= }
:=}
:=
:=When I run this, it immediately start oscillating PIN B3 but I thought getc() was supposed ot make it wait. Any idea why this happens? Am I doing something wrong? When I power it on, I have nothing connected to the receive or transmit pins (B4 & B5). Does that make any difference?
:=
:=Another little thing. I see some example codes that don't have the #fuse XT command but when I tried running some code without it, it does nothing. Is the #fuse absilutely necessary? Thanks for all the help. </font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 11497
_________________
Google and Forum Search are some of your best tools!!!!
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: GETC() not working??
PostPosted: Mon Feb 10, 2003 5:24 pm     Reply with quote

:=<font face="Courier New" size=-1>I'm trying to test some code but it doesn't seem to be working. I thought with the GETC() command, it is supposed to wait indefinitely until it gets a character. But my code does not seem to do this. It seems to just skip over the getc(). Here is my code:
:=
:=#include <16F84a.H>
:=
:=#fuses XT,NOWDT,NOPROTECT
:=#use delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B4)
:=
:=main() {
:= getc(); //wait for an input to start buzzer
:= while (TRUE) {
:= output_high (PIN_B3);
:= delay_ms(500);
:= output_low(PIN_B3);
:= delay_ms(500);
:= }
:=}
:=
:=When I run this, it immediately start oscillating PIN B3 but I thought getc() was supposed ot make it wait. Any idea why this happens? Am I doing something wrong? When I power it on, I have nothing connected to the receive or transmit pins (B4 & B5). Does that make any difference?
:=
:=Another little thing. I see some example codes that don't have the #fuse XT command but when I tried running some code without it, it does nothing. Is the #fuse absilutely necessary? Thanks for all the help. </font>

Don't leave your inputs floating. Your getting garbage input to the uart. You should also set each fuse the way you want it. If you need to read a bit about the configuration fuses. Decide what you want. The XT fuse allows the pic to use a 4MHz crystal.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11498
Humberto



Joined: 08 Sep 2003
Posts: 1185
Location: Buenos Aires la Reina del Plata

View user's profile Send private message

Re: GETC() not working??
PostPosted: Mon Feb 10, 2003 6:41 pm     Reply with quote

:=<font face="Courier New" size=-1>I'm trying to test some code but it doesn't seem to be working. I thought with the GETC() command, it is supposed to wait indefinitely until it gets a character. But my code does not seem to do this. It seems to just skip over the getc(). Here is my code:
:=
:=#include <16F84a.H>
:=
:=#fuses XT,NOWDT,NOPROTECT
:=#use delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B4)
:=
:=main() {
:= getc(); //wait for an input to start buzzer
:= while (TRUE) {
:= output_high (PIN_B3);
:= delay_ms(500);
:= output_low(PIN_B3);
:= delay_ms(500);
:= }
:=}
:=
:=When I run this, it immediately start oscillating PIN B3 but I thought getc() was supposed ot make it wait. Any idea why this happens? Am I doing something wrong? When I power it on, I have nothing connected to the receive or transmit pins (B4 & B5). Does that make any difference?

Yes, the program is running according to the code you wrote:

main() {

getc(); //wait for an input to start buzzer

// there are only a few milliseconds to catch the Start
// pulse here, then it goes to the never ending loop
// while (TRUE) and int this loop, it never will take
// care of PIN_B4 nor the getc() function.

while (TRUE) {
output_high (PIN_B3);
delay_ms(500);
output_low(PIN_B3);
delay_ms(500);
}

It is not a good practice to use getc()directly, it is recommended to use kbhit(). This function -kbhit()- is looking for the start bit, wich is a negative going pulse in the receiver line (PIN_B4). Only after you get it, you can invoque the getc() function.
If you search a little in this board you will find a lot of samples of getc() combined with kbhit() functions.


:=Another little thing. I see some example codes that don't have the #fuse XT command but when I tried running some code without it, it does nothing. Is the #fuse absilutely necessary? Thanks for all the help. </font>

Yes, itīs a MUST. With the #FUSES directive you tell the compiler to set a dedicated configuration register wich hold the most basic hardware settings into the microcontroller.
Usually in the samples, you will see that Directives to the compiler(#) are not included, but itīs only to show the codes
involved in such subject only.

Hope this help, good luck !
___________________________
This message was ported from CCS's old forum
Original Post ID: 11500
_________________
Humberto
Humberto



Joined: 08 Sep 2003
Posts: 1185
Location: Buenos Aires la Reina del Plata

View user's profile Send private message

Re: GETC() not working??
PostPosted: Mon Feb 10, 2003 6:47 pm     Reply with quote

:=:=<font face="Courier New" size=-1>I'm trying to test some code but it doesn't seem to be working. I thought with the GETC() command, it is supposed to wait indefinitely until it gets a character. But my code does not seem to do this. It seems to just skip over the getc(). Here is my code:
:=:=
:=:=#include <16F84a.H>
:=:=
:=:=#fuses XT,NOWDT,NOPROTECT
:=:=#use delay(clock=4000000)
:=:=#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B4)
:=:=
:=:=main() {
:=:= getc(); //wait for an input to start buzzer
:=:= while (TRUE) {
:=:= output_high (PIN_B3);
:=:= delay_ms(500);
:=:= output_low(PIN_B3);
:=:= delay_ms(500);
:=:= }
:=:=}
:=:=
:=:=When I run this, it immediately start oscillating PIN B3 but I thought getc() was supposed ot make it wait. Any idea why this happens? Am I doing something wrong? When I power it on, I have nothing connected to the receive or transmit pins (B4 & B5). Does that make any difference?
:=

Yes, the program is running according to the code you wrote:

main() {

getc(); //wait for an input to start buzzer

// there are only a few milliseconds to catch the Start
// pulse here, then it goes to the never ending loop
// while (TRUE) and int this loop, it never will take
// care of PIN_B4 nor the getc() function.

while (TRUE) {
output_high (PIN_B3);
delay_ms(500);
output_low(PIN_B3);
delay_ms(500);
}

It is not a good practice to use getc()directly, it is recommended to use kbhit(). This function -kbhit()- is looking for the start bit, wich is a negative going pulse in the receiver line (PIN_B4). Only after you get it, you can invoque the getc() function.
If you search a little in this board you will find a lot of samples of getc() combined with kbhit() functions.


:=:=Another little thing. I see some example codes that don't have the #fuse XT command but when I tried running some code without it, it does nothing. Is the #fuse absilutely necessary? Thanks for all the help. </font>
:=

Yes, itīs a MUST. With the #FUSES directive you tell the compiler to set a dedicated configuration register wich hold the most basic hardware settings into the microcontroller.
Usually in the samples, you will see that Directives to the compiler(#) are not included, but itīs only to show the codes
involved in such subject only.

Hope this help, good luck !
___________________________
This message was ported from CCS's old forum
Original Post ID: 11501
_________________
Humberto
R.J.Hamlett
Guest







Re: GETC() not working??
PostPosted: Tue Feb 11, 2003 3:15 am     Reply with quote

:=You will either need to pull B4 low or add the Invert switch to the Use RS232 line. The software is looking for the input to be high for a Start bit and B4 is floating high...
:=
:=Dave
You are right, that the input is the problem, but wrong about the polarity.
The serial data, on the TTL pins, idles high, and a 0v level is a start bit. Hence if the input is pulled low, this will be seen as data.
TTL signalling looks like this:

idle start d0 d1 d2 d3 d4 d5 d6 d7 stop

----- ----- ----- ----- ---------
----- ----- ---------- ----------

1 0 1 0 0 1 0 0

Data is sent LSB first, so this corresponds to 0x25.
You will see, that a _low_ signal, is the start bit. Hence on the 'B' pins being used, simple enabling the internal weak pull-ups, is enough to prevent random triggering.

Best Wishes

:=:=<font face="Courier New" size=-1>I'm trying to test some code but it doesn't seem to be working. I thought with the GETC() command, it is supposed to wait indefinitely until it gets a character. But my code does not seem to do this. It seems to just skip over the getc(). Here is my code:
:=:=
:=:=#include <16F84a.H>
:=:=
:=:=#fuses XT,NOWDT,NOPROTECT
:=:=#use delay(clock=4000000)
:=:=#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B4)
:=:=
:=:=main() {
:=:= getc(); //wait for an input to start buzzer
:=:= while (TRUE) {
:=:= output_high (PIN_B3);
:=:= delay_ms(500);
:=:= output_low(PIN_B3);
:=:= delay_ms(500);
:=:= }
:=:=}
:=:=
:=:=When I run this, it immediately start oscillating PIN B3 but I thought getc() was supposed ot make it wait. Any idea why this happens? Am I doing something wrong? When I power it on, I have nothing connected to the receive or transmit pins (B4 & B5). Does that make any difference?
:=:=
:=:=Another little thing. I see some example codes that don't have the #fuse XT command but when I tried running some code without it, it does nothing. Is the #fuse absilutely necessary? Thanks for all the help. </font>
:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 11512
Denis Gnani
Guest







Re: GETC() not working??
PostPosted: Tue Feb 11, 2003 10:28 pm     Reply with quote

I just want to express my extreme gratitude for the help you have provided. Especially R.J.Hamlett. I added the port_b_pullups(true) command and now my program appears to be working correctly.

Forgive me but I am new to programming the PIC's. Can you briefly explain what the weak pull-ups on port B does? All I know is that it made my program work. Again, thanks for the help.

:=:=You will either need to pull B4 low or add the Invert switch to the Use RS232 line. The software is looking for the input to be high for a Start bit and B4 is floating high...
:=:=
:=:=Dave
:=You are right, that the input is the problem, but wrong about the polarity.
:=The serial data, on the TTL pins, idles high, and a 0v level is a start bit. Hence if the input is pulled low, this will be seen as data.
:=TTL signalling looks like this:
:=
:=idle start d0 d1 d2 d3 d4 d5 d6 d7 stop
:=
:=----- ----- ----- ----- ---------
:= ----- ----- ---------- ----------
:=
:= 1 0 1 0 0 1 0 0
:=
:=Data is sent LSB first, so this corresponds to 0x25.
:=You will see, that a _low_ signal, is the start bit. Hence on the 'B' pins being used, simple enabling the internal weak pull-ups, is enough to prevent random triggering.
:=
:=Best Wishes
:=
:=:=:=<font face="Courier New" size=-1>I'm trying to test some code but it doesn't seem to be working. I thought with the GETC() command, it is supposed to wait indefinitely until it gets a character. But my code does not seem to do this. It seems to just skip over the getc(). Here is my code:
:=:=:=
:=:=:=#include <16F84a.H>
:=:=:=
:=:=:=#fuses XT,NOWDT,NOPROTECT
:=:=:=#use delay(clock=4000000)
:=:=:=#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B4)
:=:=:=
:=:=:=main() {
:=:=:= getc(); //wait for an input to start buzzer
:=:=:= while (TRUE) {
:=:=:= output_high (PIN_B3);
:=:=:= delay_ms(500);
:=:=:= output_low(PIN_B3);
:=:=:= delay_ms(500);
:=:=:= }
:=:=:=}
:=:=:=
:=:=:=When I run this, it immediately start oscillating PIN B3 but I thought getc() was supposed ot make it wait. Any idea why this happens? Am I doing something wrong? When I power it on, I have nothing connected to the receive or transmit pins (B4 & B5). Does that make any difference?
:=:=:=
:=:=:=Another little thing. I see some example codes that don't have the #fuse XT command but when I tried running some code without it, it does nothing. Is the #fuse absilutely necessary? Thanks for all the help. </font>
:=:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 11569
R.J.Hamlett
Guest







Re: GETC() not working??
PostPosted: Wed Feb 12, 2003 4:29 am     Reply with quote

:=I just want to express my extreme gratitude for the help you have provided. Especially R.J.Hamlett. I added the port_b_pullups(true) command and now my program appears to be working correctly.
:=
:=Forgive me but I am new to programming the PIC's. Can you briefly explain what the weak pull-ups on port B does? All I know is that it made my program work. Again, thanks for the help.
:=
The 'port_b_pullups' command, turns on a small fet, attached to each of the port B pins, so that the signal will 'float high'. Generically with _all_ CMOS chips (this is not confined to PICs), you have to ensure that the input lines are pulled to the required state when not driven. On TTL logic in the past you could assume that an input would float high (though this was still 'bad' practice). On CMOS stuff, this assumption no longer applies, and the input impedance is so high, that lines will remain at the last voltage present, or may float to an indeterminate state, unless deliberately driven.
Hence as a rule of thumb, add a large value resistor (or turn on the weak pull ups), on every input pin that is not connected to something driving it.

Glad it is working now. :-)

Best Wishes

:=:=:=You will either need to pull B4 low or add the Invert switch to the Use RS232 line. The software is looking for the input to be high for a Start bit and B4 is floating high...
:=:=:=
:=:=:=Dave
:=:=You are right, that the input is the problem, but wrong about the polarity.
:=:=The serial data, on the TTL pins, idles high, and a 0v level is a start bit. Hence if the input is pulled low, this will be seen as data.
:=:=TTL signalling looks like this:
:=:=
:=:=idle start d0 d1 d2 d3 d4 d5 d6 d7 stop
:=:=
:=:=----- ----- ----- ----- ---------
:=:= ----- ----- ---------- ----------
:=:=
:=:= 1 0 1 0 0 1 0 0
:=:=
:=:=Data is sent LSB first, so this corresponds to 0x25.
:=:=You will see, that a _low_ signal, is the start bit. Hence on the 'B' pins being used, simple enabling the internal weak pull-ups, is enough to prevent random triggering.
:=:=
:=:=Best Wishes
:=:=
:=:=:=:=<font face="Courier New" size=-1>I'm trying to test some code but it doesn't seem to be working. I thought with the GETC() command, it is supposed to wait indefinitely until it gets a character. But my code does not seem to do this. It seems to just skip over the getc(). Here is my code:
:=:=:=:=
:=:=:=:=#include <16F84a.H>
:=:=:=:=
:=:=:=:=#fuses XT,NOWDT,NOPROTECT
:=:=:=:=#use delay(clock=4000000)
:=:=:=:=#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B4)
:=:=:=:=
:=:=:=:=main() {
:=:=:=:= getc(); //wait for an input to start buzzer
:=:=:=:= while (TRUE) {
:=:=:=:= output_high (PIN_B3);
:=:=:=:= delay_ms(500);
:=:=:=:= output_low(PIN_B3);
:=:=:=:= delay_ms(500);
:=:=:=:= }
:=:=:=:=}
:=:=:=:=
:=:=:=:=When I run this, it immediately start oscillating PIN B3 but I thought getc() was supposed ot make it wait. Any idea why this happens? Am I doing something wrong? When I power it on, I have nothing connected to the receive or transmit pins (B4 & B5). Does that make any difference?
:=:=:=:=
:=:=:=:=Another little thing. I see some example codes that don't have the #fuse XT command but when I tried running some code without it, it does nothing. Is the #fuse absilutely necessary? Thanks for all the help. </font>
:=:=:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 11589
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