sshahryiar
Joined: 05 May 2010 Posts: 94 Location: Dhaka, Bangladesh
|
TLC548 8-bit SPI ADC Driver |
Posted: Tue Apr 09, 2013 4:22 am |
|
|
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 |
|