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

TLC548 8-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

TLC548 8-bit SPI ADC Driver
PostPosted: Tue Apr 09, 2013 4:22 am     Reply with quote

Code:
#include <16F87.h>


#device *= 16

                 
#fuses NOWDT, INTRC, PROTECT, CPD, PUT, NOWRT
#fuses NOMCLR, BROWNOUT,  FCMEN, NOIESO, NOLVP

                                     
#define CS_pin             pin_A0
#define Data_In_pin        pin_A1
#define Clock_pin          pin_A2   
                         
             
#use delay (clock = 4MHz)                             
#use SPI(MASTER, DI = Data_In_pin, CLK = Clock_pin, BITS = 8, SAMPLE_RISE)                         
                       
                                       
#include <lcd420.c>             
                               
           
void setup();         
                                                                                   
                                     
void main()             
{                                     
    register float v = 0.0; 
    unsigned char adc_value = 0;
    setup();           
    while(TRUE)                                                           
    {                                                       
        output_low(CS_pin);               
        adc_value = spi_xfer(0);
        output_high(CS_pin);
        v = (adc_value * 5.0);   
        v /= 255.0;     
        lcd_gotoxy(1,1);
        printf(lcd_putc, "V: %1.2f Volt ", v);       
        lcd_gotoxy(1,2);           
        printf(lcd_putc, "ADC: %3u ", adc_value); 
        delay_ms(200);                       
    };
}                                       

                                                 
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_pin);
    lcd_init();   
    lcd_putc("\f");
    delay_ms(100);   
}

_________________
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