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

Problems with timer1

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



Joined: 24 Mar 2004
Posts: 53
Location: Portugal

View user's profile Send private message Send e-mail MSN Messenger

Problems with timer1
PostPosted: Thu Apr 15, 2004 1:52 am     Reply with quote

Timer 0 and Timer 1

my program have a Timer clock and a keypad
and have problems with timer 1 to read the Keypad.

16F877


Code:

#int_timer0
timer0_isr()
{
   clock -= 256;
   if (clock<256) //<256
   {
      //seconds++;
      clock += CLOCK_VAL;
      tick = 1;
   }
}

#int_timer1
timer1_isr()
{
  // Decrement any timers that are running.
if(gc_buttons_timer)
   gc_buttons_timer--;

}

//...//

void check_buttons(void)
{

char gc_old_button_status;

if(gc_buttons_timer)
   return;
else
  gc_buttons_timer = BUTTONS_TIMER_TICKS;

       keyb=kbd_getc();
        if(keyb!=0)
        {
        printf("A tecla é: %c\r\n",keyb);
        printf(lcd_putc,"\nNum-%02c ",keyb);;
        }     // Read the buttons


}

//...//


main()
{
   int conta;
   gc_buttons_timer = BUTTONS_TIMER_TICKS;
   lcd_init();

   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_64); //
   setup_timer_1( T1_INTERNAL | T1_DIV_BY_1 );
   enable_interrupts(int_timer0); // Enable timer0 interrupt
   enable_interrupts(int_timer1);
   enable_interrupts(GLOBAL);     // Enable global interrupts   
   


   while(1)
   {
      if (tick)
      {
         tick=0;
         //lcd_gotoxy(1,1);
         //printf(lcd_putc,"%02u",seconds);
         update_clock();
         seconds++;
     
      }
          check_buttons();
   
   }
}



Ttelmah
Guest







Re: Problems with timer1
PostPosted: Thu Apr 15, 2004 2:20 am     Reply with quote

carlosma wrote:
Timer 0 and Timer 1

my program have a Timer clock and a keypad
and have problems with timer 1 to read the Keypad.

16F877


Code:

#int_timer0
timer0_isr()
{
   clock -= 256;
   if (clock<256) //<256
   {
      //seconds++;
      clock += CLOCK_VAL;
      tick = 1;
   }
}

#int_timer1
timer1_isr()
{
  // Decrement any timers that are running.
if(gc_buttons_timer)
   gc_buttons_timer--;

}

//...//

void check_buttons(void)
{

char gc_old_button_status;

if(gc_buttons_timer)
   return;
else
  gc_buttons_timer = BUTTONS_TIMER_TICKS;

       keyb=kbd_getc();
        if(keyb!=0)
        {
        printf("A tecla é: %c\r\n",keyb);
        printf(lcd_putc,"\nNum-%02c ",keyb);;
        }     // Read the buttons


}

//...//


main()
{
   int conta;
   gc_buttons_timer = BUTTONS_TIMER_TICKS;
   lcd_init();

   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_64); //
   setup_timer_1( T1_INTERNAL | T1_DIV_BY_1 );
   enable_interrupts(int_timer0); // Enable timer0 interrupt
   enable_interrupts(int_timer1);
   enable_interrupts(GLOBAL);     // Enable global interrupts   
   


   while(1)
   {
      if (tick)
      {
         tick=0;
         //lcd_gotoxy(1,1);
         //printf(lcd_putc,"%02u",seconds);
         update_clock();
         seconds++;
     
      }
          check_buttons();
   
   }
}




It would help if you actually said what the 'problems' were. The listing, does not contain enough of the code to show how the system works....
Some obvious comments though do apply.
You declare a variable 'gc_old_button_status', locally inside a routine. This is not used in the code shown, but is presumably used to hold the 'old' key pattern, so that you can check for changes?. If so, this _must_ be 'static'. Otherwise it's contents may be lost between calls to the routine...
You don't show the 'update clock' function you call.
Remember that the variable 'clock', must be a 'long'.
As shown, the code will not use the 'gc_buttons_timer' to control the keyboard scan. Remember that a 'if', or an 'else', executes just the next 'statement'. You have seven lines of code in the area that is presumably meant to be the 'else', but only the first will be executed as the 'else' condition. The rest will be executed on each call. The stuff that is meant to comprise the 'else' statement, should be bracketted {} to turn it into a single functional statement.

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