Hello there monstrosities
I have altered a code for NEC remote decoding.The disentangling part is working fine and completely dependent nervous recognition logic(using INT0).But the issue is at whatever point I put a _delay_ms in the main,the unraveling is failing/not working at all.It additionally has a zero cross detection(using INT1) for fan speed control.I am utilizing _delay_ms subroutine in the main.c for triac terminating delay.If I increment the measure of deferral/putting only a 1000ms postponement (for testing reason) in the main,the interpreting part isn’t working at all.Please take a gander at the code underneath
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include "nec_decode.h"
//Other electrical load related definition
#define load_port PORTC
#define load_pin PINC
#define load_ddr DDRC
#define load_1 0
#define load_2 1
#define load_3 2
#define load_4 3
#define load_5 4
#define load_6 5
//Electrical Fan related definition
#define fan_port PORTD
#define fan_ddr DDRD
#define fan_pin PIND
#define fan_bit 4
uint8_t fan_speed;
void load_handle(void)
{
switch(ir_data)
{
case rmt1key_1:
load_port ^= (1<<load_1);
break;
case rmt1key_2:
load_port ^= (1<<load_2);
break;
case rmt1key_3:
load_port ^= (1<<load_3);
break;
case rmt1key_4:
load_port ^= (1<<load_4);
break;
case rmt1key_5:
load_port ^= (1<<load_5);
break;
case rmt1key_6:
load_port ^= (1<<load_6);
break;
case rmt1key_volp:
if(fan_speed<0x04)
{
fan_speed++;
if(fan_speed==0x04)
{
fan_port |= (1<<fan_bit);
}
}
break;
case rmt1key_volm:
if(fan_speed>0x00)
{
fan_speed--;
if(fan_speed==0x00)
{
fan_port &= ~(1<<fan_bit);
}
}
break;
case rmt1key_0:
fan_port &= ~(1<<fan_bit);
fan_speed = 0x00;
load_port = 0x00;
break;
case rmt1key_8:
PORTB ^= (1<<5);
break;
}
}
int main(void)
{
/* Replace with your application code */
DDRB |= (1<<5);
load_ddr = 0xFF;//All output
fan_ddr |= (1<<fan_bit);//fan output
//Recall the last load status
load_port = eeprom_read_byte((uint8_t *)10);
//Recall the last fan speed
fan_speed = eeprom_read_byte((uint8_t *)20);
//If the value is out of the range,the reset it
if((fan_speed>4)||(fan_speed<0))
{
fan_speed = 0;
}
//If we get a full speed
if(fan_speed==4)
{
fan_port |= (1<<fan_bit);
}
//If the fan was off
else if(fan_speed==0)
{
fan_port &= ~(1<<fan_bit);
}
initir();
sei();
while (1)
{
if(dataready)
{
cli();
load_handle();
eeprom_update_byte((uint8_t *)10,load_port);//update the load status to eeprom
eeprom_update_byte((uint8_t *)20,fan_speed);//update the fan speed to eeprom
dataready=0;
ir_data=0;
sei();
}
if(zc_detect)
{
switch(fan_speed)
{
case 1:
_delay_ms(7);
fan_port |= (1<<fan_bit);
_delay_us(100);
fan_port &= ~(1<<fan_bit);
zc_detect = 0;
break;
case 2:
_delay_ms(5);
fan_port |= (1<<fan_bit);
_delay_us(100);
fan_port &= ~(1<<fan_bit);
zc_detect = 0;
break;
case 3:
_delay_ms(3);
fan_port |= (1<<fan_bit);
_delay_us(100);
fan_port &= ~(1<<fan_bit);
zc_detect = 0;
break;
}
}
}
}