Problem with CCS PIC programming

Status
Not open for further replies.

Jack// ani

Advanced Member level 3
Joined
Dec 2, 2004
Messages
757
Helped
107
Reputation
222
Reaction score
58
Trophy points
1,308
Activity points
5,006
Hi all,

I’ve written this simple program to count 1 to 25 and display the result on RS232 terminal software

#include <16F84A.H>
#fuses XT,NOWDT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2)
void main()
{
int i;
while(true)
{
i=1;
printf("RESET");
for(i=1;i<=25;i++)
{
printf("\nNumber is : ",i);
delay_ms(400);
}
}
}

But I can only see “Number is :” at the output, the numbers digits are missing! And after 25 times I get “RESET” as expected and everything repeats again. What could be the problem? Please help me.

Thanks
 

printf("\nNumber is : ",i); ---> printf("\nNumber is : %d",i);
 

this was one of disadvantages with C. although you have declared "i" as an int but you will have to tell again that it is an int when you use the printf command. if you use C++ you dont have to do this. but that is a different story and you wont be using C++ on a PIC.

like i have always recommended i would recommend you to first practice with C on a PC. get a good book like "The C Programming Language" by K&R and try some example programs. then move on to C for PICs.
 

I know C very well, but for quite long time I have not done any practice. Infact I came across a wrong example which was having such statement. I expected it should give some error, and went on further blindly. Anyway thanks for reply
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…