楼主是想要这个咚咚么 :lol
#ifdef SUPPORT_IRCODE_OUTPUT
#define IRCODE_GPIO 4 //GAME_LAT Pin8 GPIO4
extern const BYTE ir_mapcode[];
static BYTE get_ircode(BYTE IrFunc)
{
BYTE i;
for (i = 0; i < 96; i++)
{
if (ir_mapcode[i] == IrFunc)
break;
}
return i;
}
static void delay_necir_clk(BYTE Clk560uS)
{
UINT16 delay10us = Clk560uS * 56 + 1;
while (delay10us --)
{
delay_1us(10);
}
}
#if 1 //Refee 072112
static void send_necir_byte(BYTE data)
{
int i ;
for (i = 0; i < 8; i ++)
{
GPIO_O_SET(IRCODE_GPIO, 0);
delay_necir_clk(1);
GPIO_O_SET(IRCODE_GPIO, 1);
if (data & 0x01)
delay_necir_clk(3);
else
delay_necir_clk(1);
data >>= 1;
}
}
void send_necir_flame_data(BYTE IrFunc)
{
BYTE IRcode = 0;
GPIO_F_SET(IRCODE_GPIO, 1);
GPIO_M_SET(IRCODE_GPIO, 1);
GPIO_E_SET(IRCODE_GPIO, 1);
//Lead code
GPIO_O_SET(IRCODE_GPIO, 0);
delay_necir_clk(16);
GPIO_O_SET(IRCODE_GPIO, 1);
delay_necir_clk(8);
//Custom code
send_necir_byte(0x00);
send_necir_byte(0xFF);
//Data code
IRcode = get_ircode(IrFunc);
send_necir_byte(IRcode);
IRcode = 0xFF - IRcode;
send_necir_byte(IRcode);
GPIO_O_SET(IRCODE_GPIO, 0);
delay_necir_clk(9);
GPIO_O_SET(IRCODE_GPIO, 1);
}
#else
enum
{
SEND_IR_IDLE = 0,
SEND_IR_START,
SEND_IR_LEADCODE,
SEND_IR_CUSTOMCODE,
SEND_IR_DATACODE,
SEND_IR_FINISH,
};
#define IRBit0 2 // 01
#define IRBit1 4 // 0111
BYTE SendBitCount = 0;
BYTE SendIR_ClkCount = 0;
BYTE Send_NEC_IR_State = SEND_IR_IDLE;
BYTE CustomCode[16] = //0x00FF
{
IRBit0, IRBit0, IRBit0, IRBit0, IRBit0, IRBit0, IRBit0, IRBit0,
IRBit1, IRBit1, IRBit1, IRBit1, IRBit1, IRBit1, IRBit1, IRBit1
};
BYTE DataCode[16] = //0x00FF
{
IRBit0, IRBit0, IRBit0, IRBit0, IRBit0, IRBit0, IRBit0, IRBit0,
IRBit1, IRBit1, IRBit1, IRBit1, IRBit1, IRBit1, IRBit1, IRBit1
};
static void polling_send_ir(void)
{
switch (Send_NEC_IR_State)
{
case SEND_IR_START:
GPIO_F_SET(IRCODE_GPIO, 1);
GPIO_M_SET(IRCODE_GPIO, 1);
GPIO_E_SET(IRCODE_GPIO, 1);
GPIO_O_SET(IRCODE_GPIO, 0);
SendIR_ClkCount = 24; // 560us*24 = 13.5ms
Send_NEC_IR_State = SEND_IR_LEADCODE;
break;
case SEND_IR_LEADCODE:
SendIR_ClkCount --;
if (SendIR_ClkCount)
{
if (SendIR_ClkCount > 8) // L 9ms H 4.5ms
GPIO_O_SET(IRCODE_GPIO, 0);
else
GPIO_O_SET(IRCODE_GPIO, 1);
}
else
{
GPIO_O_SET(IRCODE_GPIO, 0);
SendBitCount = 16;
SendIR_ClkCount = CustomCode[0];
Send_NEC_IR_State = SEND_IR_CUSTOMCODE;
}
break;
case SEND_IR_CUSTOMCODE:
SendIR_ClkCount --;
if (SendIR_ClkCount)
GPIO_O_SET(IRCODE_GPIO, 1);
else
{
GPIO_O_SET(IRCODE_GPIO, 0);
SendBitCount --;
if (SendBitCount)
SendIR_ClkCount = CustomCode[(16 - SendBitCount)];
else
{
SendBitCount = 16;
SendIR_ClkCount = DataCode[0];
Send_NEC_IR_State = SEND_IR_DATACODE;
}
}
break;
case SEND_IR_DATACODE:
SendIR_ClkCount --;
if (SendIR_ClkCount)
GPIO_O_SET(IRCODE_GPIO, 1);
else
{
GPIO_O_SET(IRCODE_GPIO, 0);
SendBitCount --;
if (SendBitCount)
SendIR_ClkCount = DataCode[(16 - SendBitCount)];
else
{
SendIR_ClkCount = 9; // 560us*9 = 5ms
Send_NEC_IR_State = SEND_IR_FINISH;
}
}
break;
case SEND_IR_FINISH:
SendIR_ClkCount --;
if (SendIR_ClkCount)
GPIO_O_SET(IRCODE_GPIO, 0);
else
{
GPIO_O_SET(IRCODE_GPIO, 1);
Send_NEC_IR_State = SEND_IR_IDLE;
}
break;
default:
break;
}
}
void send_necir_flame_data(BYTE IrFunc)
{
int i = 0;
UINT16 IRcode = 0;
IRcode = ((0xFF - get_ircode(IrFunc)) << 8) | get_ircode(IrFunc);
for (i = 0; i < 16; i ++)
{
if (IRcode & 0x01)
DataCode[i] = IRBit1;
else
DataCode[i] = IRBit0;
IRcode >>= 1;
}
Send_NEC_IR_State = SEND_IR_START;
while (Send_NEC_IR_State)
{
polling_send_ir();
delay_necir_clk(1);
}
}
#endif
#endif
|