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

PIC16877A CCS how to make the program will only printf 1?

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



Joined: 02 Nov 2011
Posts: 8

View user's profile Send private message

PIC16877A CCS how to make the program will only printf 1?
PostPosted: Fri Nov 11, 2011 8:44 pm     Reply with quote

PIC16877A CCS how to make the program will only printf 1 time?
I wish to make the code below will only execute "printf" one time. How should I edit the code below ?
thanks
Code:
while(1)
{

if((input(pin_a0)==1) && (input(pin_a1)==1) && (input(pin_a2)==1))
{
delay_ms(1000);
lcd_putc("\fPL available:0");
delay_ms(1000);


printf("\fPL available:0");
delay_ms(1000);
}

else if((input(pin_a0)==0) && (input(pin_a1)==0) && (input(pin_a2)==0))
{
delay_ms(1000);
lcd_putc("\fPL available:3");
delay_ms(2000);
lcd_putc("\fPL1-empty");
lcd_putc("\nPL2-empty");
delay_ms(1000);
lcd_putc("\fPL3-empty");
delay_ms(1000);

printf("\fPL available:3");
delay_ms(1000);
}


}
Ttelmah



Joined: 11 Mar 2010
Posts: 19327

View user's profile Send private message

PostPosted: Sat Nov 12, 2011 3:09 am     Reply with quote

Something like:
Code:

//Learn to indent - makes code easier to follow....
int1 done=FALSE; //with your variable declarations


do {
    if((input(pin_a0)==1) && (input(pin_a1)==1) && (input(pin_a2)==1)) {
       delay_ms(1000);
       lcd_putc("\fPL available:0");
       delay_ms(1000);


       printf("\fPL available:0");
       delay_ms(1000);
       done=TRUE;
     }
     else if((input(pin_a0)==0) && (input(pin_a1)==0) &&  \
     (input(pin_a2)==0)) {
       delay_ms(1000);
       lcd_putc("\fPL available:3");
       delay_ms(2000);
       lcd_putc("\fPL1-empty");
       lcd_putc("\nPL2-empty");
       delay_ms(1000);
       lcd_putc("\fPL3-empty");
       delay_ms(1000);

       printf("\fPL available:3");
       delay_ms(1000);
       done=TRUE;
   }
} while (!done);


So the loop exits, when 'done' goes TRUE.

If this is the main, the chip will drop through to a hidden 'sleep' after the code, and stop running. Otherwise add whatever else you want to happen here.

Best Wishes
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