在串口接受到的一帧数据中,时间占用4个字节,进位方式采用8421码,低位在前,高位在后,最低位代表1毫秒,其中毫秒12位,秒7位,分7位,小时6位,怎么样从中提取出时间信息?请各位帮忙一下!
接收数据缓冲区:buf[4];
char tmp[2];
tmp[0] = buf[0];
tmp[1] = (buf[1]&0xf0)>>4;
short ms=*(short*)tmp; // 毫秒
tmp[0] = buf[1]&0x0f|(buf[2]>>5);
short se = tmp[0]; // 秒
tmp[0] = (buf[2]&0x1f)|(buf[3]&0xc0);
short m = tmp[0];
short h = buf[3]&0x3f;
大概就是这样,具体调试一下就行了!