I am new to pic. I am using a 16f887 controller. I am using a hi-tech compiler. I want to measure button press time. I want to use that total button press time for delay and using that led should be on for that much of delay(button press time). I am not able to store that button press value count that value and make led on for that much of time. Button press timer is more or less than 5 seconds.
- Code: Select all
#include <htc.h>
#define _XTAL_FREQ 8000000
#define SWITCH RD0
#define LED RD2
unsigned long int total_count = 0,count = 0,count1 = 0;
unsigned char flag =0,flag1 =0;
unsigned char i=0,k=0;
void Init_Timer1() // Timer Initialization at 0.6ms
{
TMR1ON = 0x01;
TMR1IF = 0;
TMR1H = 0xE0;
TMR1L = 0xC0;
TMR1IE = 1;
INTCON |= 0xC0;
}
void Extern()
{
TRISB |= 0X01;
INTCON |= 0XD0;
INTEDG = 1; // Rising Edge Detect
}
void interrupt ISR(void)
{
if(TMR1IF) // Timer1 Interrupt flag
{
TMR1IF = 0;
TMR1H = 0xE0; //0xFB
TMR1L = 0xC0; //0x4F
TMR1ON = 0x01;
if(flag==1)
{
count++;
if(count==250)
{ LED=~LED;
count = 0;
flag=1;
}
}
}
}
void main()
{
Init_Timer1();
TRISD2 = 0;
TRISD0 = 1;
LED=0;
while(1)
{
if((RD0 == 0))//&&(flag==0))
{
flag=1;
}
}
}