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

printf print broken message

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



Joined: 27 May 2016
Posts: 1

View user's profile Send private message

printf print broken message
PostPosted: Fri May 27, 2016 2:55 am     Reply with quote

Hello,
Could anybody tell me what I did wrong?
I'm trying to use printf(). but not working properly.
Source code is like this.

Code:
#include "C:\Program Files (x86)\picc\devices\18F6520.h"

#use delay(clock=40000000)
#USE RS232(uart1, baud=9600, bits=8, parity=n)

#fuses H4,OSCSEN,BROWNOUT,BORV27,NOWDT,NOPROTECT,CCP2E7//config set1

void main( void )
{
   while( true )
   {
      printf("led on.\r\n");
      output_high( pin_f7 );
      delay_ms(1000);
      printf("led off.\r\n");
      output_low( pin_f7 );
      delay_ms(1000);
   }
}


and result from Tera Term is like this.

Code:
?幢
    슊+?幢
           +?幢
                슊+?幢
                       +?




As you see, character is broken. I set tera term's baudrate as 9600.

What did I wrong? Please,,

Thank you in advance.
kWoody_uk



Joined: 29 Jan 2015
Posts: 47
Location: United Kingdom

View user's profile Send private message

PostPosted: Fri May 27, 2016 4:04 am     Reply with quote

Check the basics:-

Is the LED flashing at the correct rate?


Keith
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Fri May 27, 2016 4:47 am     Reply with quote

kWoody_uk wrote:

Is the LED flashing at the correct rate?


Almost certainly not. The order of things is not right. Should be device.h, fuses, delay, then rs232 and the like (timers etc), then do user code.

Code:
#include <18F6520.h> // Use <> and select the right path in the project.

// Fuses MUST come before delay and use rs232, and they must come after the processor include. I have not checked these fuses are sensible.
#fuses H4,OSCSEN,BROWNOUT,BORV27,NOWDT,NOPROTECT,CCP2E7//conf

#use delay(clock=40000000)

// Use rs232 must come after use delay.
#USE RS232(uart1, baud=9600, bits=8, parity=n)

// Then other stuff.
 
temtronic



Joined: 01 Jul 2010
Posts: 9163
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri May 27, 2016 11:06 am     Reply with quote

also there needs to be a 'MAX232', TTL<>USB' or similar interface between PIC and PC.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19338

View user's profile Send private message

PostPosted: Fri May 27, 2016 11:27 am     Reply with quote

and (of course) to give 40MHz, the crystal needs to be 10MHz. Back to 'does the LED flash at the correct rate'.
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