View previous topic :: View next topic |
Author |
Message |
lz1ght
Joined: 27 Nov 2017 Posts: 3
|
[SOLVED]printf problem with integer |
Posted: Tue Nov 28, 2017 11:09 pm |
|
|
Hi,
I have a strange problem with PIC18F4520.
Compiler now is 5.047 demo, but I try first with 5.049, 5.019 and 4.???
I also try with int16, int32. Result is same.
Code: | #include <main.h>
int i=0;
void main() {
for ( i = 32; i < 80; i++) {
printf ( "Char %c Dec %d Uns %u \r\n", i, i, i);
}
while(TRUE) { }
} |
Results is:
Quote: | Char Dec 0 Uns 0
Char ! Dec 0 Uns 0
Char " Dec 0 Uns 0
Char # Dec 0 Uns 0
Char $ Dec 0 Uns 0
Char % Dec 0 Uns 0
Char & Dec 0 Uns 0 |
I change MCU with PIC16F877A and all is normal. Any idea?
Thanks,
Georgi.
Last edited by lz1ght on Wed Nov 29, 2017 12:05 pm; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19561
|
|
Posted: Wed Nov 29, 2017 2:22 am |
|
|
Show us your fuses. main.h.
I'd guess something like you have XINST selected (which will cause peculiar oddities through the program). May even be selected by default. Doesn't apply with a PIC16, but does with a PIC18. So make sure you have the NOXINST fuse selected. |
|
|
lz1ght
Joined: 27 Nov 2017 Posts: 3
|
|
Posted: Wed Nov 29, 2017 11:54 am |
|
|
main.h
Code: | #include <18F4520.h>
//#include <16F877A.h>
#device ADC=10
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(crystal=18432000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,STOP=1)
|
Now result is:
Quote: | Char Dec 1<8 Uns 1<0
Char ! Dec 1<8 Uns 1<0
Char " Dec 1<8 Uns 1<0
Char # Dec 1<8 Uns 1<0
Char $ Dec 1<8 Uns 1<0
Char % Dec 1<8 Uns 1<0
Char & Dec 1<8 Uns 1<0
.........
......... |
|
|
|
lz1ght
Joined: 27 Nov 2017 Posts: 3
|
SOLVED |
Posted: Wed Nov 29, 2017 12:05 pm |
|
|
Many Thanks Ttelmah
I use bootloader and he don't change fuses.
Now is OK. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19561
|
|
Posted: Wed Nov 29, 2017 12:41 pm |
|
|
The bootloader can never change fuses.
Problem is if it changes the fuses then these can stop it running.
This is why it is vital to ensure that you program the bootloader with the fuses you intend to finally use, and you then have the code you load with the bootloader without any fuses (#FUSES NONE).
Anyway at least you now know what the problem was. |
|
|
|