Flow control for time2 and RB0pin Interrupt

Submitted by lara on Thu, 12/13/2018 - 02:15

Hi There,

I am tring to understand flow control of folling code got from tutorials for dimmer control was written in Hi. tech c 16f887 mcu with timer2(8bit) and RB0 pin interrupt.

//---------------ARRAY VARIABLE DEFINITION ------------------------------------------------
unsigned char dimmerspeed[1]={0};       
unsigned char dimmerdelay[1]={0};

#define DIMMER_MAX 5
#define DIMMER_1             PORTAbits.RA1
#define ZERO_CROSS         PORTBbits.RB0

//------------------------------------------Initial ISR-------------------------------------------------------
void interrupt intisr(void)                                                      

   if(INTCONbits.INTF)               //Check RB0 PIN INTERRUPT FOR ZC FLAG
      INTCONbits.INTF   =0;
   else (PIR1bits.TMR2IF)               // check the timer2 over flow interrupt flag 
   timer2Isr();                              //FLAG SET 2.048 mSec
   PIR1bits.TMR2IF =0;


void main() 

   while(1)               // wait forever for  the data received and ready  

      switch(command)   // swich on 
      case 0x80:                                 //remote key dimmer down
      case 0x00:                                    //remote key dimmer up
      default :    
      }//switch (command)


//--------------------------------timer2 ISR--------------------------------------------------------------------------------------

void timer2Isr()    // every  2.048 ms

What i understand that, after mcu power up, RB0 interrupt has detected under the RB0 ISR>> timer2 is reset at 0 >>dimmerdelay[0] is updated at 0b1010>>timer2isr is called.


if(dimmerdelay[0])//  is true and entering to block

DIMMER_1=0;   // triac turned off

if(!(dimmerdelay[0]&0x80))// evalue to 0b1111 1111 ie, true.

dimmerdelay[0]--; // WHY it is decrementined ????? and after that if . ------------------------->QUESTION NO 1.

if(dimmerdelay[0]) // is false, ie when dimmerspeed[0] is '5' then

dimmerdelay[0]=0xFF;    // WHY 'FF' ------------------------------------------QUESTION NO 2

How 10/8/6/4/2/0 msec is being related with timer2 interrupt(ie 2.048 msec) after detecting INTF at RB0.

tnx for reply..