⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comm.h

📁 矿工定位系统单端
💻 H
字号:
/*************************************************************************
/*                                                                       *
/*  file : comm.h           											 											 *
/*																	     																 *
/************************************************************************/
#include <absacc.h>
#define OSC_FREQ                22118400L
//TL1=TH1=[256 - (k*OSC_FREQ/16*32)/BAUD] k=1(BAUD),k=2(BAUD*2) 
#define BAUD_115200             256 - (OSC_FREQ/192L)/115200L[256 - (k*OSC_FREQ/16*32)/115200L]
#define BAUD_57600              256 - (OSC_FREQ/192L)/57600L
#define BAUD_38400              256 - (OSC_FREQ/192L)/38400L
#define BAUD_28800              256 - (OSC_FREQ/192L)/28800L
#define BAUD_19200              256 - (OSC_FREQ/192L)/19200L
#define BAUD_14400              256 - (OSC_FREQ/192L)/14400L
#define BAUD_9600               256 - (OSC_FREQ/192L)/9600L
#define BAUD_4800               256 - (OSC_FREQ/192L)/4800L
#define BAUD_2400               256 - (OSC_FREQ/192L)/2400L
#define BAUD_1200               256 - (OSC_FREQ/192L)/1200L

// Serial Protocol
#define FALSE                   0
#define TRUE                    1
sbit En485		= P4^2;			//红外或485串口选择	
#define SEND		1
#define RECV		0 

//************************************************
#define SOH                     0x01
                                        // Start of header
#define STX                     0x02	// Start of text 起始字

#define ETX                     0x03	// End of text 结束字

#define ENQ                     0x05	// Enquire

#define ACK                     0x06	// Acknowledge

#define DLE                     0x10	// Data link escape  转移字

#define NAK                     0x15	// Not acknowledge  不可识别


// Receive States

#define RECV_STX                0
#define RECV_DATA_DLE_ETX       1
#define RECV_ETX                2
#define RECV_DLE                3
#define RECV_DLE_OR_NAK         4
#define SEND_STX                5
#define RECV_ADDR0              6
#define RECV_ADDR1              7
#define RECV_ADDR2              8
#define RECV_ADDR3              9

// Serial Buffer

#define HEADER                  3

#define MAXDATA                 30
#define SUM_CHECK			    1

#define SERBUFLEN               HEADER + MAXDATA + SUM_CHECK + 1


#define T_533_ms                10





/************************* define for i/o ****************************/
sfr WDTRST  = 0xA6;

/************************* define for 12887 ****************************/
sbit uip_bit    = ACC^7 ;

/*************************** function ***********************/
void init_com(void);
void isr_timer0(void);
void isr_UART(void);
void START_T0(unsigned char x);
void CALL_isr_T0(void);
 void 	cmd_execution();
/***************************** Global Variables ********************/
volatile unsigned char xdata 	SerBuffer[SERBUFLEN];    // SERBUFLEN = 35
unsigned char xdata 					ErrorCount,Timer0Cnt,ErrorNos;
unsigned char xdata  					RecvState;
volatile bit        					DataDleReceived;
unsigned char xdata  					Index;

volatile bit        Cmdok;
volatile bit        SendOk;
volatile bit        SendReady;
volatile bit        RecvReady;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -