红外编码与解码——GREE格力遥控 发送在上一期上描述了红外解码,以及红外在传播过程中造成的误差,
上期回顾
[红外]02、红外编码与解码——GREE格力遥控 http://bbs.eeworld.com.cn/thread-462015-1-1.html
针对GREE格力遥控的红外编码的原则
file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Application%20Data/YNote/data/1696933323@qq.com/43ff4fe8f4dd442c9376e4071652cbe1/clipboard.png
进行编码如下
代码如下:
void IRsend_sendGREE(long datavalue ,unsigned int greeCRC)
{
long data = 0;
long temp = 0;
IRsend_enableIROut(38);
IRsend_mark(GREE_HDR_MARK);
IRsend_space(GREE_HDR_SPACE);
data = (datavalue&0xffffff80)|0x0A;
for (int i = 0; i < 32; i++){
if (data & TOPBIT) {
IRsend_mark(GREE_BIT_MARK);
IRsend_space(GREE_ONE_SPACE);
}
else {
IRsend_mark(GREE_BIT_MARK);
IRsend_space(GREE_ZERO_SPACE);
}
data <<= 1;
}
data = 0×02;
for (int i = 0; i < 3; i++){
if (data & TOPBIT) {
IRsend_mark(GREE_BIT_MARK);
IRsend_space(GREE_ONE_SPACE);
}
else {
IRsend_mark(GREE_BIT_MARK);
IRsend_space(GREE_ZERO_SPACE);
}
data <<= 1;
}
IRsend_mark(GREE_COM_MARK);
IRsend_space(GREE_COM_SPACE);
temp = datavalue&0×00000040;//7
data = (temp>>6);
data = data<<4;
temp = datavalue&0×00000020;//6
data = data|(temp>>5);
data = data<<5;
temp = datavalue&0×00000018;//5 4
data = data|(temp>>3);
data = ((data<<16)|0×1000)<<1;//3
temp = datavalue&0×00000004;
data = data|(temp>>2);
data = (data<<5)|(greeCRC&0x000f);
for (int i = 0; i < 32; i++){
if (data & TOPBIT) {
IRsend_mark(GREE_BIT_MARK);
IRsend_space(GREE_ONE_SPACE);
}
else {
IRsend_mark(GREE_BIT_MARK);
IRsend_space(GREE_ZERO_SPACE);
}
data <<= 1;
}
IRsend_mark(GREE_BIT_MARK);
IRsend_space(0);
}
|
IRsend_enableIROut 主要实现的功能是配置PWM波的载波频率,一般为38KHZ 1/3~1/4Duty (当然也有一些特别)
由[红外]01、红外遥控介绍与接收http://bbs.eeworld.com.cn/thread-461935-1-1.html可知
要发出红外波,就是以PWM驱动红外LED传播红外波
file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Application%20Data/YNote/data/1696933323@qq.com/475d1bd30dec47ea8a82677c7f6337b7/clipboard.png
其代码如下:
void Sct_Pwm_Init(uint32_t PWM_RATE)
{
/* Initialize the SCT as PWM and set frequency */
Chip_SCTPWM_Init(LPC_SCT);
Chip_SCTPWM_SetRate(LPC_SCT, PWM_RATE);
/* Setup Board specific output pin */
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 9, IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
/* Use SCT0_OUT1 pin */
Chip_SCTPWM_SetOutPin(LPC_SCT, SCT_PWM_OUT, SCT_PWM_PIN_OUT);
/* Start with 0% duty cycle */
Chip_SCTPWM_SetDutyCycle(LPC_SCT, SCT_PWM_OUT, Chip_SCTPWM_GetTicksPerCycle(LPC_SCT) / 4);
//Chip_SCTPWM_Start(LPC_SCT);
}
|
void IRsend_mark(int time) {
// Sends an IR IRsend_mark for the specified number of microseconds.
// The IRsend_mark output is modulated at the PWM frequency.
TIMER_ENABLE_PWM(); // Enable pin 3 PWM output
if (time > 0) delayMicros(time);
}
/* Leave pin off for time (given in microseconds) */
void IRsend_space(int time) {
// Sends an IR IRsend_space for the specified number of microseconds.
// A IRsend_space is no output, so the PWM output is disabled.
TIMER_DISABLE_PWM(); // Disable pin 3 PWM output
if (time > 0) delayMicros(time);
}
|
由[红外]02、红外编码与解码——GREE格力遥控 http://bbs.eeworld.com.cn/thread-462015-1-1.html
解译出的代码
以开/关键为理
关IRsend_sendGREE(0×900400,0xa);
开IRsend_sendGREE(0X10900400,0xb);
用数据采集仪分析对比
LPC54102 发送出来
file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Application%20Data/YNote/data/1696933323@qq.com/25105f09d6fb4f1eb6d1452cd3f70040/clipboard.png
file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Application%20Data/YNote/data/1696933323@qq.com/13cbcd67b3f84aca9be613ffeadc10ae/clipboard.png
遥控器
file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Application%20Data/YNote/data/1696933323@qq.com/1f6cd68b1f004a78bc7af0f0451c55a5/clipboard.png
仔细对比,校对得以上图。
最后上电测试 成功的开关空调。总结对于LPC54102的资源为 PWM 的输出,定时器(延时)。其实软件延时也可以。下图为非准确延时的图,都能实现开关机
不对资源不是很紧张或者是初调试者建议还是用定时器延时。用到的资源主要有
LPC_SCT 与LPC_TIMER2