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 does #use rs232 ENABLE=PIN not work with puts or printf

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



Joined: 05 Aug 2006
Posts: 149
Location: Redditch, UK

View user's profile Send private message Visit poster's website

Why does #use rs232 ENABLE=PIN not work with puts or printf
PostPosted: Sun Oct 08, 2006 1:08 am     Reply with quote

I have an odd problem with the way puts and printf are working when using the #use rs232 ENABLE feature. Basically I can see the output on Hyperterminal from the putc() but a string sent with puts() or printf() sends blanks. I am using SP485REN chip with B0 connected to the DE and /RE inputs.

The following prog compiled with 3.249 gives the following output.

Code:

// CPU Clock Freq
#define   FOSC   20000000
#define BAUDRT   9600

#include <16F876A.h>
#include <stdio.h>

#fuses HS,NOWDT,PUT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
#use delay(clock=FOSC)
#use rs232 (baud=BAUDRT, xmit=PIN_C6, rcv=PIN_C7, PARITY=N, BITS=8, ENABLE=PIN_B0)


void main()
{
   unsigned int ch ;

   putc('O') ;
   putc('k') ;
   putc('\r') ;
   putc('\n') ;

   puts("Hello from Puts") ;

   putc('H') ;
   putc('e') ;
   putc('l') ;
   putc('l') ;
   putc('o') ;
   putc('\r') ;
   putc('\n') ;

   while(1) {
      if (kbhit()) {
         ch = getc() ;
         putc(ch) ;
         if (ch == 0x31) {
            puts("Puts a long string to test the output") ;
            putc('N') ;
            putc('o') ;
            putc(' ') ;
            putc('1') ;
            putc('\r') ;
            putc('\n') ;
         }
      }
   }
}



The output on the terminal with me typing 1,2,3

Quote:
Ok
ts
Hello
1ut
No 1
23


I thought puts()/printf used putc at the bottom level ? However it seems to be doing the enable in a different way.

Any ideas ?
nurquhar



Joined: 05 Aug 2006
Posts: 149
Location: Redditch, UK

View user's profile Send private message Visit poster's website

PostPosted: Sun Oct 08, 2006 1:29 am     Reply with quote

I made a small mod and used my own puts which works ! Whats wrong with CCS version ?


Code:
// CPU Clock Freq
#define   FOSC   20000000
#define BAUDRT   9600

#include <16F876A.h>
#include <stdio.h>

#fuses HS,NOWDT,PUT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
#use delay(clock=FOSC)
#use rs232 (baud=BAUDRT, xmit=PIN_C6, rcv=PIN_C7, PARITY=N, BITS=8, ENABLE=PIN_B0)

char buf[40] ;

void myputs(char *str)
{
   for(; *str != 0 ; str++) {
      putc(*str) ;
   }
   putc('\r') ;
   putc('\n') ;
}

void main()
{
   unsigned int ch ;

   putc('O') ;
   putc('k') ;
   putc('\r') ;
   putc('\n') ;

//   puts("Hello from Puts") ;
   strcpy(buf, "Hello from Puts") ;
   myputs(buf) ;

   putc('H') ;
   putc('e') ;
   putc('l') ;
   putc('l') ;
   putc('o') ;
   putc('\r') ;
   putc('\n') ;

   while(1) {
      if (kbhit()) {
         ch = getc() ;
         putc(ch) ;
         if (ch == 0x31) {
//            puts("Puts a long string to test the output") ;
            strcpy(buf, "Puts a long string to test the output") ;
            myputs(buf) ;

            putc('N') ;
            putc('o') ;
            putc(' ') ;
            putc('1') ;
            putc('\r') ;
            putc('\n') ;
         }
      }
   }
}


Output for 1,2,3

Quote:
Ok
Hello from Puts
Hello
1Puts a long string to test the output
No 1
23

[/code]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 08, 2006 2:16 pm     Reply with quote

puts() is a macro that calls printf. Here's the macro definition
from stdlib.h.
Code:
#define puts(s) {printf(s); putchar(13); putchar(10);}

Here's the stdlib.h file location: c:\program files\picc\drivers\stdio.h

So the problem is in printf.

Here's a report in April 2005 of the same problem.
http://www.ccsinfo.com/forum/viewtopic.php?t=22421

It appears that 'enable' only works with putc(). So one way to do
a work-around would be to use the re-direction feature of the CCS
printf() function, and send the output to putc. Example:

Code:

#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, Enable=PIN_B0, ERRORS)

my_putc(char c)
{
putc(c);
}

//===================================
void main()
{
printf(my_putc, "Hello World");

while(1);
}

I looked at the .LST file, and this does work.
nurquhar



Joined: 05 Aug 2006
Posts: 149
Location: Redditch, UK

View user's profile Send private message Visit poster's website

PostPosted: Mon Oct 09, 2006 12:52 am     Reply with quote

Dear PCM

Thanks for confirming what I suspected. ie its a long standing CCS bug. Re-directing through "myputc" with printf(myputc, "xxx") is certanily a good work around, however it would be much better if CCS fixed it. I am guesing the fix will consume another valuable stack level. Especialy if you only have an level 8 stack to start with !

I'll post it as bug to CCS, you never know if may get fixed by April 2007.
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