//----------------------------------------------------- // file: sapin3.c // author: Emicros // update: 8/8/00 //----------------------------------------------------- // Description: This file contains the C source code // for a PIC12C672 to read 2 a/d inputs // and 1 digital input and send the // data at 9600 baud to a terminal (PC). // // Compiler: CCS PCM C Compiler // Compiling: pcm -c sapin3.c //----------------------------------------------------- #include <12c672.h> #use delay(clock=4000000) #use rs232(baud=9600,xmit=PIN_A0,INVERT) //-------------------------------------- // Period of time between updates //-------------------------------------- #define REPEAT_TIME 100 unsigned int rad1, rad2; //----------------------------------------------- // function: main() //----------------------------------------------- void main( void ) { while( 1 ) { set_tris_a( 0x1f ); delay_ms( REPEAT_TIME ); setup_adc( ADC_CLOCK_DIV_8 ); setup_adc_ports( ALL_ANALOG ); set_adc_channel( 1 ); delay_us( 10 ); rad1 = read_adc(); set_adc_channel( 2 ); delay_us( 10 ); rad2 = read_adc(); setup_adc_ports( NO_ANALOGS ); printf( "ad1=%u,", rad1 ); printf( "ad2=%u,", rad2 ); if( input( PIN_A3 ) ) printf( "1" ); else printf( "0" ); printf( "\n\r" ); } }