金牌会员
- 积分
- 1986
- 威望
- 1222
- 贡献
- 504
- 兑换币
- 410
- 注册时间
- 2013-10-4
- 在线时间
- 130 小时
|
9#
楼主 |
发表于 2013-12-4 23:57:41
|
只看该作者
简单丹 发表于 2013-12-4 19:27
怎么用??
我会了
/*这是头文件 sbq.h*/
# ifndef _SBQ_H_
# define _SBQ_H_
//extern s16 pulse;
unsigned short CRC_CHECK(unsigned char *Buf, unsigned char CRC_CNT);
void OutPut_Data(void);
void sbq(float a, float b, float c, float d);
#endif
/*这是库函数 sbq.c*/
/*************************虚拟示波器底层驱动*********************************/
# include "common.h"
# include "uart.h"
//# include "zjjm.h"
# include "sbq.h"
extern u16 ADresult;
float OutData[4] = { 0 };
/*配合串口示波器的校验协议*/
unsigned short CRC_CHECK(unsigned char *Buf, unsigned char CRC_CNT)
{
unsigned short CRC_Temp;
unsigned char i,j;
CRC_Temp = 0xffff;
for (i=0;i<CRC_CNT; i++){
CRC_Temp ^= Buf;
for (j=0;j<8;j++)
{
if (CRC_Temp & 0x01)
CRC_Temp = (CRC_Temp >>1 ) ^ 0xa001;
else
CRC_Temp = CRC_Temp >> 1;
}
}
return(CRC_Temp);
}
/* 配合串口示波器的输出协议*/
void OutPut_Data(void)
{
int temp[4] = {0};
unsigned int temp1[4] = {0};
unsigned char databuf[10] = {0};
unsigned char i;
unsigned short CRC16 = 0;
for(i=0;i<4;i++)
{
temp = (int)OutData;
temp1 = (unsigned int)temp;
}
for(i=0;i<4;i++)
{
databuf[i*2] = (unsigned char)(temp1%256);
databuf[i*2+1] = (unsigned char)(temp1/256);
}
CRC16 = CRC_CHECK(databuf,8);
databuf[8] = CRC16%256;
databuf[9] = CRC16/256;
for(i=0;i<10;i++)
uart_putchar(UART3,databuf);
}
void sbq(float a, float b, float c, float d)
{
OutData[0]=a;
OutData[1]=b;
OutData[2]=c;
OutData[3]=d;
OutPut_Data();
}
/*
在主函数里面只要调用这个函数void sbq(float a, float b, float c, float d)就可以把a, b, c, d 四个变量发送到串口(要添加文件),电脑端选择com口和波特率就好*/
|
|