|
|
View previous topic :: View next topic |
Author |
Message |
carlosma
Joined: 24 Mar 2004 Posts: 53 Location: Portugal
|
Problems with timer1 |
Posted: Thu Apr 15, 2004 1:52 am |
|
|
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 |
Posted: Thu Apr 15, 2004 2:20 am |
|
|
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 |
|
|
|
|
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
|