|
|
View previous topic :: View next topic |
Author |
Message |
odt133
Joined: 27 May 2016 Posts: 1
|
printf print broken message |
Posted: Fri May 27, 2016 2:55 am |
|
|
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
|
|
Posted: Fri May 27, 2016 4:04 am |
|
|
Check the basics:-
Is the LED flashing at the correct rate?
Keith |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Fri May 27, 2016 4:47 am |
|
|
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: 9226 Location: Greensville,Ontario
|
|
Posted: Fri May 27, 2016 11:06 am |
|
|
also there needs to be a 'MAX232', TTL<>USB' or similar interface between PIC and PC.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Fri May 27, 2016 11:27 am |
|
|
and (of course) to give 40MHz, the crystal needs to be 10MHz. Back to 'does the LED flash at the correct rate'. |
|
|
|
|
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
|