hemnath
Advanced Member level 3
I'm using pic 18F2520 and ccs c compiler. Button is connected to PIN C0. My program goes upto 1500 lines and does some other things.
I'm continuously reading adc value and displaying in lcd. And, when button is pressed, it shows the display value(which is in float) in different units which i have programmed. Everything is working ok, but the problem is, when button is pressed, display unit changes and sometimes it doesn't changes. Due to polling the button pin, and the program is big, will it be a reason to miss the button press??
So i have decided to write a small isr routine using timer1. For every 100ms, timer_flag sets. And, when timer_flag is set and im checking the button is pressed or not. still the problem remains the same. I know that still i'm polling the button pin.
small routine program i have included in my program
In main function
Is there any other method to accurately detect the button press. I know that can be done with external hardware interrupts. But i have connected pin C0 to button. Pin C0 dont have interrupt feasibility. Even i couldn't change the pin. So please help with this!!!
I'm continuously reading adc value and displaying in lcd. And, when button is pressed, it shows the display value(which is in float) in different units which i have programmed. Everything is working ok, but the problem is, when button is pressed, display unit changes and sometimes it doesn't changes. Due to polling the button pin, and the program is big, will it be a reason to miss the button press??
So i have decided to write a small isr routine using timer1. For every 100ms, timer_flag sets. And, when timer_flag is set and im checking the button is pressed or not. still the problem remains the same. I know that still i'm polling the button pin.
small routine program i have included in my program
HTML:
#INT_timer1
void isr()
{
if(TMR1IF == 1)
{
timer_flag = 0;
TMR1IF = 0;
TMR1IE = 1;
TMR1H = 0xFE; // Values calculated for 100 millisecond delay with 4MHz crystal
TMR1L = 0x79;
}
}
In main function
HTML:
while(1)
{
if(timer_flag==0)
{
if(input(Button)==0)
{
i = i + 0.1;
lcd_cmd(0x80);
printf(lcd_data,"%6.3f",i);
}
timer_flag = 1;
}
}
Is there any other method to accurately detect the button press. I know that can be done with external hardware interrupts. But i have connected pin C0 to button. Pin C0 dont have interrupt feasibility. Even i couldn't change the pin. So please help with this!!!