Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I@R @VR problem with a code

Status
Not open for further replies.

7rots51

Advanced Member level 4
Joined
May 17, 2002
Messages
1,183
Helped
25
Reputation
50
Reaction score
12
Trophy points
1,318
Activity points
9,636
Hi
when I make a project with below code with I@R @VR c0mpiler (cpu:at90s8515) and debug it with $py ,I see that the program exit the while loop !!! without any reason.if I change sprintf to printf ,there is no problem.

Is this my problem or is c0mpiler problem?



#include "stdio.h"
void main(void)
{
unsigned int kkk;
char bufff[6];

bufff[5] = 0;

while(1){
kkk = 1234;
sprintf (bufff,"%u", kkk);
}
}
 

Hi,

did you try to change the while-loop into a for-loop?
I remember i had a similar problem and with a for-loop the problem was solved.

regards
 

it could be the case your string is not enough to hold entire output forvalue of kkk . As your string buff is defined as stack variable , when output is done sprintf could overide the stack and lead to corruption , then behaviour is undefined .
Incrcease buff size up to 20 let say and try again .
 

In IAR C-SPY 2.28a, uC set is ATmega128, all works fine....
 

Hi,

You may need to implement the printf function, or 'stub' it
out, e.g. this is the prontf function that I use, I make a back-up and
modify the existing 'printf.c' file which is in one of
the IAR directories (INC I think):


static void put_one_char(char c, void *dummy)
{
tx_byte(PRINT_PORT,c);
/* or comment the above line out if you are using c-spy */
} /* Warning on this line OK (unused 'dummy') */


int printf (const char *format, ...) /* Our main entry */
{
va_list ap;
int nr_of_chars;

va_start (ap, format); /* Variable argument begin */
nr_of_chars = _formatted_write (format, put_one_char, (void *) 0, ap);
va_end (ap); /* Variable argument end */
return (nr_of_chars); /* According to ANSI */
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top