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

gets() not working with PIC18LF2550

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



Joined: 30 Nov 2009
Posts: 7

View user's profile Send private message

gets() not working with PIC18LF2550
PostPosted: Fri Mar 19, 2010 11:06 pm     Reply with quote

Hi All,

Using PCHL 4.101; 7/1/2009

gets() seems to be hanging and I am not sure what is going on.

Test code:

Code:
#include <18F2550.h>

#fuses INTRC_IO,CPUDIV1,NOWDT,NOPROTECT
#use delay(clock=8MHZ,RESTART_WDT)
#use rs232(uart1, baud=57600)

void main() {
   char cmd[30];
   while (TRUE){
      printf("enter string: ");
      //cmd[0] = getc();
      gets(cmd);
      printf("you entered: %s(%x)\r\n", cmd, cmd[0]);
         }
}


this code locks up does not detect RETURN (0x0D).

test code 2:

Code:
#include <18F2550.h>

#fuses INTRC_IO,CPUDIV1,NOWDT,NOPROTECT
#use delay(clock=8MHZ,RESTART_WDT)
#use rs232(uart1, baud=57600)

void main() {
   char cmd[30];
   while (TRUE){
      printf("enter string: ");
      cmd[0] = getc();
      //gets(cmd);
      printf("you entered: %s(%x)\r\n", cmd, cmd[0]);
         }
}


This code accepts characters fine, for example if you hit 'e' it prints out:
'you entered: e(65)'

And if you hit the enter key, it prints:

'you entered: (0D).

So my serial link is working, and the chip detects a return, but the gets() does not.

Any ideas?

Cheers,
Nigel
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 21, 2010 2:00 pm     Reply with quote

You're using the Linux version of the compiler. I don't think the version
numbers of the Linux compiler track with the Windows version. So I
don't think I can duplicate your environment.

Can you compile a stripped down version of your code, as shown below,
and post the .LST file. Then I can look at it and see if it's doing
something wrong.
Code:

#include <18F2550.h>
#fuses INTRC_IO,CPUDIV1,NOWDT,NOPROTECT
#use delay(clock=8MHZ,RESTART_WDT)
#use rs232(uart1, baud=57600)

//===============================
void main()
{
char cmd[30];

while(1)
  {
   gets(cmd);
   printf("%s(%x)\r\n", cmd, cmd[0]);
  }
}
big_nige



Joined: 30 Nov 2009
Posts: 7

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 12:59 am     Reply with quote

As requested:

Code:
CCS PCH C Compiler, Version 4.101, 51450               22-Mar-10 17:56

               Filename: /home/nigel/redearth/smseries/test_ccs.lst

               ROM used: 218 bytes (1%)
                         Largest free fragment is 32550
               RAM used: 34 (2%) at main() level
                         36 (2%) worst case
               Stack:    1 locations

*
0000:  GOTO   0060
.................... #include <18F2550.h>
.................... //////// Standard Header file for the PIC18F2550 device ////////////////
.................... #device PIC18F2550
.................... #list
.................... 
.................... #fuses INTRC_IO,CPUDIV1,NOWDT,NOPROTECT
.................... #use delay(clock=8MHZ,RESTART_WDT)
.................... #use rs232(uart1, baud=57600)
.................... 
.................... //===============================
.................... void main()
.................... {
0060:  CLRF   FF8
0062:  BCF    FD0.7
0064:  CLRF   FEA
0066:  CLRF   FE9
0068:  MOVLW  70
006A:  MOVWF  FD3
006C:  MOVF   FD3,W
006E:  BSF    FB8.3
0070:  MOVLW  22
0072:  MOVWF  FAF
0074:  MOVLW  00
0076:  MOVWF  FB0
0078:  MOVLW  A6
007A:  MOVWF  FAC
007C:  MOVLW  90
007E:  MOVWF  FAB
0080:  MOVF   FC1,W
0082:  ANDLW  C0
0084:  IORLW  0F
0086:  MOVWF  FC1
0088:  MOVLW  07
008A:  MOVWF  FB4
.................... char cmd[30];
.................... 
.................... while(1)
....................   {
....................    gets(cmd);
008C:  CLRF   FEA
008E:  MOVLW  05
0090:  MOVWF  FE9
0092:  DECF   FE9,F
0094:  BTFSS  F9E.5
0096:  BRA    0094
0098:  MOVFF  FAE,FEE
009C:  MOVLW  0D
009E:  SUBWF  FEF,W
00A0:  BNZ   0092
00A2:  CLRF   FEF
....................    printf("%s(%x)\r\n", cmd, cmd[0]);
00A4:  CLRF   FEA
00A6:  MOVLW  05
00A8:  MOVWF  FE9
00AA:  BRA    0004
00AC:  MOVLW  28
00AE:  BTFSS  F9E.4
00B0:  BRA    00AE
00B2:  MOVWF  FAD
00B4:  MOVFF  05,23
00B8:  MOVLW  57
00BA:  MOVWF  24
00BC:  BRA    001C
00BE:  MOVLW  29
00C0:  BTFSS  F9E.4
00C2:  BRA    00C0
00C4:  MOVWF  FAD
00C6:  MOVLW  0D
00C8:  BTFSS  F9E.4
00CA:  BRA    00C8
00CC:  MOVWF  FAD
00CE:  MOVLW  0A
00D0:  BTFSS  F9E.4
00D2:  BRA    00D0
00D4:  MOVWF  FAD
....................   }
00D6:  BRA    008C
.................... } 
00D8:  SLEEP

Configuration Fuses:
   Word  1: C827   INTRC_IO IESO FCMEN PLL12 CPUDIV1 USBDIV
   Word  2: 1E3E   BROWNOUT NOWDT BORV20 PUT WDT32768 VREGEN
   Word  3: 8700   PBADEN CCP2C1 MCLR LPT1OSC
   Word  4: 0081   STVREN NODEBUG NOLVP NOXINST
   Word  5: C00F   NOPROTECT NOCPD NOCPB
   Word  6: E00F   NOWRT NOWRTD NOWRTC NOWRTB
   Word  7: 400F   NOEBTR NOEBTRB


Cheers,
Nigel
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 1:47 am     Reply with quote

I think gets() is buggy in your version. Try using get_string() in input.c
instead. The input.c file is in the CCS drivers directory. get_string()
requires that you supply the maximum buffer length.
big_nige



Joined: 30 Nov 2009
Posts: 7

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 2:35 am     Reply with quote

yeah - that fixed it.

I tried my own quick-and-dirty getc loop testing for ENTER key and it works too - so I would agree that there is a bug in the compiler somewhere.

Thanks for your help.

Nigel
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