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

📄 per.h

📁 Keil 下编译的基于mcs51单片机的PCA82C250CAN收发器控制的程序源代码。
💻 H
📖 第 1 页 / 共 3 页
字号:
//********************************************************************************
//this header file include prototype of function which about periferals the
//peripherals 
//include:A/D convert,PWM in c505/c515 ,PWM in the c505c.  programable 
//extended port 8255.       
//********************************************************************************

//********************************************************************************
//@OR operate constant which or operate 
//with a variable only change one bit to "1"
//********************************************************************************
#define OR_BIT7 0x80
#define OR_BIT6 0x40
#define OR_BIT5 0x20
#define OR_BIT4 0x10
#define OR_BIT3 0x08
#define OR_BIT2 0x04
#define OR_BIT1 0x02
#define OR_BIT0 0x01
//********************************************************************************
//@AND operate constant which and operate
//with a variable only change one bit to "0"
//********************************************************************************
#define AND_BIT7 0x7f
#define AND_BIT6 0xbf
#define AND_BIT5 0xdf
#define AND_BIT4 0xef
#define AND_BIT3 0xf7
#define AND_BIT2 0xfb
#define AND_BIT1 0xfd
#define AND_BIT0 0xfe
/////////////constant definition/////////////////////////////////////////////////
//*******************************************************************************
//@constant of Timer2 reload mode
//*******************************************************************************
#define fosc 12.00             //fosc's unit is MHz;
//*******************************************************************************
//@constant of the sensor circuit
//*******************************************************************************
#define VREF            5      //the reference voltage for the sensor and A/D convert 
#define AD_FULL_VALUE   1023
#define VCC             9
//******************************************************************************
//@constant of the timer
//******************************************************************************
#define T1_TH 0xfd        //for serial port communication ,20.83K
#define T1_TL 0xfd
//#define T1_TH 0xcc        //for serial port communication ,2.6Kbps
//#define T1_TL 0xcc

//--------------------------------------------
//	b=fosc/(32*6*(256-c))
//   if SMOD=1, C=256-2*1000000/16b
//	 if SMOD=0, C=256-1000000/16b
//   C---counter initial vale; b---boundrate;
//--------------------------------------------
//#define T0_TH 0x63        //20ms  at 12MHz fosc
//#define T0_TL 0xc0
#define T0_TH 0xf0        //2ms  at 12MHz fosc
#define T0_TL 0x60

//#define T2_TH 0xf8        //2ms at 12MHz fosc ,clocked with fosc/12
//#define T2_TL 0x2f

#define T2_TH 0xb1        //20ms at 12MHz fosc ,clocked with fosc/12
#define T2_TL 0xe0
/*================================================================================|
|calculate way about the count value(mode 1):  Time=(65536-CountValue)* (1/fosc)*12| 
|                                            or CountValue=65536-Time*fosc/12     |  
|================================================================================*/
//#define WDT_TIME 0xe7     //time-out period is 102.4ms
#define WDT_TIME 0xc2     //time-out period is 250ms
/*=================================================================================|
|calculate way about time-out count value:                                         |
|if WDTPSEL=1,time=(32768-CountValue)*1/(12/6/32)us                                |
|	     or CountValue=32768-time/16us ,only get high seven bit for WDTH           |
|if WDTPSEL=0,time=(32768-CountValue)*1/(12/6/2)us                                 |
|		 or CountValue=32768-time/1us,only get high seven bit for WDTH             |
|==================================================================================*/

#define AD_TIME			10//200ms A/D convert once

#define SEND_GAP1		6//
#define SEND_GAP2		2
#define RECEIVE_DELAY	2//if have received a byte,but can't receive next for a long time,clear
#define MILEAGE_TIME	50
#define CLEAR_DELAY_TIME	300
#define EX1_OFF_TIME	15//ex1 off 300ms
#define FRE2_CAL_TIME	15//frequcency calculate time 300ms

#define RXD_MAX_NUM		13
#define TXD_MAX_NUM		51

#define ERROR_TIMES		3
/*================================================================================|
|calculate way about the count value(mode 1):  Time=(65536-CountValue)* (1/fosc)*6| 
|                                            or CountValue=65536-Time*fosc/6      |  
|================================================================================*/
//******************************************************************************
//@CPU customer port define
//******************************************************************************
///about x5045
///command words difinition
#define WREN	  0x06 //enable write
#define WRDI      0x04 //disable write
#define RDSR	  0x05 //read status register
#define WRSR	  0x01 //write status register
#define READ0 	  0x03 // read data from address 0-ffh
#define READ1     0x0b // read data from address 100-1ffh
#define WRITE0	  0x02 // write data to memory  0-ffh
#define WRITE1    0x0a // write data to memory  100-1ffh
/////////////////////////////////////////////////////////////////
#define EE_POWER1			  0x04
#define EE_POWER2			  0x05

#define RUN_MILEAGE	  	 	  0x20
#define SINGLE_MILEAGE	  	  0x24
#define TOTAL_MILEAGE	      0x28
#define RUN_ERROR_TIMES	      0x2c
#define RUN_TIME	          0x2d
#define FUEL_USE	          0x2e
//define ERROR_CODE0			  0x57
#define ERROR_CODE0			  0x49	//changed by lihx 2004/09/15
#define ERROR_CODE1			  0x50
#define ERROR_CODE2			  0x51
#define ERROR_CODE3			  0x52
#define ERROR_CODE4			  0x53
#define ERROR_CODE5			  0x54
#define ERROR_CODE6			  0x55
#define ERROR_CODE7			  0x56



/////////////////////////////////////////////////////////////////
///ports connected to CPU difinition
sbit cs5045  =P3^4;
sbit so5045  =P3^5;
sbit si5045  =P3^6;
sbit sck5045 =P3^7;
//@A/D channel define
//*******************************************************************************
#define FUEL_Q     0
#define AIR_1      1
#define AIR_2      2
//*******************************************************************************
//@definition of the warn signal light constant
//*******************************************************************************
#define WATER_T_WARN       20
#define FUEL_P_WARN        20
#define AIR_P_WARN         20
/////////////fuction's prototype for A/D convert////////////////////////////////
//******************************************************************************
//function:    void ad_init(ChSelect);
//description: initialize ad converter as single convertion mode.fadc=1.5MHz
//input:       none
//return:      none;
//*******************************************************************************
void ad_init(unsigned char ChSelect);   //A/D initialization;
//*******************************************************************************
//function:  unsigned char ad_single(unsigned char ch);
//input:     unsigned char ch   select A/D chanel;
//return:    unsigned int     A/D converted value(value= return*5.0/1024V);
//*******************************************************************************
unsigned int ad_single(unsigned char ch);//A/D convertion for once;
//******************************************************************************************
//function:     float AD_V(unsigned int ADValue,unsigned int ADFullValue,float vref);
//description:  calculate input voltage according to the gather value,A/D full value and 
//              reference voltage.
//parameter:    ADValue---A/D converter gather value;

⌨️ 快捷键说明

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