📄 sc16is752.c
字号:
{
//add
frame_leng = uartSC16IS752A_copy(uartSC16IS752A_ack_buff); // 复制一帧数据
}
switch (uartSC16IS752A_cmmd)
{
case 0x01: // 询问命令
{
uartSC16IS752A_tbuf[ 0] = 0xf5; // 01 F5
uartSC16IS752A_tbuf[ 1] = 0x89; // 02 89
uartSC16IS752A_tbuf[ 2] = 0xc7; // 03 C7
uartSC16IS752A_tbuf[ 3] = 0x00;//system_id; // 04 系统编号
uartSC16IS752A_tbuf[ 4] = uartSC16IS752A_type; // 05 第一设备种类
uartSC16IS752A_tbuf[ 5] = uartSC16IS752A_addr; // 06 第一设备地址
uartSC16IS752A_tbuf[ 6] = 0x00;//locl_type; // 07 第二设备种类
uartSC16IS752A_tbuf[ 7] = 0x00;//locl_addr; // 08 第二设备地址
uartSC16IS752A_tbuf[ 8] = uartSC16IS752A_cmmd; // 09 命令码
uartSC16IS752A_tbuf[ 9] = uartSC16IS752A_cycl; // 10 发送周期
uartSC16IS752A_tbuf[10] = 0x00; // 11 重发次数
uartSC16IS752A_tbuf[11] = 0x00; // 12 数据长度(高8位)
uartSC16IS752A_tbuf[12] = 0x06; // 13 数据长度(低8位)
uartSC16IS752A_tbuf[13] = 0x00;//curt_temp >> 8; // 当前温度(高8位)
uartSC16IS752A_tbuf[14] = 0x00;//curt_temp; // 当前温度(低8位)
uartSC16IS752A_tbuf[15] = 0x00;//curt_hmdt >> 8; // 当前湿度(高8位)
uartSC16IS752A_tbuf[16] = 0x00;//curt_hmdt; // 当前湿度(低8位)
uartSC16IS752A_tbuf[17] = 0x00;//curt_brit; // 当前亮度
uartSC16IS752A_tbuf[18] = 0x00;//curt_port; // 当前端口状态
uartSC16IS752A_tbuf[19] = 0x00; // 14 校验和
uartSC16IS752A_send(20); // 发送返回数据帧
break; // 退出case
}
case 0x02: // 读取当前温度
{
uartSC16IS752A_tbuf[ 0] = 0xf5; // 01 F5
uartSC16IS752A_tbuf[ 1] = 0x89; // 02 89
uartSC16IS752A_tbuf[ 2] = 0xc7; // 03 C7
uartSC16IS752A_tbuf[ 3] = 0x00;//system_id; // 04 系统编号
uartSC16IS752A_tbuf[ 4] = uartSC16IS752A_type; // 05 第一设备种类
uartSC16IS752A_tbuf[ 5] = uartSC16IS752A_addr; // 06 第一设备地址
uartSC16IS752A_tbuf[ 6] = 0x00;//locl_type; // 07 第二设备种类
uartSC16IS752A_tbuf[ 7] = 0x00;//locl_addr; // 08 第二设备地址
uartSC16IS752A_tbuf[ 8] = uartSC16IS752A_cmmd; // 09 命令码
uartSC16IS752A_tbuf[ 9] = uartSC16IS752A_cycl; // 10 发送周期
uartSC16IS752A_tbuf[10] = 0x00; // 11 重发次数
uartSC16IS752A_tbuf[11] = 0x00; // 12 数据长度(高8位)
uartSC16IS752A_tbuf[12] = 0x02; // 13 数据长度(低8位)
uartSC16IS752A_tbuf[13] = 0x00;//curt_temp >> 8; // 当前温度(高8位)
uartSC16IS752A_tbuf[14] = 0x00;// curt_temp; // 当前温度(低8位)
uartSC16IS752A_tbuf[15] = 0x00; // 14 校验和
uartSC16IS752A_send(16); // 发送返回数据帧
break; // 退出case
}
default:
{
uartSC16IS752A_send_nack(); // 发送ACK确认帧
break; // 退出case
}
}
}
/*******************************************************************************
* 名 称: uartSC16IS752A_send_nack
* 功 能: 发送ACK确认帧
* 入口参数: 无
* 出口参数: 无
*******************************************************************************/
void uartSC16IS752A_send_nack (void)
{
uartSC16IS752A_tbuf[ 0] = 0xf5; // 01 F5
uartSC16IS752A_tbuf[ 1] = 0x89; // 02 89
uartSC16IS752A_tbuf[ 2] = 0xc7; // 03 C7
uartSC16IS752A_tbuf[ 3] = system_id; // 04 系统编号
uartSC16IS752A_tbuf[ 4] = uartSC16IS752A_type; // 05 第一设备种类
uartSC16IS752A_tbuf[ 5] = uartSC16IS752A_addr; // 06 第一设备地址
uartSC16IS752A_tbuf[ 6] = uartSC16IS752A_type; // 07 第二设备种类
uartSC16IS752A_tbuf[ 7] = uartSC16IS752A_addr; // 08 第二设备地址
uartSC16IS752A_tbuf[ 8] = 0x00; // 09 命令码
uartSC16IS752A_tbuf[ 9] = uartSC16IS752A_cycl; // 10 发送周期
uartSC16IS752A_tbuf[10] = 0x00; // 11 重发次数
uartSC16IS752A_tbuf[11] = 0x00; // 12 数据长度(高8位)
uartSC16IS752A_tbuf[12] = 0x00; // 13 数据长度(低8位)
uartSC16IS752A_tbuf[13] = 0x00; // 14 校验和
uartSC16IS752A_send(14); // 发送应答帧
}
/****************************************************************************
* 名 称: uartSC16IS752A_send
* 功 能: 准备uart0发送
* 入口参数: data_leng: 发送数据长度
* 出口参数: 无
****************************************************************************/
void uartSC16IS752A_send (uint data_leng)
{
uint i;
uchar ch;
uartSC16IS752A_tlen = data_leng; // 置发送帧长度
for(i=0,ch=0; i<(data_leng-1); i++) // 计算校验和
{
ch = ch + uartSC16IS752A_tbuf[i]; // 计算校验和
}
uartSC16IS752A_tbuf[i] = 0x100 - ch; // 计算校验和
uartSC16IS752A_tsdy = 3; // uart0延时3mS后发送
}
/****************************************************************************
* 名 称: uartSC16IS752B_send
* 功 能: 准备uartSC16IS752B发送
* 入口参数: data_leng: 发送数据长度
* 出口参数: 无
****************************************************************************/
void uartSC16IS752B_send (uint data_leng)
{
uint i;
uchar ch;
uartSC16IS752B_tlen = data_leng; // 置发送帧长度
for(i=0,ch=0; i<(data_leng-1); i++) // 计算校验和
{
ch = ch + uartSC16IS752B_tbuf[i];
}
uartSC16IS752B_tbuf[i] = 0x100 - ch;
uartSC16IS752B_tsdy = 3; // uartSC16IS752B延时3mS后发送
}
/****************************************************************************
* 名 称: uartSC16IS752A_sendst
* 功 能: 启动uart0发送
* 入口参数: 无
* 出口参数: 无
****************************************************************************/
void uartSC16IS752A_sendst (void)
{
uint i;
IO0SET = isDRE0; // DRE0=1, 485发送
for (i=50; i>0; i--) ; // 延时6uS, 确保485转换结束
WriteRegister(THR,ChannelA,uartSC16IS752A_tbuf[uartSC16IS752A_tptr]); // 复制到发送FIFO
uartSC16IS752A_tptr++; // 缓冲区指针加1
uartSC16IS752A_tlen--; // 发送长度减1
//U0IER = 0x03; // 开发送中断
WriteRegister(IER,ChannelA,0X03); // 开发送中断
}
/****************************************************************************
* 名 称: uartSC16IS752B_sendst
* 功 能: 启动uartSC16IS752B发送
* 入口参数: 无
* 出口参数: 无
****************************************************************************/
void uartSC16IS752B_sendst (void)
{
uint i;
IO0SET = isDRE1; // DRE0=1, 485发送
for (i=50; i>0; i--) ; // 延时6uS, 确保485转换结束
WriteRegister(THR,ChannelB,uartSC16IS752B_tbuf[uartSC16IS752B_tptr]); // 复制到发送FIFO
uartSC16IS752B_tptr++; // 缓冲区指针加1
uartSC16IS752B_tlen--; // 发送长度减1
//U0IER = 0x03; // 开发送中断
WriteRegister(IER,ChannelB,0X03); // 开发送中断
}
/*
void testSend(void)
{
uartSC16IS752A_tbuf[ 0] = 0xf5; // 01 F5
uartSC16IS752A_tbuf[ 1] = 0x89; // 02 89
uartSC16IS752A_tbuf[ 2] = 0xc7; // 03 C7
uartSC16IS752A_tbuf[ 3] = 0x00;//system_id; // 04 系统编号
uartSC16IS752A_tbuf[ 4] = uartSC16IS752A_type; // 05 第一设备种类
uartSC16IS752A_tbuf[ 5] = uartSC16IS752A_addr; // 06 第一设备地址
uartSC16IS752A_tbuf[ 6] = 0x00;//locl_type; // 07 第二设备种类
uartSC16IS752A_tbuf[ 7] = 0x00;//locl_addr; // 08 第二设备地址
uartSC16IS752A_tbuf[ 8] = uartSC16IS752A_cmmd; // 09 命令码
uartSC16IS752A_tbuf[ 9] = uartSC16IS752A_cycl; // 10 发送周期
uartSC16IS752A_tbuf[10] = 0x00; // 11 重发次数
uartSC16IS752A_tbuf[11] = 0x00; // 12 数据长度(高8位)
uartSC16IS752A_tbuf[12] = 0x05; // 13 数据长度(低8位)
uartSC16IS752A_tbuf[13] = 0x00;//time_ponh; // 开机时间(时)
uartSC16IS752A_tbuf[14] = 0x00;//time_ponm; // 开机时间(分)
uartSC16IS752A_tbuf[15] = 0x00;//time_pofh; // 关机时间(时)
uartSC16IS752A_tbuf[16] = 0x00;//time_pofm; // 关机时间(分)
uartSC16IS752A_tbuf[17] = 0x00;//time_pctl; // 定时开关电源
uartSC16IS752A_tbuf[18] = 0x00; // 14 校验和
uartSC16IS752A_send(19); // 发送返回数据帧
}
*/
/*******************************************************************************
* 名 称: uart0_SendToDrivers
* 功 能: 发送PWM值到各驱动器
* 入口参数: 驱动器地址号 暂时(0-20)
* 出口参数: 无
* Edit by : jumping
*******************************************************************************/
void uartSC16IS752A_SendToDrivers (uchar iport)
{
uartSC16IS752A_tbuf[ 0] = 0xf5; // 01 F5
uartSC16IS752A_tbuf[ 1] = 0x89; // 02 89
uartSC16IS752A_tbuf[ 2] = 0xc7; // 03 C7
uartSC16IS752A_tbuf[ 3] = 0xff;//system_id; // 04 系统编号
uartSC16IS752A_tbuf[ 4] = 0xff;//uart0_type; // 05 第一设备种类
uartSC16IS752A_tbuf[ 5] = iport;//uart0_addr; // 06 第一设备地址
uartSC16IS752A_tbuf[ 6] = locl_type; // 07 第二设备种类
uartSC16IS752A_tbuf[ 7] = 0xff;//locl_addr; // 08 第二设备地址
uartSC16IS752A_tbuf[ 8] = uart0_cmmd; // 09 命令码
uartSC16IS752A_tbuf[ 9] = 00;//uart0_cycl; // 10 发送周期
uartSC16IS752A_tbuf[10] = 0x00; // 11 重发次数
uartSC16IS752A_tbuf[11] = 0x00; // 12 数据长度(高8位)
uartSC16IS752A_tbuf[12] = 0x01; // 13 数据长度(低8位)
uartSC16IS752A_tbuf[13] = drv_pwm_val[iport]; // 当前温度(高8位)
uartSC16IS752A_tbuf[14] = 0x00; // 14 校验和
uartSC16IS752A_send(15); // 发送返回数据帧
// 退出case
}
/*******************************************************************************
* 名 称: uart0_SendToDrivers
* 功 能: 发送PWM值到各驱动器
* 入口参数: 驱动器地址号 暂时(0-20)
* 出口参数: 无
* Edit by : jumping
*******************************************************************************/
void uartSC16IS752B_SendToDrivers (uchar iport)
{
uartSC16IS752B_tbuf[ 0] = 0xf5; // 01 F5
uartSC16IS752B_tbuf[ 1] = 0x89; // 02 89
uartSC16IS752B_tbuf[ 2] = 0xc7; // 03 C7
uartSC16IS752B_tbuf[ 3] = 0xff;//system_id; // 04 系统编号
uartSC16IS752B_tbuf[ 4] = 0xff;//uart0_type; // 05 第一设备种类
uartSC16IS752B_tbuf[ 5] = iport;//uart0_addr; // 06 第一设备地址
uartSC16IS752B_tbuf[ 6] = locl_type; // 07 第二设备种类
uartSC16IS752B_tbuf[ 7] = 0xff;//locl_addr; // 08 第二设备地址
uartSC16IS752B_tbuf[ 8] = uart0_cmmd; // 09 命令码
uartSC16IS752B_tbuf[ 9] = 00;//uart0_cycl; // 10 发送周期
uartSC16IS752B_tbuf[10] = 0x00; // 11 重发次数
uartSC16IS752B_tbuf[11] = 0x00; // 12 数据长度(高8位)
uartSC16IS752B_tbuf[12] = 0x01; // 13 数据长度(低8位)
uartSC16IS752B_tbuf[13] = drv_pwm_val[iport]; // 当前温度(高8位)
uartSC16IS752B_tbuf[14] = 0x00; // 14 校验和
uartSC16IS752B_send(15); // 发送返回数据帧
// 退出case
}
/*******************************************************************************
* 名 称: Nint_SC16IS752A
* 功 能: 发送PWM值到各驱动器
* 入口参数: 驱动器地址号 暂时(0-20)
* 出口参数: 无
* Edit by : jumping
*******************************************************************************/
void Nint_SC16IS752A (uchar iport)
{
uchar i,ch=0;
uartSC16IS752A_tbuf[ 0] = 0xf5; // 01 F5
uartSC16IS752A_tbuf[ 1] = 0x89; // 02 89
uartSC16IS752A_tbuf[ 2] = 0xc7; // 03 C7
uartSC16IS752A_tbuf[ 3] = 0xff;//system_id; // 04 系统编号
uartSC16IS752A_tbuf[ 4] = 0xff;//uart0_type; // 05 第一设备种类
uartSC16IS752A_tbuf[ 5] = iport;//uart0_addr; // 06 第一设备地址
uartSC16IS752A_tbuf[ 6] = locl_type; // 07 第二设备种类
uartSC16IS752A_tbuf[ 7] = 0xff;//locl_addr; // 08 第二设备地址
uartSC16IS752A_tbuf[ 8] = uart0_cmmd; // 09 命令码
uartSC16IS752A_tbuf[ 9] = 00;//uart0_cycl; // 10 发送周期
uartSC16IS752A_tbuf[10] = 0x00; // 11 重发次数
uartSC16IS752A_tbuf[11] = 0x00; // 12 数据长度(高8位)
uartSC16IS752A_tbuf[12] = 0x01; // 13 数据长度(低8位)
uartSC16IS752A_tbuf[13] = drv_pwm_val[iport]; // 当前温度(高8位)
uartSC16IS752A_tbuf[14] = 0x00; // 14 校验和
//uartSC16IS752A_send(15); // 发送返回数据帧
for(i=0,ch=0; i<14; i++) // 计算校验和
{
ch = ch + uartSC16IS752A_tbuf[i];
}
uartSC16IS752A_tbuf[i] = 0x100 - ch;
uartSC16IS752A_tlen=15;
uartSC16IS752A_tptr=0;
IO0SET = isDRE0; // DRE0=1, 485发送
for (i=50; i>0; i--) ; // 延时6uS, 确保485转换结束
// WriteRegister(IER,ChannelB,0X01); // 关发送中断
for (i=0; (i<15) && (uartSC16IS752A_tlen>0); i++)
{
WriteRegister(THR,ChannelA, uartSC16IS752A_tbuf[ uartSC16IS752A_tptr]); //发送数据
uartSC16IS752A_tptr++; // 缓冲区指针加1
uartSC16IS752A_tlen--; // 长度减1
}
//uartSC16IS752A_tptr = 0; // 复位缓冲区指针
for (i=50; i>0; i--) ; // 延时6uS, 确保485转换结束
IO0CLR = isDRE0; // DRE0=0, 485接受
}
/*******************************************************************************
* 名 称: Nint_SC16IS752B
* 功 能: 发送PWM值到各驱动器
* 入口参数: 驱动器地址号 暂时(0-20)
* 出口参数: 无
* Edit by : jumping
*******************************************************************************/
void Nint_SC16IS752B (uchar iport)
{
uchar i,ch=0;
uartSC16IS752B_tbuf[ 0] = 0xf5; // 01 F5
uartSC16IS752B_tbuf[ 1] = 0x89; // 02 89
uartSC16IS752B_tbuf[ 2] = 0xc7; // 03 C7
uartSC16IS752B_tbuf[ 3] = 0xff;//system_id; // 04 系统编号
uartSC16IS752B_tbuf[ 4] = 0xff;//uart0_type; // 05 第一设备种类
uartSC16IS752B_tbuf[ 5] = iport;//uart0_addr; // 06 第一设备地址
uartSC16IS752B_tbuf[ 6] = locl_type; // 07 第二设备种类
uartSC16IS752B_tbuf[ 7] = 0xff;//locl_addr; // 08 第二设备地址
uartSC16IS752B_tbuf[ 8] = uart0_cmmd; // 09 命令码
uartSC16IS752B_tbuf[ 9] = 00;//uart0_cycl; // 10 发送周期
uartSC16IS752B_tbuf[10] = 0x00; // 11 重发次数
uartSC16IS752B_tbuf[11] = 0x00; // 12 数据长度(高8位)
uartSC16IS752B_tbuf[12] = 0x01; // 13 数据长度(低8位)
uartSC16IS752B_tbuf[13] = drv_pwm_val[iport]; // 当前温度(高8位)
uartSC16IS752B_tbuf[14] = 0x00; // 14 校验和
//uartSC16IS752B_send(15); // 发送返回数据帧
for(i=0,ch=0; i<14; i++) // 计算校验和
{
ch = ch + uartSC16IS752B_tbuf[i];
}
uartSC16IS752B_tbuf[i] = 0x100 - ch;
uartSC16IS752B_tlen=15;
uartSC16IS752B_tptr=0;
IO0SET = isDRE1; // DRE0=1, 485发送
for (i=50; i>0; i--) ; // 延时6uS, 确保485转换结束
// WriteRegister(IER,ChannelB,0X01); // 关发送中断
for (i=0; (i<15) && (uartSC16IS752B_tlen>0); i++)
{
WriteRegister(THR,ChannelB, uartSC16IS752B_tbuf[ uartSC16IS752B_tptr]); //发送数据
uartSC16IS752B_tptr++; // 缓冲区指针加1
uartSC16IS752B_tlen--; // 长度减1
}
//uartSC16IS752A_tptr = 0; // 复位缓冲区指针
for (i=50; i>0; i--) ; // 延时6uS, 确保485转换结束
IO0CLR = isDRE1; // DRE0=0, 485接受
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -