
LTC2414/LTC2418
43
241418fa
// LTC2418 PIC16F84 Interface Example
// Written for CC5X Compiler
// Processor is PIC16F84 running at 10 MHz
#include <16f84.h>
#include <int16cxx.h>
#pragma origin = 0x4
#pragma config |= 0x3fff, WDTE=off,FOSC=HS
// global pin definitions:
#pragma bit rx_pin
@ PORTB.0
//input
#pragma bit tx_pin
@ PORTB.1
//output
#pragma bit sck
@ PORTB.2
//output
#pragma bit sdi
@ PORTB.3
//output
#pragma bit sdo
@ PORTB.4
//input
#pragma bit cs_bar
@ PORTB.5
//output
// Global Variables
uns8 result_3;
// Conversion result MS byte
uns8 result_2;
// ..
uns8 result_1;
// ..
uns8 result_0;
// Conversion result LS byte
void shiftbidir(char nextch);
// function prototype
void main( void)
{
INTCON=0b00000000;
// no interrupts
TRISA=0b00000000;
// all PORTA pins outputs
TRISB=0b00010001;
// according to definitions above
char channel;
// next channel to send
while(1)
{
/* channel bit fields are 7:6, 10 always; 5, EN; 4, SGL; 3, ODD/SIGN; 2:0, ADDR */
channel = 0b10101000;
// CH0,1 DIFF.
cs_bar=0;
// activate ADC
while(sdo==1)
// test for end of conversion
{
// wait if conversion is not complete
}
shiftbidir(channel);
// read ADC, send next channel
cs_bar = 1;
// deactivate ADC
/* At this point global variables result 3,2,1 contain the 24 bit conversion result. Variable result3
contains the corresponding channel information in the following fields:
bits 7:6, 00 always, 5, EN; 4, SGL; 3, ODD/SIGN; 2:0, ADDR */
}
// end of loop
}
// end of main
Figure 50. Sample Program in CC5X for PIC16F84
APPLICATIO S I FOR ATIO
WU
UU