/**************** (c) 2005 佛山菱电 *****************************************
PROJECT : AUX VRV
COMPILER : AVR GCC/ICC
MODULE : rem.c
VERSION : 1.0.0
DATE : 2006/01/02
AUTHOR : 朱坤
DESCRIPTION : 遥控接收或线控器收发[T0]
MODIFICATIONS :
******************************************************************************/
#include "rem.h"
#include "ports.h"
#include "timer.h"
#include "main.h"
#include "buz.h"
#include "fan.h"
#include "adc.h"
#include "led.h"
#include "pzf.h"
#include "i2c.h"
#include "rscom.h"
#include "swing.h"
u8 LcSt0Cnt; /* 低电平计时 */
u8 *LcByteCnt; /* 字节计数 */
u8 LcBitCnt; /* 位计数 */
#ifdef EnSTYLE5
#ifdef EnSCOM
u8 LcBufAdr[15]; /* 遥控接收、线控器接收、发送缓冲区 */
#else
u8 LcBufAdr[13]; /* 遥控接收缓冲区 */
#endif
#else
u8 LcBufAdr[13]; /* 遥控接收缓冲区 */
#endif
u8 LcInHiCnt; /* 高电平计时 */
u8 LcFlag; /* 标志位 */
#define fLcRxOk 7
#define fLcTxRxSc 6
#define fLcTx 5 /* 1: Tx, 0: Rx */
#define fLcTxLo 4 /* 1: 高低电平标志 */
#define fLc388 3 /* 1: 388 0: AUX */
u8 AckTm; /* 参数修改锁定计时 3分钟 */
#ifdef EnSCOM
u8 ErrFlashCnt; /* 循环发送故障码计数 */
u8 LcComTm; /* 若线控器一直处于发送状态,强制为接收状态 */
u8 LcMonCnt; /* 线控器通信故障计时 */
u8 ErrCnt; /* 循环发送故障码计时 */
u8 LcInitCnt; /* 系统初始化计数 */
u8 LcInitTmr; /* 系统初始化计时 */
#endif
const u8 LcRxMod_Tab[] = {MODEAUTO,MODECOOL,MODEDRY,MODEFAN,MODEHEAT,MODEAUTO,MODEAUTO};
const u8 ModeAux[] = {MODEAUTO,MODECOOL,MODEDRY,MODEDRY,MODEHEAT,MODEHEAT,MODEFAN};
const u8 LcRxFan_Tab[] = {FANAUTO_S,FANHI_S,FANMI_S,FANLO_S,FANPO_S,FANEC_S,FANAUTO_S,FANAUTO_S};
const u8 FanAux[] = {FANPO_S,FANHI_S,FANMI_S,FANLO_S,FANEC_S,FANAUTO_S,FANAUTO_S,FANAUTO_S};
#ifdef EnSCOM
const u8 LcComTx_IFan[] = {0x00,0x30,0x20,0x10,0x00,0x50,0x00,0x40};
const u8 LcComTx_IMod[] = {0x00,0x04,0x01,0x02,0x03,0x04,0x01,0x03};
#ifdef EnSTYLE5
const u8 Tab_DErr_No[] = { /*定频外机系统*/
46,47,48,49,50,51,52,53,
54,55,56,57,58,59,60,61,
62,63,64,65,66,67,68,69,
70,71,72,73,74,75,76,77};
const u8 Tab_BErr_No[] = { /* 变频外机系统 */
30,31,32,33,34,35,36,37,
38,39,40,41,42,43,44,45,
1, 2, 3, 4, 5, 6, 7, 8,
9, 10,11,12,13, 0, 0, 0,
20,21,22, 0, 0, 0, 0, 0,23};
const u8 Tab_NErr_No[] = { /* 内机故障代码*/
80,82,81,83,84,88,87,89,
90,93,91,0,0,0,0,0}; /* 90:PG风机故障; 93: 房卡断开 */
#else
const u8 Tab_Err_No[] = {
3, /* 室外压缩机排气温度过高*/
6, /* 缺氟或换向阀故障*/
2, /* 室外机交流输入电流过大*/
7, /* 室外机交流输入电流采样故障*/
5, /* 室外机直流母线电压异常*/
8, /* 室内机总功率过大*/
4, /* 室外机传感器故障*/
1, /* 变频器模块保护*/
12, /* 室温传感器故障*/
15, /* 细管传感器故障*/
13, /* 室内盘管传感器故障*/
16, /* 粗管传感器故障*/
11, /* 室内机地址冲突*/
14, /* 线控器与室内机通讯故障*/
11, /* 室内机与室外机通讯故障*/
8, /* 室内机总功率过大*/
17, /* PG风机故障*/
18, /* 房卡断开*/
10, /* 水泵故障*/
0,0,0,0,0};
#endif
#endif
/*-----------------------------------------------------------------------------
ROUTINE NAME : TIMA_Int
INPUT/OUTPUT : None
DESCRIPTION : T2 Interrupt Service Routine
COMMENTS : 线控器收发 0.256mS
-----------------------------------------------------------------------------*/
#ifdef AVRGCC
SIGNAL(SIG_OUTPUT_COMPARE2)
#else
#pragma interrupt_handler TIMA_Int:iv_TIMER2_COMP
void TIMA_Int(void)
#endif
{
#ifdef EnSCOM
if (ValBit(LcFlag,fLcTx)){ /* 线控器发送 */
if (ValBit(LcFlag,fLcTxLo)){ /* 1: 高电平标志 */
ClrBit(LcFlag,fLcTxLo);
SetBit(pLCTx,pbLCTx); /* 低电位 */
if (ValBit(LcFlag,fLcTxRxSc)){
OCR2 += 768/16; /* 0.768mS */
} else {
OCR2 += 3840/16; /* 3.84mS */
}
} else {
SetBit(LcFlag,fLcTxLo);
ClrBit(pLCTx,pbLCTx); /* 高电位 */
if (ValBit(LcFlag,fLcTxRxSc)){
if (LcSt0Cnt == 0) LcFlag = 0;
if ((u8)(*LcByteCnt & LcBitCnt) == 0){
OCR2 += 768/16; /* 0.768mS */
} else {
OCR2 += 2304/16; /* 2.304mS/3.072mS/3.4mS */
}
if ((LcBitCnt <<= 1) == 0){
LcBitCnt = 1;
LcByteCnt++;
--LcSt0Cnt;
}
} else {
OCR2 += 3840/16; /* 3.84mS */
SetBit(LcFlag,fLcTxRxSc);
LcBitCnt = 1;
LcByteCnt = LcBufAdr;
if (LcBufAdr[0] == 0x7E){
LcSt0Cnt = (u8)((LcBufAdr[1] & 0x0F) + 4);
} else {
LcSt0Cnt = 8; /* 8字节 */
}
LcComTm = 0;
}
}
} else { /* 0.256mS 线控器接收 */
#endif
OCR2 += 256/16; /* 0.256mS */
/* 388 遥控器(含参数设定遥控器、按388码格式发送的线控器)
(6.1mS, 7.4mS, 3.4mS, 1.4mS, 0.6mS)
* 五型线控器 (3.84mS,3.84mS,2.304mS,0.768mS,0.768mS)
* AUX 遥控器 (9mS, 4.5mS, 1.69mS, 0.56mS, 0.56mS) */
if (!ValBit(LcFlag,fLcRxOk)){ /* 尚未处理,不接收 */
#ifdef EnSCOM
if (ValBit(Sysflag1,f1XK_YK)){ /* 1: 线控器,0:遥控器 */
ClrBit(pLCTx,pbLCTx); /* 准备接收 */
Nop3();
}
#endif
if (ValBit(pLCRx,pbLCRx)||ValBit(pLCRx,pbLCRx)){
LcSt0Cnt = 0;
if ((++LcInHiCnt > 20) && ValBit(LcFlag,fLcTxRxSc)){
LcFlag = (u8)(1<<fLcRxOk);
LcInHiCnt = 0;
}
} else {
/* 388: 9.0mS 引导脉冲
* AUX: 6.1mS 引导脉冲
* 五型线控: 3.84mS */
if (++LcSt0Cnt > 10) LcFlag = 0; /* 2.56mS, 清除所有标志 */
if (ValBit(LcFlag,fLcTxRxSc)){
/* 0.256mS - 4.096mS */
if ((LcInHiCnt < 16) && (LcInHiCnt != 0)){
/* 388: 1: 3.2mS 0: 1.4mS 2.304mS
* 五型线控: 1: 2.304mS 0: 0.768mS 1.28mS
* AUX: 1: 1.69mS 0: 0.56mS 1.28mS */
if ((ValBit(LcFlag,fLc388) && (LcInHiCnt > 8)) ||
(!ValBit(LcFlag,fLc388) && (LcInHiCnt > 4))){
*LcByteCnt |= LcBitCnt;
}
if ((LcBitCnt <<= 1) == 0){
LcBitCnt = 1;
*++LcByteCnt = 0; /* 准备接收下一个字节 */
}
}
} else if ((LcInHiCnt >= 12) && (LcInHiCnt <= 32)){
if (LcInHiCnt > 22){
/* 388: 7.4mS */
LcFlag = (u8)((1<<fLcTxRxSc)|(1<<fLc388));
} else {
/* AUX: 4.5mS
* 五型线控: 3.84mS */
LcFlag = (u8)(1<<fLcTxRxSc);
}
LcBitCnt = 1;
LcByteCnt = LcBufAdr;
LcBufAdr[0] = 0;
#ifdef EnSCOM
LcComTm = 0;
#endif
}
LcInHiCnt = 0;
}
}
#ifdef EnSCOM
}
#endif
}
/* 初始化 */
void Init_TIMA(void)
{
/* FOC0 WGM00 COM01 COM00 WGM01 CS02 CS01 CS00 */
TCCR2 = 0x05; /* Normal, OC2 Disconnected, 1:128 */
ASSR = 0x00; /* */
//TCNT2 = 0x00; /* 清除 T0 */
OCR2 = (u8)(256/16); /* 设置中断时间 0.256mS */
//TIFR = 0x0FF;
TIMSK |= (u8)(1 << OCIE2);
//LcInHiCnt = 0;
//LcSt0Cnt = 0;