#ifndef _SPI-ADC_H_
#define _SPI-ADC_H_

/*
 * 	(C)opyright SOOO "Gomelsky Priborostroitelny Zavod"
 *	www.gomel-pribor.com
 */

//#define ADC_CS	RA5
//#define ADC_DRDY	RA3
//#define ADC_CS_TRIS	TRISA5
//#define ADC_DRDY_TRIS	TRISA3

#define OUTPUT_PIN      0x0	
#define INPUT_PIN       0x1	

#define ADC_REG_COMM			0b00000000
#define ADC_CHANAL0			0b00000000
#define ADC_CHANAL1			0b00000001
#define ADC_REG_READ			0b00001000
#define ADC_REG_WRITE			0b00000000
#define ADC_STBY			0b00000100
#define ADC_COMM_DRTY			0b10000000
#define ADC_NORMAL			0b0

#define ADC_REG_SETUP			0b00010000
#define ADC_SETUP_NORMAL		0b00000000
#define ADC_SETUP_SELF_CALIBRATION	0b01000000
#define ADC_SETUP_ZERO_SCALE		0b10000000
#define ADC_SETUP_FULL_SCALE		0b11000000
#define ADC_SETUP_GAIN1			0b00000000
#define ADC_SETUP_GAIN2			0b00001000
#define ADC_SETUP_GAIN4			0b00010000
#define ADC_SETUP_GAIN8			0b00011000
#define ADC_SETUP_GAIN16		0b00100000
#define ADC_SETUP_GAIN32		0b00101000
#define ADC_SETUP_GAIN64		0b00110000
#define ADC_SETUP_GAIN128		0b00111000
#define ADC_SETUP_BIPOLAR		0b00000000
#define ADC_SETUP_UNIPOLAR		0b00000100
#define ADC_SETUP_BUF			0b00000010
#define ADC_SETUP_FSYNC			0b00000001

#define ADC_REG_CLOCK			0b00100000
#define ADC_CLOCK_ZERO			0b00000000
#define ADC_CLOCK_CLKDIS		0b00010000
#define ADC_CLOCK_CLKDIV		0b00001000
#define ADC_CLOCK_CLK			0b00000100


#define ADC_REG_DATA			0b00110000
#define ADC_REG_TEST			0b01000000
#define ADC_REG_OFFSET			0b01100000
#define ADC_REG_GAIN			0b01110000

extern void spi_init();
extern unsigned int spi_readADC(char ch);
extern void spi_writetoregADC(char bData);
extern char spi_readbyteADC();
extern void spi_initADC(char ch);
extern char spi_DRDY(char ch);

#endif

