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 CCS Technical Support

why getchar() does not wait for receiving data ?

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



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

why getchar() does not wait for receiving data ?
PostPosted: Fri Jan 07, 2005 3:51 pm     Reply with quote

I have a simple program as
Code:

#if defined(__PCM__)
#include <12F675.h>
#fuses INTRC_IO, BROWNOUT,NOWDT,NOPROTECT,PUT,NOMCLR
#use delay(clock =4000000)
#use rs232(baud=9600, parity=N, RCV=PIN_A1,XMIT=PIN_A0)

void main ()
{
  int dat;
  setup_comparator(NC_NC_NC_NC);
  SETUP_ADC_PORTS(NO_ANALOGS);

  while(1)

     {
     char a;
     a=getchar();
     output_high(PIN_A4);

     }
}


a=getchar() should hang there waiting for signal input, however, it does not here, PIN_A4 keep having high output?

why getcgar() does not wait
dyeatman



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

View user's profile Send private message

What are you connected to?
PostPosted: Fri Jan 07, 2005 4:19 pm     Reply with quote

We need more information.

How are you connected?
What are using on the other end for the comm program?

I would suspect you need the invert keyword in your rs232 statement
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Sat Jan 08, 2005 10:53 pm     Reply with quote

What's the value of variable a ?

Nick
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Mon Jan 10, 2005 7:06 am     Reply with quote

first of all, I already used the MAX232, I connected the RX, TX to serial monitor through MA232, So I think I do not need a INVERT for the fuses, second, the value of a is "z" at " " at the very beginning, at after a while it becomes to " " only.
dyeatman



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

View user's profile Send private message

PostPosted: Mon Jan 10, 2005 9:08 am     Reply with quote

Young,
Offhand I would agree with you about the INVERTand the MAX232 however I dont know what actual level you are getting from the source and whether it is inverted or not. I have been "bitten" by this before... so I suggested it...

If the UART buffer has garbage somehow at startup the getc() whould work the first time and set the output A4 high. You dont have anything to set it back low again so it would stay that way even if the getc() was waiting the next time around.

FWIW....
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Mon Jan 10, 2005 9:50 am     Reply with quote

Thank you dyeatman:

I tried the program on a 16f819 chip it works just as what it should be, getchar() just hang over there waiting for my input. I tried INTRC_IO and external crystal, both works. Does anyone have these experience, Many program does not work well on 12f675, but works on other chips, and 12f675 is very easy burned out.
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Mon Jan 10, 2005 1:54 pm     Reply with quote

Did you tried setting the GP4 to a known value as suggested?
Code:
  while(1)
     {
     output_low(PIN_A4);
     char a;
     a=getchar();
     output_high(PIN_A4);
     }


You mention that the same program works on a 16F819. Pin A1 (RCV-pin) is part of the ICSP on 12F675, but not on the 16F819. Do you have the ICSP circuit somehow connected to this during normal operation? Just some thoughts.

In any case, as was mentioned before, it is not recommended to use variables (or inputs) without initializing them. In software, at least, it is just bad practice. In embedded design is risky.

Edit:
Note that from the datasheets, on 12F675 GPIO-ports on POR or BOD are "--xx xxxx" (i.e. unknown state). On 16F819 PORTA on POR or BOD are "xxx0 0000" (i.e. only RA7-RA5 are unknown, all others are low).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 10, 2005 2:56 pm     Reply with quote

What is your version of the compiler ? Some earlier versions
had problems with the Analog/Digital settings for the 12F675 pins,
and with the comparator configuration. If you post your compiler
version, we can check this. The version is given at the top of
the .LST file.
Guest








PostPosted: Mon Jan 10, 2005 3:09 pm     Reply with quote

Thank you, I am using CCS PCM C Compiler, Version 3.202, 24343
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 10, 2005 4:57 pm     Reply with quote

I modified your test program slightly, so I could make it be
more interactive. I don't have a 12F675 chip, but I do have
a 12F629. They are similar chips, except that the 12F629 does
not have an A/D converter. I installed PCM vs. 3.202 and
programmed the PIC with a PicStart-Plus programmer. It worked OK.

I did not use a MAX232 chip, so I added the "INVERT" option
to the end of the #use rs232() statement. I just connected
a 10K series resistor between the RS232 xmit signal and pin 6
of the 12F675, to protect the input pin from the +/- 12v RS232 signal.

When I press the "A" key, pin 3 of the 12F675 goes high.
When I press the "B" key, pin 3 goes low.

I looked at the .LST file generated by vs. 3.202. It looks like
the setup_adc_ports() and setup_comparators() functions are OK.
The CCS startup code is incorrect, though. It sets pins ANS0-ANS3
as analog inputs, and it turns on the A/D converter and sets
the "GO" bit = 1. So if you want to, you could add this line
to your startup code, in the program below:
Code:
setup_adc(ADC_OFF);

It probably won't have any effect, but it won't hurt.


Code:
#include <12F675.h>
#fuses INTRC_IO, BROWNOUT,NOWDT,NOPROTECT,PUT,NOMCLR
#use delay(clock =4000000)
#use rs232(baud=9600, parity=N, RCV=PIN_A1,XMIT=PIN_A0, INVERT)

void main ()
{
int i;
char c;
   
setup_comparator(NC_NC_NC_NC);
SETUP_ADC_PORTS(NO_ANALOGS);

while(1)
  {
   c = getchar();
   c &= 0x5F;

   if(c == 'A')
      output_high(PIN_A4);

   if(c == 'B')
      output_low(PIN_A4);
  }

}
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