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

Play with timer

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







Play with timer
PostPosted: Wed Mar 04, 2009 10:33 am     Reply with quote

Hi..I'm newbie new in PIC programing. My lecturer give me an assignment to develop a timer circuit. The situation is like this:

Initial condition: LED0 turn ON

When i push a button for 5 second: LED1 turn ON.
IF i hold for another 10 second: LED1 and LED2 turn ON.

If i release before 10 or 5 second, LED0 return ON.

I try using some example but don't know how to implement timer inside my coding.

Code:

void main()
{
   set_tris_b (0);
   set_tris_b (0);
   set_tris_c (0xff);
   
   do
   {

      if(portb = 0b00000001)
      {
         portc = 0b00000001;
         delay_ms(5000);
         portc = 0b00000010;
         delay_ms(10000);
         portc = 0b00000110;
         break;
      } 
         
      else if(portb = 0b00000000)
      {
         portc = 0b00000001;

      }   

         
     
   }while(true);
}





Can anybody show me how to use timer inside my coding? tq Embarassed
Sydney



Joined: 13 Feb 2009
Posts: 71

View user's profile Send private message

PostPosted: Wed Mar 04, 2009 11:02 am     Reply with quote

This should get you started

Code:
#define BUT0 PIN_B0
#define LED0 PIN_C0
#define LED1 PIN_C1
#define LED2 PIN_C2

void main(void){
   int16 time = 0;
   while(input(BUT0)){
      if(++time > 500)
         output_high(LED1);
      else if(time > 1000)
         output_high(LED2);
      delay_ms(10);
   }
}
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