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

[SOLVED]printf problem with integer

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



Joined: 27 Nov 2017
Posts: 3

View user's profile Send private message

[SOLVED]printf problem with integer
PostPosted: Tue Nov 28, 2017 11:09 pm     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Wed Nov 29, 2017 2:22 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 29, 2017 11:54 am     Reply with quote

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

View user's profile Send private message

SOLVED
PostPosted: Wed Nov 29, 2017 12:05 pm     Reply with quote

Many Thanks Ttelmah

I use bootloader and he don't change fuses.

Now is OK.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Nov 29, 2017 12:41 pm     Reply with quote

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. Smile
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