remote control's protocol decoder code

Discussion in 'Embedded Systems and Microcontrollers' started by sayf alawneh, Nov 13, 2014.

  1. sayf alawneh

    Thread Starter New Member

    Aug 4, 2014
    this code is for decoding an unknow remote control protocolby caturing the time of every rising and falling edge using ccp module mikroc pro for pic and pic16f877a

    int m ;char txt1[9],txt2[9],char txt3[9];
    int time1=0,time2=0;
    sbit LCD_RS at RB2_bit;
    sbit LCD_EN at RB3_bit;
    sbit LCD_D7 at RB7_bit;
    sbit LCD_D6 at RB6_bit;
    sbit LCD_D5 at RB5_bit;
    sbit LCD_D4 at RB4_bit;
    sbit LCD_RS_Direction at TRISB2_bit;
    sbit LCD_EN_Direction at TRISB3_bit;
    sbit LCD_D7_Direction at TRISB7_bit;
    sbit LCD_D6_Direction at TRISB6_bit;
    sbit LCD_D5_Direction at TRISB5_bit;
    sbit LCD_D4_Direction at TRISB4_bit;
    void main()
    CMCON=7;//disable comparator
    TRISC=255;// portc as input.
    TRISB=0;portb as output.
    T1CON=0B00000101;//enabling timer one in asynchronized timer mode.
    INTCON=0B11000000;//enabling GIE and PEIE bits to allow interrupts
    PIR1=0; //CCP1IF and TMR1IF are both zeros
    TMR1H=0;// initializing TMR1L and TMR1H
    CCP1CON=0B00000101; capture every rising edge (the first one) and as i understood when first rising edge is captured CCP1IF will be 1
    PIE1=0B00000101;//TMR1IE and CCP1IE bits are enabled
    if(CCP1IF_BIT==1){// when this bit is 1 the first rising edge is captured
    time1=CCPR1L+(256*CCPR1H);//the time of the first rising edge
    TMR1IF_BIT=0;//set the interrupt flag to zero to enable another oncoming one
    CCP1CON=0B00000100;// capture every falling edge () the first falling edge)
    PIE1=0B00000101;// CCP1IE and TMR1IE bits are enabled
    if(CCP1IF_BIT==1){ if the first falling edge is captured
    time2=CCPR1L+(256*CCPR1H);// the time of the first falling edge
    TMR1IF_BIT=0;//set the interrupt flag to zero to enable another oncoming one
    m=time2-time1;//m presents the time of an on pulse only i mean the 1 part (the positive part of the pulse)
    LCD_OUT(1,1,txt3);//view the time of rising edges
    LCD_OUT(1,7,txt2);//view the time of falling edges
    LCD_OUT(2,1,txt1);// view the positive part of the pulse time
    the problem is the time of the falling edges is always negative
    the time of the rising edges is always zero
    Last edited: Nov 13, 2014