|
|
View previous topic :: View next topic |
Author |
Message |
Paul_B
Joined: 08 Sep 2003 Posts: 9 Location: Birmingham, UK
|
having probs with nested ints for debouncing....can anyone h |
Posted: Mon Mar 03, 2003 4:57 am |
|
|
Good morning everyone,
i'm having problems with the following routines, it displays the first two keypresses fine but then doesn't run after that.
i know it need tidying and maybe some commenting would help, but if anyone can spot anything obvious it would be a great help.
It is only reading the top row of the keypad for development purposes. Row =PIN_A1, 3xCOLS=PIN_B1, PIN_B2, PIN_B4.
PIN_A2 connected to LED for debugging.
Thanks in advance.
Here is part of the code then.
#bit TMR0IF = 0xb.2
#bit TMR1IF = 0xc.0
void display_key (char key_press);
char Key;
char key_press;
int flag=0;
int16 counter=0;
char main()
{
SETUP_ADC_PORTS( NO_ANALOGS );
set_tris_a(0x00);
set_tris_b(0x1f);
disable_interrupts ( GLOBAL );
setup_timer_0 ( RTCC_INTERNAL | RTCC_DIV_256 );
setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_8 );
enable_interrupts (INT_TIMER1);
enable_interrupts (INT_RTCC);
enable_interrupts ( GLOBAL );
disable_interrupts (INT_TIMER1);
lcd_init();
lcd_putc("\f");
delay_ms(100);
output_high(pin_a2);
delay_ms(100);
output_low(pin_a2);
do{
if (flag==1)
{
key_press=key;
display_key(key_press);
}
}
while(1);
}
#INT_RTCC
char TIMER_0_ISR( )
{
set_timer0(61);
output_low(pin_A2);
output_high(pin_a1);
if(input(pin_B1)){key='1';flag=1;}
if(input(pin_B2)){key='2';flag=1;}
if(input(pin_B4)){key='3';flag=1;}
output_low(pin_a1);
if(flag==1)
{
TMR1IF=0;
set_timer1(0xcf2c); //100ms
enable_interrupts(INT_TIMER1);
disable_interrupts(INT_RTCC);
// display_key(key);
}
}
void display_key (char key_press)
{
lcd_putc(key_press);
flag=0;
}
#INT_TIMER1
T1_ISR( )
{
set_timer1(0xcf2c); //100ms
counter++;;
if(counter==10)
{
TMR0IF=0;
output_high(pin_A2);
set_timer0(61);
enable_interrupts(INT_RTCC);
disable_interrupts(INT_TIMER1);
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12301 |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: having probs with nested ints for debouncing....can anyo |
Posted: Mon Mar 03, 2003 10:59 am |
|
|
Have a look at the code I posted yesterday about debouncing an input. You can use the same concept with your application.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12308 |
|
|
Paladdin Guest
|
Re: having probs with nested ints for debouncing....can anyo |
Posted: Tue Mar 04, 2003 7:02 am |
|
|
:=Good morning everyone,
:=
:=i'm having problems with the following routines, it displays the first two keypresses fine but then doesn't run after that.
:=
:=i know it need tidying and maybe some commenting would help, but if anyone can spot anything obvious it would be a great help.
:=
:=It is only reading the top row of the keypad for development purposes. Row =PIN_A1, 3xCOLS=PIN_B1, PIN_B2, PIN_B4.
:=
:=PIN_A2 connected to LED for debugging.
:=
:=Thanks in advance.
:=
:=Here is part of the code then.
:=
:=
:=
:=#bit TMR0IF = 0xb.2
:=#bit TMR1IF = 0xc.0
:=
:=void display_key (char key_press);
:=
:=char Key;
:=char key_press;
:=int flag=0;
:=int16 counter=0;
:=
:=char main()
:={
:=
:=SETUP_ADC_PORTS( NO_ANALOGS );
:=
:=set_tris_a(0x00);
:=set_tris_b(0x1f);
:=
:=
:=disable_interrupts ( GLOBAL );
:=
:=setup_timer_0 ( RTCC_INTERNAL | RTCC_DIV_256 );
:=setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_8 );
:=
:=enable_interrupts (INT_TIMER1);
:=enable_interrupts (INT_RTCC);
:=enable_interrupts ( GLOBAL );
:=disable_interrupts (INT_TIMER1);
:=lcd_init();
:=
:=lcd_putc("\f");
:=
:=delay_ms(100);
:=output_high(pin_a2);
:=delay_ms(100);
:=output_low(pin_a2);
:=
:=do{
:=if (flag==1)
:= {
:= key_press=key;
:= display_key(key_press);
:= }
:=
:=}
:=while(1);
:=
:=}
:=
:=
:=
:=#INT_RTCC
:=char TIMER_0_ISR( )
:={
:=set_timer0(61);
:=
:= output_low(pin_A2);
:=
:=output_high(pin_a1);
:=
:= if(input(pin_B1)){key='1';flag=1;}
:= if(input(pin_B2)){key='2';flag=1;}
:= if(input(pin_B4)){key='3';flag=1;}
:=
:=output_low(pin_a1);
:=
:=
:=if(flag==1)
:= {
:=
:= TMR1IF=0;
:= set_timer1(0xcf2c); //100ms
:=
:= enable_interrupts(INT_TIMER1);
:= disable_interrupts(INT_RTCC);
:=
:=// display_key(key);
:=
:= }
:=}
:=
:=
:=
:=void display_key (char key_press)
:={
:=
:= lcd_putc(key_press);
:=
:= flag=0;
:=
:=
:=
:=}
:=
:=
:=#INT_TIMER1
:=T1_ISR( )
:={
:=set_timer1(0xcf2c); //100ms
:=counter++;;
:=
:=if(counter==10)
:= {
:=
:= TMR0IF=0;
:= output_high(pin_A2);
:= set_timer0(61);
:=
:= enable_interrupts(INT_RTCC);
:= disable_interrupts(INT_TIMER1);
:=
:= }
:=
:=}
As I see set_tris functions... are you using fast IO? Then add at least a delay_cycles(1) between consecutive input or output settings -like the ones at the beginning of Timer0 ISR-. Without this precaution pins could overlap, as you may be attempting read of write a state depending of other pin, and that pin had had not enough time to stabilize... just an idea!
___________________________
This message was ported from CCS's old forum
Original Post ID: 12323 |
|
|
Hans Wedemeyer Guest
|
Re: having probs with nested ints for debouncing....can anyo |
Posted: Tue Mar 04, 2003 9:05 am |
|
|
Far too much code in the ISR ,
___________________________
This message was ported from CCS's old forum
Original Post ID: 12326 |
|
|
Paul_B
Joined: 08 Sep 2003 Posts: 9 Location: Birmingham, UK
|
Re: having probs with nested ints for debouncing....can anyo |
Posted: Tue Mar 04, 2003 3:34 pm |
|
|
:=Good morning everyone,
:=
:=i'm having problems with the following routines, it displays the first two keypresses fine but then doesn't run after that.
:=
:=i know it need tidying and maybe some commenting would help, but if anyone can spot anything obvious it would be a great help.
:=
:=It is only reading the top row of the keypad for development purposes. Row =PIN_A1, 3xCOLS=PIN_B1, PIN_B2, PIN_B4.
:=
:=PIN_A2 connected to LED for debugging.
:=
:=Thanks in advance.
:=
:=Here is part of the code then.
:=
:=
:=
:=#bit TMR0IF = 0xb.2
:=#bit TMR1IF = 0xc.0
:=
:=void display_key (char key_press);
:=
:=char Key;
:=char key_press;
:=int flag=0;
:=int16 counter=0;
:=
:=char main()
:={
:=
:=SETUP_ADC_PORTS( NO_ANALOGS );
:=
:=set_tris_a(0x00);
:=set_tris_b(0x1f);
:=
:=
:=disable_interrupts ( GLOBAL );
:=
:=setup_timer_0 ( RTCC_INTERNAL | RTCC_DIV_256 );
:=setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_8 );
:=
:=enable_interrupts (INT_TIMER1);
:=enable_interrupts (INT_RTCC);
:=enable_interrupts ( GLOBAL );
:=disable_interrupts (INT_TIMER1);
:=lcd_init();
:=
:=lcd_putc("\f");
:=
:=delay_ms(100);
:=output_high(pin_a2);
:=delay_ms(100);
:=output_low(pin_a2);
:=
:=do{
:=if (flag==1)
:= {
:= key_press=key;
:= display_key(key_press);
:= }
:=
:=}
:=while(1);
:=
:=}
:=
:=
:=
:=#INT_RTCC
:=char TIMER_0_ISR( )
:={
:=set_timer0(61);
:=
:= output_low(pin_A2);
:=
:=output_high(pin_a1);
:=
:= if(input(pin_B1)){key='1';flag=1;}
:= if(input(pin_B2)){key='2';flag=1;}
:= if(input(pin_B4)){key='3';flag=1;}
:=
:=output_low(pin_a1);
:=
:=
:=if(flag==1)
:= {
:=
:= TMR1IF=0;
:= set_timer1(0xcf2c); //100ms
:=
:= enable_interrupts(INT_TIMER1);
:= disable_interrupts(INT_RTCC);
:=
:=// display_key(key);
:=
:= }
:=}
:=
:=
:=
:=void display_key (char key_press)
:={
:=
:= lcd_putc(key_press);
:=
:= flag=0;
:=
:=
:=
:=}
:=
:=
:=#INT_TIMER1
:=T1_ISR( )
:={
:=set_timer1(0xcf2c); //100ms
:=counter++;;
:=
:=if(counter==10)
:= {
:=
:= TMR0IF=0;
:= output_high(pin_A2);
:= set_timer0(61);
:=
:= enable_interrupts(INT_RTCC);
:= disable_interrupts(INT_TIMER1);
:=
:= }
:=
:=}
It would help if i set the variable "counter" back to "0", otherwise of course it will it only run this once, well until 65000 cycles later. Its always the easy ones that catch you out.
The other week, i set up LCD on port D and couldn't get it working for ages because i misread the pin out and sort of assumed that the whole of port D pins would be next to each other on the 16F877......it ain't. Caught out again , eh.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12349 |
|
|
|
|
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
|