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 CCS Technical Support

Strange error in printf?

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







Strange error in printf?
PostPosted: Mon Mar 13, 2006 3:19 pm     Reply with quote

Hi!

Have a 18f252 with 20Mhz crystal and this code:

#include "error.h"
unsigned CHAR TxPacket[80];
unsigned CHAR RxPacket[80];
//unsigned CHAR HxPacket[80];
int u;


void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_oscillator(False);
while(1)
{
delay_ms(1000);
printf("hello %d",u);
u++;
}

}


#include <18F252.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES PUT //Power Up Timer
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOCPD //No EE protection
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads

#use delay(clock=20000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)

If i remark the second 80 byte array the program work perfectly. Every second writeout 'hello' and the number. BUT if i use the second array the program will go into crazy, write out this text in FULL speed:
llo -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8hello -1<8

Anybody know why?
Thanks
Robi77
Guest







Comp version
PostPosted: Mon Mar 13, 2006 3:27 pm     Reply with quote

I tried out with 3.245, 3.242, 3.109
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 15, 2006 12:59 am     Reply with quote

Is that the entire program that causes the problem or is there more
code that you didn't post ?

It's possible that your code (code that's not posted) is writing past
the end of one of your arrays, and is clobbering some internal variables
used by the compiler. If you did this, it could cause the program to
go berzerk as you are seeing.



Other problems:

You have this fuse:
Quote:
#FUSES LVP

It's unlikely that you have a LVP programmer, so change it to:
Code:
#FUSES NOLVP

If you leave it as LVP, it could cause your program to lock up.

Here you are specifying 9-bit data:
Quote:

#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)

It's unlikely that your terminal program uses 9 bits. Most are set to
8-bits as the default. Also, no parity is the default. You don't need
to specify it. Finally, it's a good idea to use the ERRORS directive
to prevent the UART from locking up if you get a receive overrun error.
Example:
Code:
#use rs232(baud=19200,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
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