void UartAction(unsigned char *buf, unsigned char len)
{
unsigned char i;
unsigned char cmd0[] = "buzz on"; //开蜂鸣器命令
unsigned char cmd1[] = "buzz off"; //关蜂鸣器命令
unsigned char cmd2[] = "showstr "; //字符串显示命令
unsigned char cmdLen[] = { //命令长度汇总表
sizeof(cmd0)-1, sizeof(cmd1)-1, sizeof(cmd2)-1,
};
uchar *cmdPtr[] = { //命令指针汇总表
&cmd0[0], &cmd1[0], &cmd2[0],
};
for (i=0; i<sizeof(cmdLen); i++) //遍历命令列表,查找相同命令
{
if (len >= cmdLen[i]) //首先接收到的数据长度要不小于命令长度
{
if (CmpMemory(buf, cmdPtr[i], cmdLen[i])) //比较相同时退出循环
{
break;
}
}
}
这段程序中定义uchar *cmdPtr[]用于存放上面数组的首地址,不知道为什么编译老出错,说是initializer must be constant,有没有大神指点下,是不是与const有关,51中在uchar后面有code编译没问题(unsigned char定义为uchar) |