View previous topic :: View next topic |
Author |
Message |
filodendron Guest
|
Bug in printf command??? |
Posted: Thu Feb 02, 2006 3:54 pm |
|
|
My program:
Code: |
#include <16F876A.h>
#device *=16
#use delay(clock=20000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
void main()
{
int8 a=10, b=100;
printf("a = %d\n",a);
printf("b = %d\n",b);
delay_ms(10);
}
|
Result:
aaaa10
b = 100
First string is BAD!!!
Second string is OK.
Why??? |
|
|
Ttelmah Guest
|
|
Posted: Thu Feb 02, 2006 4:03 pm |
|
|
Unless you pull the signal line high, and (assuming you are using a MAX232), wait a while for it's capacitor charge pump to get going, the signal being received by a computer connected at the other end, will be 'indeterminate' for a while when the PIC starts....
I'd suspect this is resulting in the computer 'missing' the correct edge in the first character, and returning garbage for a moment.
Best Wishes |
|
|
filodendron Guest
|
|
Posted: Thu Feb 02, 2006 8:40 pm |
|
|
Code: |
#include <16F876A.h>
#device *=16
#use delay(clock=20000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
void main()
{
int8 a=10, b=100;
printf("a = %d\n",a);
printf("b = %d\n",b);
printf("a = %d\n",a); //repeated first command
delay_ms(10);
}
|
The result of this modified code is:
aaaa10
b = 100
aaaa10
I don't understand about it. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 02, 2006 9:07 pm |
|
|
Post your #fuses statement. |
|
|
Eugeneo
Joined: 30 Aug 2005 Posts: 155 Location: Calgary, AB
|
|
Posted: Fri Feb 03, 2006 12:15 am |
|
|
That's strange. Have you tried a couple other variations? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Feb 03, 2006 1:56 am |
|
|
Strange results, but as PCM programmer already asked you, please post your #fuses statement. You are running at 20MHz and the default fuses don't work in that situation, you require at least the HS crystal fuse.
What is your compiler version? Without that we can't check for the same results. |
|
|
filodendron Guest
|
|
Posted: Fri Feb 03, 2006 3:02 am |
|
|
I am working with the PIC bootloader (www.microchipc.com).
This contains:
Code: |
#define FOSC D'20000000' ; <<< set quartz frequence [Hz], max. 20 MHz
IF FOSC<=D'4000000'
#define _MYCRYSTAL _XT_OSC ;see datasheet
ELSE
#define _MYCRYSTAL _HS_OSC
ENDIF
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _MYCRYSTAL & _WRT_OFF & _LVP_OFF & _DEBUG_OFF & _CPD_OFF
|
I have the latest version of the compiler (3.242). |
|
|
|