b.通过消息队列发送
在上面基础上,用一个buf装下消息,然后“打包”到消息队列,通过消息队列的方式(FIFO)发送出去。
static uint8_t sDGUS_SendBuf[DGUS_PACKAGE_LEN];
//往DGDS屏指定寄存器写一字节数据
void DGUS_REG_WriteWord(uint8_t RegAddr, uint16_t Data)
{
sDGUS_SendBuf[0] = DGUS_FRAME_HEAD1; //帧头
sDGUS_SendBuf[1] = DGUS_FRAME_HEAD2;
sDGUS_SendBuf[2] = 0x06; //长度
sDGUS_SendBuf[3] = DGUS_CMD_W_CTRL; //指令
sDGUS_SendBuf[4] = RegAddr; //地址
sDGUS_SendBuf[5] = (uint8_t)(Data>>8); //数据
sDGUS_SendBuf[6] = (uint8_t)(Data&0xFF);
DGUS_CRC16(&sDGUS_SendBuf[3], sDGUS_SendBuf[2] - 2, &sDGUS_CRC_H, &sDGUS_CRC_L);
sDGUS_SendBuf[7] = sDGUS_CRC_H; //校验
sDGUS_SendBuf[8] = sDGUS_CRC_L;
DGUSSend_Packet_ToQueue(sDGUS_SendBuf, sDGUS_SendBuf[2] + 3);
}
//往DGDS屏指定地址写一字节数据
void DGUS_DATA_WriteWord(uint16_t DataAddr, uint16_t Data)
{
sDGUS_SendBuf[0] = DGUS_FRAME_HEAD1; //帧头
sDGUS_SendBuf[1] = DGUS_FRAME_HEAD2;
sDGUS_SendBuf[2] = 0x07; //长度
sDGUS_SendBuf[3] = DGUS_CMD_W_DATA; //指令
sDGUS_SendBuf[4] = (uint8_t)(DataAddr>>8); //地址
sDGUS_SendBuf[5] = (uint8_t)(DataAddr&0xFF);
sDGUS_SendBuf[6] = (uint8_t)(Data>>8); //数据
sDGUS_SendBuf[7] = (uint8_t)(Data&0xFF);
DGUS_CRC16(&sDGUS_SendBuf[3], sDGUS_SendBuf[2] - 2, &sDGUS_CRC_H, &sDGUS_CRC_L);
sDGUS_SendBuf[8] = sDGUS_CRC_H; //校验
sDGUS_SendBuf[9] = sDGUS_CRC_L;
DGUSSend_Packet_ToQueue(sDGUS_SendBuf, sDGUS_SendBuf[2] + 3);
}
|