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 problems using pic18f2525

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



Joined: 05 Nov 2006
Posts: 4
Location: Seattle, WA

View user's profile Send private message MSN Messenger

printf problems using pic18f2525
PostPosted: Sun Nov 05, 2006 12:30 am     Reply with quote

I am starting to develop a small embedded application using the PIC18F2525 MCU. I am experiencing some odd behavior using printf. Any strings I enter into the printf (such as something like printf("Hello world")) display perfectly. The characters I echo back all come accross fine, but whenever I try to display the contents of a variable, such as:

int8 x = 50;
printf("x = %d\n\r", x);

will show something like:

x = <garbage>

I've used the same compiler (I'm not exactly sure what version we have in the lab, but can post it tomorrow if it becomes relevant) with PIC16 devices, and haven't had the same problem.

Any help with this would be greatly appreciated. It has become a rather frustrating problem for me.

Leonard
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 05, 2006 12:49 am     Reply with quote

1. Post a very short test program that shows the problem.
2. Post your compiler version.
3. Are you testing this with hardware or a simulator ?
4. If hardware, describe the display device (Hyperterm, LCD, etc.).

This is an example of a test program:
Code:

#include <18F2525.h>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000) 
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//====================================
void main()
{
int8 x = 50;

printf("x = %d\n\r", x);

while(1);
}
lentracy



Joined: 05 Nov 2006
Posts: 4
Location: Seattle, WA

View user's profile Send private message MSN Messenger

PostPosted: Sun Nov 05, 2006 1:11 am     Reply with quote

Here is the program I was using for test. I am using a 20MHz oscillator, and reading the input on hyperterm. I tried several different baud rates, but all had the same results. I also experimented using different length integers. As I said before, I'm not 100% sure on the compiler version, but I'll be able to post it tomorrow.

#include <18F2525.h>
#device adc=8
#fuses NOWDT,WDT128,HS, NOPROTECT, IESO, BROWNOUT, BORV20, NOPUT, NOCPD, STVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, FCMEN, XINST, NOPBADEN, LPT1OSC, MCLR
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)

void main() {
int16 kp=50;
printf("TEST\n\rI initialized kp to 50\n\r");
printf("kp = %ld\n\rEND TEST\n\r\n\r", kp);

while(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 05, 2006 1:30 am     Reply with quote

Quote:

#fuses NOWDT,WDT128,HS, NOPROTECT, IESO, BROWNOUT, BORV20,
NOPUT, NOCPD, STVREN, NODEBUG, NOLVP, NOWRT, NOWRTD,
NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, FCMEN, XINST,
NOPBADEN, LPT1OSC, MCLR


The XINST fuse will enable the Extended Instruction Set. CCS doesn't
support this. The 18F2525 data sheet says this, in section 24.2.3:
Quote:

Enabling the PIC18 instruction set
extension may cause legacy applications
to behave erratically or fail entirely.

Change it to NOXINST.
lentracy



Joined: 05 Nov 2006
Posts: 4
Location: Seattle, WA

View user's profile Send private message MSN Messenger

PostPosted: Sun Nov 05, 2006 12:25 pm     Reply with quote

I'll give that a try. Thanks for your help.
lentracy



Joined: 05 Nov 2006
Posts: 4
Location: Seattle, WA

View user's profile Send private message MSN Messenger

PostPosted: Mon Nov 06, 2006 11:20 am     Reply with quote

That solved my problem, thank you. Does CCS version 4 support the extended instruction set? I realized that we are using 3.224 here.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 06, 2006 2:34 pm     Reply with quote

Quote:
Does CCS version 4 support the extended instruction set?

It's not listed in either current or future features.
http://www.ccsinfo.com/content.php?page=v4overview&refr=version4
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