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

new user

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



Joined: 01 Jun 2011
Posts: 4

View user's profile Send private message

new user
PostPosted: Wed Mar 21, 2012 6:40 am     Reply with quote

I am a new user and i would like to ask you that :
I have this code and i want to stuck the prog when it print the "LOW" or "HIGH" condition, not to running all the time. How can i do that?


Code:

main()
{
while(1)
{
if (input(pin_A0)==0)
   printf("\r\nLOW");
if (input(pin_A0)==1)
   printf("\r\nHIGH");
 
}
}
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Mar 21, 2012 7:11 am     Reply with quote

The while(1) is what makes it run continuously. However you need to keep the PIC running long enough to send the serial strings, so you can not stop the program right after the print statements.

You could remove the main while(1) loop and add a while(1) after each of the print statements. Then the PIC would boot, test the pin, print the appropriate message, and then stay in a loop forever. That sounds like what you want.

For better style you should look at using an if/else construction.
_________________
The search for better is endless. Instead simply find very good and get the job done.
nikolasvr



Joined: 01 Jun 2011
Posts: 4

View user's profile Send private message

PostPosted: Mon Mar 26, 2012 9:50 am     Reply with quote

I know about while(1), is it possible to have an example?
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

Re: new user
PostPosted: Mon Mar 26, 2012 10:17 am     Reply with quote

Code:

main()
{
if (input(pin_A0)==0)
   {
   printf("\r\nLOW");
   while(1);
   }
if (input(pin_A0)==1)
   {
   printf("\r\nHIGH");
   while(1);
   }
}


Code:

main()
{
if (input(pin_A0)==0)
   {
   printf("\r\nLOW");
   while(1);
   }
else
   {
   printf("\r\nHIGH");
   while(1);
   }
}

_________________
The search for better is endless. Instead simply find very good and get the job done.
nikolasvr



Joined: 01 Jun 2011
Posts: 4

View user's profile Send private message

PostPosted: Mon Mar 26, 2012 10:26 am     Reply with quote

I'm trying this code but when I change the state of input, it do nothing.....
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Mar 26, 2012 11:17 am     Reply with quote

Code:
main()
{
  while(1)// main loop
  {
    if(input(pin_A0) == 0)// if the input is LOW
    {
      printf("\r\nLOW");
      while(input(pin_A0) == 0)// stay here if the input is still LOW
        ;
    }

    if(input(pin_A0) == 1)// if the input is HIGH
    {
      printf("\r\nHIGH");
      while(input(pin_A0) == 1)// stay here if the input is still HIGH
        ;
    }
  }// end of while loop
}// end of main()
nikolasvr



Joined: 01 Jun 2011
Posts: 4

View user's profile Send private message

PostPosted: Mon Mar 26, 2012 11:01 pm     Reply with quote

Thank you very much my friend!!
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