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 CCS Technical Support

MCP3201 12-bit SPI ADC Driver

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



Joined: 05 May 2010
Posts: 94
Location: Dhaka, Bangladesh

View user's profile Send private message Send e-mail Visit poster's website

MCP3201 12-bit SPI ADC Driver
PostPosted: Mon Apr 08, 2013 11:15 pm     Reply with quote

Code:

#include <16F87.h>

#device *= 16
                 
#fuses NOWDT, INTRC, PROTECT, CPD, PUT, NOWRT
#fuses NOMCLR, BROWNOUT,  FCMEN, NOIESO, NOLVP
             
#use delay (clock = 4MHz)                             
#use SPI(MASTER, DI = PIN_A1, CLK = PIN_A2, BITS = 16, MODE = 0)
                           
#define CS        pin_A0                           
                                       
#include <lcd420.c>             
           
void setup();         
                                                                                   
                                     
void main()             
{                                   
    register float v = 0.0; 
    register unsigned long adc_value = 0;
    setup();           
    while(TRUE)         
    {                                                       
        output_low(CS);               
        adc_value = spi_xfer(0);
        output_high(CS);           
        adc_value &= 0x1FFE;
        adc_value >>= 1;
        v = (adc_value * 5.0);       
        v /= 4095.0;                                                       
        lcd_gotoxy(1,1);
        printf(lcd_putc, "V: %1.3f Volt ", v);       
        lcd_gotoxy(1,2);           
        printf(lcd_putc, "ADC: %4lu ", adc_value); 
        delay_ms(100);                       
    };
}                                       

                                                 
void setup()                           
{
    setup_oscillator(OSC_4MHZ);
    disable_interrupts(global);
    setup_WDT(WDT_off);
    setup_comparator(NC_NC_NC_NC);
    setup_CCP1(CCP_off);
    setup_SPI(SPI_disabled);           
    setup_timer_0(0 | 0 | 0);
    setup_timer_1(T1_disabled);
    setup_timer_2(T2_disabled, 255, 1);
    set_timer0(0);           
    set_timer1(0);                   
    set_timer2(0);
    output_high(CS);
    lcd_init();   
    lcd_putc("\f");
    delay_ms(100);   
}       

_________________
https://www.facebook.com/MicroArena

SShahryiar
ihsanbu



Joined: 14 Oct 2006
Posts: 27
Location: islamabad,pakistan

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

Can we use this driver for MCP3909
PostPosted: Fri Nov 08, 2013 5:03 am     Reply with quote

Can we use this driver for MCP3909
_________________
ihsan ullah khan
Embedded Designer Since 2003
sshahryiar



Joined: 05 May 2010
Posts: 94
Location: Dhaka, Bangladesh

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Nov 08, 2013 9:07 am     Reply with quote

May be not because both chips are not same....
_________________
https://www.facebook.com/MicroArena

SShahryiar
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