Calamar
Joined: 07 Sep 2003 Posts: 60 Location: Buenos Aires (Argentina)
|
|
Posted: Sat Jul 23, 2005 5:43 pm |
|
|
#include <dac12.C>
init_dac_12(1,1,1) ; // BUF,GAN,SHDN (MCP4921/22)
-------------------------------------------------------
//init_dat.c
//DAC 12 BIT MCP4921_4922
LONG INT DATO ;
INT CONT ; //
int16 CMD ; //
#define DAC_CS PIN_A0
#define DAC_DIN PIN_A3
#define DAC_CLK PIN_A2
//#define DAC_DOUT PIN_D3
#define DAC_PCLATH PIN_A1
void init_dac_12(buf,ga,shdn) {
CMD = 0X0000;
IF(BUF){bit_set(CMD,14);}
ELSE {bit_clear(CMD,14);}
IF(GA){bit_set(CMD,13);}
ELSE {bit_clear(CMD,13);}
IF(SHDN){bit_set(CMD,12);}
ELSE {bit_clear(CMD,12);}
}
void wr_dac_12(INT16 DATO) {
DATO |= CMD ;
OUTPUT_LOW(DAC_CS) ;
FOR (CONT = 1 ;CONT <=16 ;++CONT ) {
OUTPUT_BIT( DAC_DIN,SHIFT_LEFT(&DATO,2,0)) ;
OUTPUT_LOW(DAC_CLK) ;
delay_cycles (1) ;
OUTPUT_HIGH(DAC_CLK) ;}
delay_CYCLES(1) ;
OUTPUT_HIGH(DAC_CS) ;
delay_CYCLES(1) ;
OUTPUT_LOW(DAC_PCLATH) ;
delay_CYCLES(1) ;
OUTPUT_HIGH(DAC_PCLATH) ;
delay_CYCLES(1) ;
OUTPUT_LOW(DAC_CLK) ;
} _________________ Best Regards
Daniel H. Sagarra
La Plata (Argentina) |
|