slyfox
Joined: 20 Sep 2007 Posts: 11 Location: GRENOBLE FRANCE
|
code for MCP3202 with 18f4550 !!!! |
Posted: Sun Feb 07, 2010 12:17 pm |
|
|
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 !! |
|