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

Double Control with two different timer but how?

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



Joined: 22 Mar 2011
Posts: 7

View user's profile Send private message MSN Messenger

Double Control with two different timer but how?
PostPosted: Fri Apr 01, 2011 3:24 am     Reply with quote

Hi!

I'm newbie on PIC programming.

I want to prepare little project as below.

I want to control two different leds with two button with a two different timer (timer0 and timer1) but How can i do this i don't know?? Can somebody give to me little examples for about this?

Thank you!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 01, 2011 1:21 pm     Reply with quote

I'll tell you how to do it.

Use the button command program here:
http://www.ccsinfo.com/forum/viewtopic.php?t=23837

Instead of calling printf() as shown in that program, you can setup
a timer and turn it on. Use CCS functions to do this, as described
in the CCS manual. Also, turn on the LED. And then, enable interrupts
for the Timer, including Global interrupts.

After some time passes, the timer will count up and "roll over" to 0.
It will generate an interrupt and execute the interrupt service routine
code. You need to create this interrupt routine in your program.
(You need separate routines for Timer0 and Timer1). Then, inside the
interrupt routine, you need to disable the interrupt for the Timer and
turn off the LED.

I don't want to write this program for you. I also don't want to teach you
the C lanuage. You need to learn C outside of this forum. And you
need to write the program by yourself. We can help you to debug it, but
you must learn C and do most of the work.
mierdogan



Joined: 22 Mar 2011
Posts: 7

View user's profile Send private message MSN Messenger

PostPosted: Fri Apr 01, 2011 2:44 pm     Reply with quote

PCM programmer wrote:
I'll tell you how to do it.

Use the button command program here:
http://www.ccsinfo.com/forum/viewtopic.php?t=23837

Instead of calling printf() as shown in that program, you can setup
a timer and turn it on. Use CCS functions to do this, as described
in the CCS manual. Also, turn on the LED. And then, enable interrupts
for the Timer, including Global interrupts.

After some time passes, the timer will count up and "roll over" to 0.
It will generate an interrupt and execute the interrupt service routine
code. You need to create this interrupt routine in your program.
(You need separate routines for Timer0 and Timer1). Then, inside the
interrupt routine, you need to disable the interrupt for the Timer and
turn off the LED.

I don't want to write this program for you. I also don't want to teach you
the C lanuage. You need to learn C outside of this forum. And you
need to write the program by yourself. We can help you to debug it, but
you must learn C and do most of the work.


Thank you for your advice...

Best Regards
mierdogan



Joined: 22 Mar 2011
Posts: 7

View user's profile Send private message MSN Messenger

PostPosted: Wed Apr 06, 2011 3:04 pm     Reply with quote

PCM programmer wrote:
I'll tell you how to do it.

Use the button command program here:
http://www.ccsinfo.com/forum/viewtopic.php?t=23837

Instead of calling printf() as shown in that program, you can setup
a timer and turn it on. Use CCS functions to do this, as described
in the CCS manual. Also, turn on the LED. And then, enable interrupts
for the Timer, including Global interrupts.

After some time passes, the timer will count up and "roll over" to 0.
It will generate an interrupt and execute the interrupt service routine
code. You need to create this interrupt routine in your program.
(You need separate routines for Timer0 and Timer1). Then, inside the
interrupt routine, you need to disable the interrupt for the Timer and
turn off the LED.

I don't want to write this program for you. I also don't want to teach you
the C lanuage. You need to learn C outside of this forum. And you
need to write the program by yourself. We can help you to debug it, but
you must learn C and do most of the work.


Hi!!,


You can find my new code below,

When i was try compile this code, ccs c compiler gives to me error code for two lines as below

Error 49 ""timer.c"Line 46(15,16): Expecting LVALUE such as a variable name or * expression


Error 49 ""timer.c"Line 55(15,16): Expecting LVALUE such as a variable name or * expression

Code:
#include <16F877.h>
#fuses HS,NOWDT,PUT,PROTECT,NOLVP
#fuses NODEBUG,NOBROWNOUT,NOWRT,NOCPD
#use delay(clock=20000000)


#define BUTON1   PIN_B0
#define BUTON2   PIN_B1
#define LED1   PIN_B2
#define LED2    PIN_B3

int counter;
boolean Led1Enable, Led2Enable;

#int_timer0
void timer0isr()
{
   if(++Counter >= 25)
   {
      Counter = 0;
      if(Led1Enable)
         output_toggle(LED1);

      if(Led2Enable)
         output_toggle(LED2);
   }
}

void main(void)
{

      Led1Enable = FALSE;
   Led1Enable = FALSE;

      setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);

      enable_interrupts(INT_TIMER0);
      enable_interrupts(GLOBAL);

      while(TRUE)
      {
      if (!input(BUTON1))
      {
      Led1Enable = TRUE;
         Led2Enable = FALSE;
         LED2 = 0;
         while(!input(BUTON1))
               ;
      }

      if (!input(BUTON2))
      {
         Led1Enable = FALSE;
         Led2Enable = TRUE;
         LED1 = 0;
            while(!input(BUTON2))
               ;
      }
   }
}


Could you check this please?

Than you so much

Best Wishes
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed Apr 06, 2011 3:38 pm     Reply with quote

in place of this:
Code:
LED2 = 0;


Use this:
Code:
output_low(LED2);

_________________
Google and Forum Search are some of your best tools!!!!
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