Compile error

I have been working on code for Atmega8, for controlling in 10 steps the speed of a n AC fan.
IR remote is used for varying the speed and triac is fired on zero crossing.
I have tested the code in sections ie The display part with IR (Increment/decrement).
On adding the code for zero cross detection and output to control gate signal.
The code does'nt compile
The code is followed with the compile error.

#include <EEPROM.h>
#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>



#define setbit(port, bit) (port) |= (1<< (bit))
#define clearbit(port, bit) (port) &=~(1<< (bit))

#define POWER_LED_ON() clearbit(PORTD, PD7)
#define POWER_LED_OFF() setbit(PORTD, PD7)

uint8_t table[10] = {141, 125, 109, 94, 78, 62, 47, 31, 16, 1};

const int iRReceivePin = PD2;
IRrecv irrecv(iRReceivePin);
decode_results results;
/* iniialise speed to zero, and also store the set value in EEPROM
  on every change to be read from it on power recycle.
*/
char speedVal = 0;
char num = 0;
uint8_t fan_on = 0;
uint8_t lastPowerState = 0;





void setup()
{
  // put your setup code here, to run once:
  initialize();
  //Initialize the zero crossing detector INT(1)
  MCUCR |= ((1 << ISC11) | (1 << ISC10)); //INT in Rising edge
  GICR |= (1 << INT1);      //Enable INT1
  //Set Timer 1
  TCCR1A = 0;
  TCCR1B = 0;
  TCCR1B |= (1 << WGM12); //CTC
  TCCR1B |= ((1 << CS12) | (1 << CS10));
  TIMSK |= (1 << OCIE1A); //Enable CTC Output capture
  sei();
}
//Zero Crossing Detect.


ISR(INT1_vect)
{
  if (!fan_on)
  {
    PORTD |= (1 << PD5); //High = TRIAC Off
    return;
  }
  if (9 == speedVal)
  {
    PORTD &= (~(1 << PD5)); //low = TRIAC ON
    return;
  }
  PORTD |= (1 << PD5); //High = TRIAC Off
  OCR1A = table[speedVal];
  TCNT1H = 0x00;
  TCNT1L = 0x00;
  TCCR1B |= ((1 << CS12) | (1 << CS10)); // eneble presccalar of 1024
}


ISR(TIMER1_COMPA_vect)
{
  PORTD &= (~(1 << PD5)); //low = TRIAC ON
  TCCR1B &= (~((1 << CS12) | (1 << CS10))); //Stop Timer
}


void loop()
{
  while (1)
  {
    if (irrecv.decode(&results))
    {
      switch (results.value)
      {
        case 0xFF48B7:  // NEC code for UP Key
          {
            if (speedVal < 9)
              speedVal++;
            Display (speedVal);
            EEPROM.put(5, speedVal);
          }
          break;
        case 0XFF609F:  //NEC Code for DOWN Key
          {
            if (speedVal > 0)
              speedVal--;
            Display (speedVal);
            EEPROM.put(5, speedVal);
          }
          break;
        case 0xFFAA55:  // NEC code for enter key
          {
            if (fan_on)
            {
              POWER_LED_OFF();
              fan_on = 0;
              lastPowerState = fan_on;
              EEPROM.put (3, lastPowerState);
            }
            else
            {
              POWER_LED_ON();
              fan_on = 1;
              lastPowerState = fan_on;
              EEPROM.put (3, lastPowerState);
            }
          }
          break;
      }
      irrecv.resume(); // Receive the next value
    }
  }
}
/* Seven Segment Display Function */

void Display(char num)
{
  if (num > 9)
    return;
  switch (num)
  {
    case 0:
      PORTC = 0B00000000;
      PORTB = 0B00000010;
      break;
    case 1:
      PORTC = 0B00111001;
      PORTB = 0B00000010;
      break;
    case 2:
      PORTC = 0B00100100;
      PORTB = 0B00000000;
      break;
    case 3:
      PORTC = 0B00110000;
      PORTB = 0B00000000;
      break;
    case 4:
      PORTC = 0B00011001;
      PORTB = 0B00000000;
      break;
    case 5:
      PORTC = 0B00010010;
      PORTB = 0B00000000;
      break;
    case 6:
      PORTC = 0B00000010;
      PORTB = 0B00000000;
      break;
    case 7:
      PORTC = 0B00111000;
      PORTB = 0B00000010;
      break;
    case 8:
      PORTC = 0B00000000;
      PORTB = 0B00000000;
      break;
    case 9:
      PORTC = 0B00010000;
      PORTB = 0B00000000;
      break;
  }
}
void initialize()
{
  irrecv.enableIRIn(); // Start the IR receiver
  /*  PD7 as output  */
  POWER_LED_OFF();
  DDRD |= (1 << PD7);
  /* Set PD2 and PD3 as inputs */
  DDRD &= ~(1 << PD2);
  DDRD &= ~(1 << PD3);
  // Port C pins 0 to 5 as output for seg a b c d e f
  // Port B pin 1 as output for segment g
  DDRC |=  (1 << PC0) | (1 << PC1) | (1 << PC2) | (1 << PC3) | (1 << PC4) | (1 << PC5);
  DDRB |= (1 << PB1);
  /* Sets all segments a to g in the display off */
  setbit (PORTC, PC0);
  setbit (PORTC, PC1);
  setbit (PORTC, PC2);
  setbit (PORTC, PC3);
  setbit (PORTC, PC4);
  setbit (PORTC, PC5);
  setbit (PORTB, PB1);
  EEPROM.get (5, speedVal);
  Display (speedVal);
  EEPROM.get (3, lastPowerState);
  fan_on = lastPowerState;
  if (lastPowerState)
  {
    POWER_LED_ON();
  }
  else
  {
    POWER_LED_OFF();
  }
  /*  Output - blocking gate signal to opto isolator */
  setbit(PORTD, PD5); //PD5 High = Triac off
  DDRD |= (1 << PD5); //set DDR for port BIT 5
}

The max character limit is exceeded with the compile error.
Try to post it in next message.

error message.txt (14.2 KB)

IRremote is already using TIMER1_COMPA_vect so you cannot use it in your sketch again.

pylon:
IRremote is already using TIMER1_COMPA_vect so you cannot use it in your sketch again.

Yes the IRremote library uses both Timer1 and Timer2. I freed up Timer2 from this library, changed it to Timer1.
I used Timer2 in my code and it now compiled and uploaded also successfully.
Thanks for your support, pylon.

with support from this forum, i have been able to get the desired results from the code for controlling speed of a fan motor, by varying the firing angle of a triac using a zero cross detector.
The seven segment digit used for displaying the position (0 to 9) remains on. Is there a way that this digit powers down say after a period of 10 seconds.
I am putting up the code for your perusal please

/*
  *****************************************************************************
  *** NOTE This code works as original coded from Extreme electronics                                 ***
  *** Only the IR library is changed to standard library.However in this                                  ***
  *** library Timer2 for atmega8 has been changed to Timer1 as this code                             ***
  *** uses timer2. For Last Speed and Power state has been coded.                                       ***
  *** For this help was extended by the Arduino Forum.                                                        ***
  *****************************************************************************


Hardware:
  INT0 - IR Receiver
  INT1 - Zero Crossing Detector.
  PD5 - Triac Control.

  For
  ATmega8 @ 16MHz

  Fuse:
  HIGH=0xC9 LOW=0xFF


*/
#include <EEPROM.h>
#include <arduino.h>
#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>

#define FAN_POWER_LED_PORT PORTD
#define FAN_POWER_LED_DDR DDRD
#define FAN_POWER_LED_BIT 7

#define POWER_LED_ON()   FAN_POWER_LED_PORT&=(~(1<<FAN_POWER_LED_BIT))
#define POWER_LED_OFF() FAN_POWER_LED_PORT|=(1<<FAN_POWER_LED_BIT)

uint8_t table[10] = {141, 125, 109, 94, 78, 62, 47, 31, 16, 1};

const int iRReceivePin = PD2;
IRrecv irrecv(iRReceivePin);
decode_results results;

int speed = 0;
uint8_t fan_on = 0;
void initialize()
{
  irrecv.enableIRIn();
  FAN_POWER_LED_DDR |= 0B10000000;  //1
  EEPROM.get (3, fan_on);
  if (fan_on == 1)
  {
    POWER_LED_ON();
  }
  else
  {
    POWER_LED_OFF();
  }
  DDRC |= 0b00111111; //Seven segment digits a,b,c,d,e,f  //2
  DDRB |= 0b00000010; //Middle segment g  //3
  display (0);
  EEPROM.get (0 , speed);
  display (speed);
  //void RemoteInit();
  //Initialize the zero crossing detector INT(1)
  MCUCR |= ((1 << ISC11) | (1 << ISC10)); //INT in Rising edge
  GICR |= (1 << INT1);      //Enable INT1
  //Output
  DDRD |= (1 << PD5);
  PORTD |= (1 << PD5); //High = TRIAC Off
  //Set Timer 2
  TCCR2 |= (1 << WGM21); //CTC
  TIMSK |= (1 << OCIE2); //Enable OCI2
  sei();
}
/*
  Zero Crossing Detect.
*/
ISR(INT1_vect)
{
  if (!fan_on)
  {
    PORTD |= (1 << PD5); //High = TRIAC Off
    return;
  }
  if (speed == 9)
  {
    PORTD &= (~(1 << PD5)); //low = TRIAC ON
    return;
  }
  PORTD |= (1 << PD5); //High = TRIAC Off
  OCR2 = table[speed];
  TCNT2 = 0x00;
  TCCR2 |= ((1 << CS22) | (1 << CS21) | (1 << CS20)); //Start Timer prescaler =1024
}

/*
  Timer2 Compare ISR
*/
ISR(TIMER2_COMP_vect)
{
  PORTD &= (~(1 << PD5)); //low = TRIAC ON
  TCCR2 &= (~((1 << CS22) | (1 << CS21) | (1 << CS20))); //Stop Timer
}

/*
  Displays a number in Seven Seg Display
*/
void display (int  num)
{
  if (num > 9)
    return;
  switch (num)
  {
    case 0:
      PORTC = 0B00000000;
      PORTB = 0B00000010;
      break;
    case 1:
      PORTC = 0B00111001;
      PORTB = 0B00000010;
      break;
    case 2:
      PORTC = 0B00100100;
      PORTB = 0B00000000;
      break;
    case 3:
      PORTC = 0B00110000;
      PORTB = 0B00000000;
      break;
    case 4:
      PORTC = 0B00011001;
      PORTB = 0B00000000;
      break;
    case 5:
      PORTC = 0B00010010;
      PORTB = 0B00000000;
      break;
    case 6:
      PORTC = 0B00000010;
      PORTB = 0B00000000;
      break;
    case 7:
      PORTC = 0B00111000;
      PORTB = 0B00000010;
      break;
    case 8:
      PORTC = 0B00000000;
      PORTB = 0B00000000;
      break;
    case 9:
      PORTC = 0B00010000;
      PORTB = 0B00000000;
      break;
  }
}
int main ()
{
  initialize ();
  while (1)
  {
    if (irrecv.decode(&results))
    {
      switch (results.value)
      {
        case 0xFF48B7:  // NEC code for UP Key
          {
            if (speed < 9)
              speed++;
            EEPROM.put(0, speed);
          }
          break;
        case 0XFF609F:  //NEC Code for DOWN Key
          {
            if (speed > 0)
              speed--;
            EEPROM.put(0, speed);
          }
          break;
        case 0xFFAA55:  // NEC code for enter key
          {
            if (fan_on)
            {
              POWER_LED_OFF();
              fan_on = 0;
              EEPROM.put (3, fan_on);
            }
            else
            {
              POWER_LED_ON();
              fan_on = 1;
              EEPROM.put (3, fan_on);
            }
          }
          break;
      }
      irrecv.resume(); // Receive the next value
    }
    display (speed);
  }
}