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 problem

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







getc problem
PostPosted: Sat Jan 08, 2005 1:34 pm     Reply with quote

I did a little test program.

Code:
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

Code:
void main()
{
   int flag;
   int ch;
   flag = 1;
   
   while(1) {
   
         ch = getc();
   
      if (flag) {
        output_high(PIN_A1);
        flag = 0;
      } else {
        output_low(PIN_A1);
        flag = 1;
      }
   
      printf("You pressed ");
      putc ( ch );
      printf("  ");
   }
}


before I press any key, the LED is off as it should be. When I press a key, the LED is on, but the problem is that it stays on all the time, even when I press keys.

This means that the program is stuck at the line
Code:
ch = getc


Why is it???
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Sat Jan 08, 2005 2:17 pm     Reply with quote

Try adding

Code:
setup_adc_ports( NO_ANALOGS );


At the beginning of your code.

Or use a port that isn't an analog port for the LED.
Guest








PostPosted: Sat Jan 08, 2005 3:27 pm     Reply with quote

This does not solve anything. even by changing the port, the program still seems to be stuck at the line ch = getc()
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Sat Jan 08, 2005 4:22 pm     Reply with quote

Tested with V3.215 on PIC16F877A and it seems to be working just fine. Pin A1 goes up and down (per DMM, didn't hook up LED) and RS232 port is echoing typed character.

Note that I added 4 lines to what you had in your post:

#include <pic16f877a.h>, #case, #use delay and the #fuse statement.

Below is a copy of the LST file.

What version of the compiler are you using? What chip are you using?

Code:
CCS PCM C Compiler, Version 3.215, 26886               08-Jan-05 16:15

               Filename: C:\Program Files\PICC\Projects\crapola\crapola.LST

               ROM used: 90 words (1%)
                         Largest free fragment is 2048
               RAM used: 8 (5%) at main() level
                         8 (5%) worst case
               Stack:    1 locations

*
0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   015
0003:  NOP
....................  #include <16F877A.h>
....................  //////// Standard Header file for the PIC16F877A device ////////////////
.................... #device PIC16F877A
.................... #list
....................
.................... #case
.................... #use delay(clock=20000000)
.................... #fuses NOWDT,HS, PUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT
.................... #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
....................
.................... void main()
.................... {
0015:  CLRF   04
0016:  MOVLW  1F
0017:  ANDWF  03,F
0018:  BSF    03.5
0019:  BSF    1F.0
001A:  BSF    1F.1
001B:  BSF    1F.2
001C:  BCF    1F.3
001D:  MOVLW  07
001E:  MOVWF  1C
001F:  MOVF   1C,W
0020:  BCF    03.5
0021:  BCF    0D.6
0022:  MOVLW  81
0023:  BSF    03.5
0024:  MOVWF  19
0025:  MOVLW  26
0026:  MOVWF  18
0027:  MOVLW  90
0028:  BCF    03.5
0029:  MOVWF  18
....................    int flag;
....................    int ch;
....................    flag = 1;
002A:  MOVLW  01
002B:  MOVWF  21
....................
....................    while(1) {
....................
....................          ch = getc();
002C:  BTFSS  0C.5
002D:  GOTO   02C
002E:  MOVF   1A,W
002F:  MOVWF  22
....................
....................       if (flag) {
0030:  MOVF   21,F
0031:  BTFSC  03.2
0032:  GOTO   039
....................         output_high(PIN_A1);
0033:  BSF    03.5
0034:  BCF    05.1
0035:  BCF    03.5
0036:  BSF    05.1
....................         flag = 0;
0037:  CLRF   21
....................       } else {
0038:  GOTO   03F
....................         output_low(PIN_A1);
0039:  BSF    03.5
003A:  BCF    05.1
003B:  BCF    03.5
003C:  BCF    05.1
....................         flag = 1;
003D:  MOVLW  01
003E:  MOVWF  21
....................       }
....................
....................       printf("You pressed ");
003F:  CLRF   23
0040:  MOVF   23,W
0041:  CALL   004
0042:  INCF   23,F
0043:  MOVWF  77
0044:  MOVF   77,W
0045:  BTFSS  0C.4
0046:  GOTO   045
0047:  MOVWF  19
0048:  MOVLW  0C
0049:  SUBWF  23,W
004A:  BTFSS  03.2
004B:  GOTO   040
....................       putc ( ch );
004C:  MOVF   22,W
004D:  BTFSS  0C.4
004E:  GOTO   04D
004F:  MOVWF  19
....................       printf("  ");
0050:  MOVLW  20
0051:  BTFSS  0C.4
0052:  GOTO   051
0053:  MOVWF  19
0054:  MOVLW  20
0055:  BTFSS  0C.4
0056:  GOTO   055
0057:  MOVWF  19
....................    }
0058:  GOTO   02C
.................... }
....................
0059:  SLEEP

Configuration Fuses:
   Word  1: 3F72   HS NOWDT PUT NODEBUG NOPROTECT BROWNOUT NOLVP NOCPD NOWRT

_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Guest








PostPosted: Sat Jan 08, 2005 4:29 pm     Reply with quote

I realized that the problem is my circuit. when I send data from the PIC, everything works fine. When the PC sends data, the PIC seems not to receive the data. (The pic gets 0x00 for any character)

I also realized that when I power down my circuit, as the voltage is decreasing, If I keep pressing keys, the PIC echoes the characters that I press for about half a second before completely powering down.

The problem might be with the capacitors that I am using.

Here is how my MAX232 is hooked up:
PIN 1 and 3 are connected through a 10uF cap
PIN 4 and 5 are connected through a 10uF cap
PIN 6 is connected to ground through a 20uF cap
PIN 2 is connected to 5V through a 20uF cap

other tx and rx pins are correctly connected.

What do you think?
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Sat Jan 08, 2005 6:37 pm     Reply with quote

Double check the polarity of the capacitors.
_________________
David
Guest








masterchief
PostPosted: Sat Jan 08, 2005 6:56 pm     Reply with quote

I am using ceramic disc capacitors, they don't have polarity. So, the problem is probably somewhere else...
Guest








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

Before I press anything, the pin R2out (TTL) of the MAX232 chip that goes to the rx pin on the chip is high (5V).

When I press a key, the pin goes and stays to zero. Besides, the terminal shows me "You pressed ". there is no key code, The PIC just receives a 0x00 iinstead of the keycode.

Is this behavior normal, I dont think so.
Any suggestions? Thanks in advance
dyeatman



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

View user's profile Send private message

Sounds like a MAX232 problem
PostPosted: Sat Jan 08, 2005 10:18 pm     Reply with quote

The MAX232 (R2out) output should return to the original high state after the character(s) come in.

What does the input pin on the MAX232 do? Does it return to low when the incoming char(s) are complete?

Since there is no enable on this chip the input and output states MUST ALWAYS be opposite (i.e if input R2in high then the output R2out must be low). If they are ever the same something is definitely wrong and I would suspect a wiring error since it seems to start out properly.

Check all the connections making sure all the caps, especially the ones to pins 2 and 6, are wired properly.
Guest








masterchief
PostPosted: Sat Jan 08, 2005 11:03 pm     Reply with quote

the voltage on pin R2IN is about -10.5V
while the voltage on pin R2OUT is 0
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 08, 2005 11:18 pm     Reply with quote

Quote:
I am using ceramic disc capacitors

PIN 1 and 3 are connected through a 10uF cap
PIN 4 and 5 are connected through a 10uF cap
PIN 6 is connected to ground through a 20uF cap
PIN 2 is connected to 5V through a 20uF cap

To my knowledge, ceramic disk capacitors are not
available in the uF range. They are only available
in the pf or nF range. Are you certain that your
capacitors are 10uF, etc. ?
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 11:28 pm     Reply with quote

MAX232 datasheet suggest to use 0.1uF to 1.0uF (page 17). I always use 0.1uF caps with MAX232 myself.

Oh, by the way, in your test circuit do you sink or source current from/to the LED?

Nick
Guest








PostPosted: Sat Jan 08, 2005 11:29 pm     Reply with quote

That was my problem. I was dealing with picofarads instead of micro farads.
Thank you very much. I lack experience, but I am gaining it with people like you.

Thank you to all the people who helped
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