本帖最后由 huanyufei 于 2009-8-23 21:29 编辑
知道16F查表不能越界,而导致死机应该还是查表时超出了范围。可3天了,仍然没有找到真正原因。
要发送的字符数组
const unsigned char acucHead[7]={"\n$SIG,"};
const unsigned char acucCmd[6][10]={{"ON\n"},{"OFF\n"},{"FAIL\n"},{"REST\n"},{"TEST ON\n"},{"TEST OFF\n"}};
const unsigned char acucName[27][33]={
{"STEERING LIGHT.P(01),"},
{"DANGEROUS LIGHT(02),"},
{"SUEZ SIGNAL L.T-R.P(03),"},
{"SUEZ SIGNAL L.T-W.P(04),"},
{"SUEZ SIGNAL L.T-G.P(05),"},
{"SUEZ SIGNAL L.T-R.P(06),"},
{"SUEZ SIGNAL L.T-R.P(07),"},
{"SUEZ SIGNAL L.T-W.P(08),"},
{"STEERING LIGHT.S(09),"},
{"SUEZ SIGNAL L.T-R.S(10),"},
{"SUEZ SIGNAL L.T-W.S(11),"},
{"SUEZ SIGNAL L.T-R.S(12),"},
{"SUEZ SIGNAL L.T-W.S(13),"},
{"SUEZ SIGNAL L.T-R.S(14),"},
{"SUEZ SIGNAL L.T-R.S(15),"},
{"SUEZ SIGNAL L.T(16),"},
{"NULL(17),"},
{"NULL(18),"},
{"NULL(19),"},
{"NULL(20),"},
{"NULL(21),"},
{"NULL(22),"},
{"NULL(23),"},
{"NULL(24),"},
{"POWER MSB,"},
{"POWER ESB,"},
{"SYSTEM,"}
};
发送函数:(发送前获得ucNameIndex、ucCmdIndex值)
void UsartSnd()
{
while(TXIE) //等待上一次发送完成
{
asm("clrwdt");
}
ucHdNameIndex=ucNameIndex; //发送系统开始工作
ucHdCmdIndex=ucCmdIndex;
ucHdIndex=0;
ucHdElmtPlace=0;
TXIE=1;
}
中断处理函数:
if(TXIE&&TXIF) //USART发送中断
{
GIE=0;
switch(ucHdIndex)
{
case 0x00: TXREG=acucHead[ucHdElmtPlace];
if(acucHead[ucHdElmtPlace]==',')
{
ucHdIndex=1;
ucHdElmtPlace=0;
}
else
ucHdElmtPlace++;
break;
case 0x01: TXREG=acucName[ucHdNameIndex][ucHdElmtPlace];
if(acucName[ucHdNameIndex][ucHdElmtPlace]==',')
{
ucHdIndex=2;
ucHdElmtPlace=0;
}
else
ucHdElmtPlace++;
break;
case 0x02: TXREG=acucCmd[ucHdCmdIndex][ucHdElmtPlace];
if(acucCmd[ucHdCmdIndex][ucHdElmtPlace]=='\n')
{
ucHdIndex=0;
ucHdElmtPlace=0;
TXIE=0;
}
else
ucHdElmtPlace++;
break;
default: TXIE=0;
}
GIE=1;
} |
|