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

code for MCP3202 with 18f4550 !!!!

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
slyfox



Joined: 20 Sep 2007
Posts: 11
Location: GRENOBLE FRANCE

View user's profile Send private message

code for MCP3202 with 18f4550 !!!!
PostPosted: Sun Feb 07, 2010 12:17 pm     Reply with quote

now it's ok !!!
just few lines to use the MCP3202 , 12 bits analog to digital converter , with pic microcontroller :

USE spi hardware if you can !

Code:

#use spi(FORCE_HW, BITS=16,SAMPLE_RISE, BAUD=1000000)

#define CS1  PIN_C6
#define DIN  PIN_C7
#define DOUT PIN_B0
#define CLK  PIN_B1

in your main program or function :
Code:

int8 msb, lsb;
int16 value;

// for first channel reading

output_low(cs1);
spi_write(0x01); // start bit
msb=spi_read(0xC0); // first channel in single mode and read first byte
lsb=spi_read(0x00); // read second byte
output_high(CS1);
value=make16(msb,lsb); //convert to 16 bits
value=value & 0x0fff;  // forced fourth first msb bits to zero

print value to read result !!!!

// for second channel reading
Code:

output_low(cs1);
spi_write(0x01); // start bit
msb=spi_read(0x80); // second channel in single mode and read first byte
lsb=spi_read(0x00); // read second byte
output_high(CS1);
value=make16(msb,lsb); //convert to 16 bits
value=value & 0x0fff;  // forced fourth first msb bits to zero


hope it is useful !!
glk.c.93



Joined: 27 Jun 2012
Posts: 9
Location: India

View user's profile Send private message

re:
PostPosted: Mon Jul 09, 2012 2:57 am     Reply with quote

If you are transferring 16 bits at a time, then while
reading data to a 8 bit number, which 8 bits do we get ?
Do we get 16/8 bit value while we read ?
Did you check the program practically ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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