CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

MCP4921 DAC / MCP3204 ADC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








MCP4921 DAC / MCP3204 ADC
PostPosted: Sat Jul 23, 2005 10:13 am     Reply with quote

Any chance anyone has some sample code for the MCP4921 DAC and MCP3204 ADC.
Init routines and read/wite.

Thanks....
Calamar



Joined: 07 Sep 2003
Posts: 60
Location: Buenos Aires (Argentina)

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Sat Jul 23, 2005 5:43 pm     Reply with quote

#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)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group