Daljeet12
Member level 4
I have pic16f877a and MPLABX8 and I want to count pluses generated by encoder
sensor and encoder output is connected to input of PIC and LED is connected to output of PIC
I want to write program for following statement
if the sensor is active, an encoder will generate pulses and microcntroller will count pulses upto 32000 then turn on LED
I am using TMR1 to count pulses on pin RC0
Please someone help me to make program ?
sensor and encoder output is connected to input of PIC and LED is connected to output of PIC
I want to write program for following statement
if the sensor is active, an encoder will generate pulses and microcntroller will count pulses upto 32000 then turn on LED
I am using TMR1 to count pulses on pin RC0
Code:
#define _XTAL_FREQ 20000000 //Specify the XTAL crystall FREQ
#define LED RB2
#define ON 1
void main()
{
TRISB=0X00; //PORTB pins are used as Output.
TRISC=0Xff; //PORTC pins are used as Input.
TMR1H=0x82; // initial count values in timer1 register
TMR1L=0xff;
TMR1IE=1; //Enable timer interrupt bit in PIE1 register
GIE=1; //Enable Global Interrupt
PEIE=1; //Enable the Peripheral Interrupt
TMR1ON = 1; //Start Timer1
T1CON=0x01; //Prescale value = 1:1, It using Internal clock, Timer 1 ON
}
void interrupt timer_isr()
{
if(TMR0IF==1) // Timer flag has been triggered
{
LED = on
TMR0IF=0; // Clear timer interrupt flag
}
}
Please someone help me to make program ?