#include 'reg52.h'
typedef unsigned char uint8;
typedef unsigned int uint16;
typedef unsigned long uint32;
#define TIMER_HIGHT
0xf8
#define TIMER_LOW 0xcd
sbit bRunLED =P3^4; //运行指示灯
sbit bWatchDog =P1^7; //看门狗复位
sbit b485Send= P1^3; //75LBC184 发送接收控制
uint32 dwTickCount,dwIntTick; //时钟
uint8 idata sendBuf[16],receBuf[16]; //发送接收缓冲区
uint8 idata checkoutError; // ==2 偶校验错
uint8 idata receTimeOut; //接收超时
uint8 idata c10ms;
//10ms 计时
bit b1ms,bt1ms,b10ms,bt10ms,b100ms,bt100
#include <REG52.H>
unsigned char RunMode;
void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++);
}
unsigned char code LEDDisplayCode[] = {
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8, //0~7
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF};
void Display(unsigned char Value)
{
P3 = LEDDisplayCode[Value];
}
#include 'reg52.h'
typedef unsigned char uint8
typedef unsigned int uint16
uint8 sendCount;
uint8 receCount;
uint8 sendPosi;
//字地址 0 - 255 (只取低8位)
//位地址 0 - 255 (只取低8位)
/// CRC 高位字节值表 ///
const uint8 code auchCRCHi[] = {
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01
#include <REG52.h>
#include <string.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define ushort unsigned short
#define MAX_DATA_LENGTH 32
typedef struct//定义数据发送包
{
uchar head;//包头
uchar length;//数据长度
uchar cmd;//命令
uchar sData[6];//数据
uchar crc;//校验
uchar end;//包尾
} Packet,*PT;
typedef struct//定义接收缓冲区
{
uchar iCnt;