www.pudn.com > LTC2440.rar > LTC2440.H, change:2013-03-30,size:3352b


 
#ifndef _LTC2440_H_ 
#define _LTC2440_H_ 
 
//PC15 
 
#define LTC2440_BUSY_I    (GPIOC->CRH&=~GPIO_CRH_MODE15) 
#define LTC2440_BUSY_O    (GPIOC->CRH|=GPIO_CRH_MODE15) 
#define LTC2440_BUSY    (GPIOC->IDR&GPIO_IDR_IDR15) 
#define LTC2440_BUSY_H  (GPIOC->BSRR=GPIO_BSRR_BS15) 
#define LTC2440_BUSY_L  (GPIOC->BSRR=GPIO_BSRR_BR15) 
 
 
//PC13 
#define LTC2440_FO_I    (GPIOC->CRH&=~GPIO_CRH_MODE13) 
#define LTC2440_FO_O    (GPIOC->CRH|=GPIO_CRH_MODE13) 
#define LTC2440_FO	  	(GPIOC->IDR&GPIO_IDR_IDR13) 
#define LTC2440_FO_H  	(GPIOC->BSRR=GPIO_BSRR_BS13) 
#define LTC2440_FO_L  	(GPIOC->BSRR=GPIO_BSRR_BR13) 
 
//PC11 
#define LTC2440_SCK_I 	(GPIOC->CRH&=~GPIO_CRH_MODE11) 
#define LTC2440_SCK_O  	(GPIOC->CRH=(GPIOC->CRH|GPIO_CRH_MODE11)|(GPIOC->CRH&(~GPIO_CRH_CNF11))) 
#define LTC2440_SCK	  	(GPIOC->IDR&GPIO_IDR_IDR11) 
#define LTC2440_SCK_H  	(GPIOC->BSRR=GPIO_BSRR_BS11) 
#define LTC2440_SCK_L  	(GPIOC->BSRR=GPIO_BSRR_BR11) 
//PC9 
#define LTC2440_SDO_I  	((GPIOC->CRH)&=~GPIO_CRH_MODE9) 
#define LTC2440_SDO_O 	(GPIOC->CRH=(GPIOC->CRH|GPIO_CRH_MODE9)|(GPIOC->CRH&(~GPIO_CRH_CNF9))) 
#define LTC2440_SDO	  	(GPIOC->IDR&GPIO_IDR_IDR9) 
#define LTC2440_SDO_H  	(GPIOC->BSRR=GPIO_BSRR_BS9) 
#define LTC2440_SDO_L  	(GPIOC->BSRR=GPIO_BSRR_BR9) 
//PB7 
#define LTC2440_nCS_I  	(GPIOB->CRL&=GPIO_CRL_MODE7) 
#define LTC2440_nCS_O 	(GPIOB->CRL=(GPIOB->CRL|GPIO_CRL_MODE7)|(GPIOB->CRL&(~GPIO_CRL_CNF7))) 
#define LTC2440_nCS	   	(GPIOB->IDR&GPIO_IDR_IDR7) 
#define LTC2440_nCS_H  	(GPIOB->BSRR=GPIO_BSRR_BS7) 
#define LTC2440_nCS_L  	(GPIOB->BSRR=GPIO_BSRR_BR7) 
//PB5 
#define LTC2440_nEXT_I 	(GPIOB->CRL&=~GPIO_CRL_MODE5) 
#define LTC2440_nEXT_O 	(GPIOB->CRL=(GPIOB->CRL|GPIO_CRL_MODE5)|(GPIOB->CRL&(~GPIO_CRL_CNF5))) 
#define LTC2440_nEXT    (GPIOB->IDR&GPIO_IDR_IDR5) 
#define LTC2440_nEXT_H  (GPIOB->BSRR=GPIO_BSRR_BS5) 
#define LTC2440_nEXT_L  (GPIOB->BSRR=GPIO_BSRR_BR5) 
//PB3 
#define LTC2440_SDI_I  	(GPIOB->CRL&=~GPIO_CRL_MODE3) 
#define LTC2440_SDI_O  	(GPIOB->CRL=((GPIOB->CRL)|GPIO_CRL_MODE3)|((GPIOB->CRL)&(~GPIO_CRL_CNF3))) 
#define LTC2440_SDI	   	(GPIOB->IDR&GPIO_IDR_IDR3) 
#define LTC2440_SDI_H  	(GPIOB->BSRR=GPIO_BSRR_BS3) 
#define LTC2440_SDI_L  	(GPIOB->BSRR=GPIO_BSRR_BR3) 
 
#define	 uint32 unsigned long 
 
 //delay 
void delay() 
{ 
	unsigned int i = 0; 
	for(i = 0 ; i < 100 ; i ++) 
	{ 
		; 
	} 
} 
 
unsigned char TEST_EOC() 
{ 
	unsigned char tmp=0; 
 
	LTC2440_nCS_L ;  delay(); 
	if(!LTC2440_SDO) 
		tmp=1; 
	else 
		tmp=0; 
	LTC2440_nCS_H ;  
	return tmp; 
   
} 
uint32 READLTC2440(unsigned char inputdata) 
{ 
 //	uint32 outputdata=0; 
	char i; 
	uint32 tmp=0; 
 
	LTC2440_SCK_L;   delay(); 
	LTC2440_nCS_L ;  delay(); 
 
	for(i=0;i<32;i++) 
	{ 
	    if(inputdata&0x10) 
			LTC2440_SDI_H; 
		else 
			LTC2440_SDI_L; 
		inputdata<<=1;			delay();   
		LTC2440_SCK_H; 	delay();   
	 
		tmp<<=1; 
		if(LTC2440_SDO) 
			tmp|=1; 
		LTC2440_SCK_L; delay(); 
  
	}  
 
	LTC2440_nCS_H ; 
	return tmp; 
 
 
} 
 
void LTC2440Init() 
{ 
	LTC2440_nCS_O; 
	GPIOB->CRL&=~GPIO_CRL_CNF7	; 
	LTC2440_nCS_H; 
 
 
	LTC2440_nEXT_O ;   //SCK external clk 
	LTC2440_nEXT_L ; 
 
	LTC2440_FO_O;	 //internal ADC clk 
	LTC2440_FO_L; 
 
	LTC2440_SCK_O ; 
 	GPIOC->CRH&=~GPIO_CRH_CNF11	; 
 
	LTC2440_SDI_O ; 
//	GPIOB->CRL&=(~GPIO_CRL_CNF3); 
	LTC2440_SDI_L ; 
 
	LTC2440_SDO_I ; 
 
	LTC2440_BUSY_I; 
 
 
	LTC2440_nCS_L; 
 
 
 
} 
 
#endif