根据以上描述我们可以编写对应不同对象访问的程序了。
(1)、写数据变量存储器
void WriteDataToLCD(uint16_t startAddress,uint8_t txData[],uint16_tlength)
{
/*命令的长度由帧头(2个字节)+数据长度(1个字节)+指令(1个字节)+起始地址(2个字节)+数据(长度为length)*/
uint16_t cmd_Length=length+6;
uint8_tcmd_VAR_Write[WriteDataCommandLength];
cmd_VAR_Write[0]=0x5A;
cmd_VAR_Write[1]=0xA5;
cmd_VAR_Write[2]=(uint8_t)(length+3);
cmd_VAR_Write[3]= FC_VAR_Write;
cmd_VAR_Write[4]=(uint8_t)(startAddress>>8);//起始地址
cmd_VAR_Write[5]=(uint8_t)startAddress;//起始地址
for(intdataIndex=0;dataIndex
{
cmd_VAR_Write[dataIndex+6]=txData[dataIndex];
}
SendData(cmd_VAR_Write,cmd_Length);
}
(2)、读变量存储器数据
void ReadDataFromLCD(uint16_t startAddress,uint8_t readWordLength)
{
//命令的长度由帧头(2个字节)+数据长度(1个字节)+指令(1个字节)+起始地址(2个字节)+读取的字长度(1个字节)
uint16_t cmd_Length=7;
uint8_tcmd_VAR_Read[]={0x5A,0xA5,0x04,FC_VAR_Read,0x00,0x00,0x00};//读数据命令
cmd_VAR_Read[4]=(uint8_t)(startAddress>>8);//起始地址
cmd_VAR_Read[5]=(uint8_t)startAddress;//起始地址
cmd_VAR_Read[6]=readWordLength;//读取长度
SendData(cmd_VAR_Read,cmd_Length);
}
(3)、写曲线缓冲区
void WriteCurveToLCD(uint8_t txData[],uint16_t length,uint8_tchannelMode)
{
//命令的长度由帧头(2个字节)+数据长度(1个字节)+指令(1个字节)+通道模式(1个字节)+数据(length,最多8个字)
uint16_t cmd_Length=length+5;
uint8_tcmd_Curve_Write[WriteCurveCommandLength];//写曲线缓冲区命令
cmd_Curve_Write[0]=0x5A;
cmd_Curve_Write[1]=0xA5;
cmd_Curve_Write[2]=(uint8_t)(length+2);
cmd_Curve_Write[3]=FC_Curve_Write;
cmd_Curve_Write[4]=channelMode;
for(intdataIndex=0;dataIndex
{
cmd_Curve_Write[dataIndex+5]=txData[dataIndex];
}
SendData(cmd_Curve_Write,cmd_Length);
}
(4)、写寄存器数据
void SetRegisterData(uint8_t regAddress,uint8_t txData[],uint16_t length)
{
//命令的长度由帧头(2个字节)+数据长度(1个字节)+指令(1个字节)+寄存器地址(1个字节)+写的数据
uint16_t cmd_Length=length+5;
uint8_tcmd_Reg_Write[WriteCurveCommandLength];//写曲线缓冲区命令
cmd_Reg_Write[0]=0x5A;
cmd_Reg_Write[1]=0xA5;
cmd_Reg_Write[2]=(uint8_t)(length+2);
cmd_Reg_Write[3]= FC_REG_Write;
cmd_Reg_Write[4]=regAddress;
for(intdataIndex=0;dataIndex
{
cmd_Reg_Write[dataIndex+5]=txData[dataIndex];
}
SendData(cmd_Reg_Write,cmd_Length);
}
(5)、读寄存器数据
void GetRegisterData(uint8_t regAddress,uint8_t readByteLength)
{
//命令的长度由帧头(2个字节)+数据长度(1个字节)+指令(1个字节)+寄存器地址(1个字节)+读取寄存器的字节长度(1个字节)
uint16_t cmd_Length=6;
uint8_tcmd_Reg_Read[]={0x5A,0xA5,0x03,FC_REG_Read,0x00,0x00};//读数据命令
cmd_Reg_Read[4]=regAddress;
cmd_Reg_Read[5]=readByteLength;
SendData(cmd_Reg_Read,cmd_Length);
}
3、测试结果
完成上述编写后,接上显示屏下装,我们来查看显示效果:
`