#include <REGX52.H>
#include <intrins.h>
#include "HC_SR04.h"
#include "uart1.h"
#include "timer.h"
#define uchar unsigned char
#define uint unsigned int
#define DATAOK 0x01
#define DistanceERROR1 0x02
#define DistanceERROR2 0x03
#define DATAOK_R 0x11
#define DATAOK_G 0x12
sbit LED_G = P1^0; //LED1
sbit LED_R = P1^1; //LED2
uchar address = 0x00;
/*包头 地址 命令 距离高位 距离低位 校验位 包尾
0x55 a b d e 0xaa
d:0x01 距离下限错误 0x02 距离上限错误
*/
void SendDataPack(uchar address,uchar com,uint S)
{
uchar senddata[7];
uchar i;
senddata[0] = 0x55;
senddata[1] = address;
senddata[2] = com;
senddata[3] = S/256;
senddata[4] = S%256;
senddata[5] = senddata[1] + senddata[2] + senddata[3] + senddata[4];
senddata[6] = 0xaa;
for(i=0;i<7;i++)
{
SendUart1Byte(senddata[i]);
}
}