ÿþ/**serial Example for PIC18F252///////////// //by dj sniff //july 2004 //connect a variable resister to A0 and A1 //connect LED to B7 //connect serial transmit pin to pin 2 of //serial connector */////////////////////////////////////////// //include standard libraries and headers #include <18F252.h> #device ADC=10 #include <stdlib.h> //set fuses #fuses HS, NOLVP, NOWDT, PUT, NOPROTECT //20 MHZ crystal delay #use delay (clock=20000000) //set serial port inverted #use rs232(baud=9600,xmit=PIN_C5,rcv=PIN_C4, invert) //define outputs #define checkLED PIN_B7 main() { int16 potVar; int16 lightVar; byte i; // setup ADC setup_adc( ADC_CLOCK_INTERNAL ); setup_adc_ports( ALL_ANALOG ); //startup led/////////////////////// for (i = 0; i < 5; i++){ output_high(checkLED); delay_ms(100); output_low(checkLED); delay_ms(100); } /////////////////////////////////// printf("hello world\n\r"); while (true) { set_adc_channel(0); delay_ms(5); potvar=read_adc(); printf( "the pot value is %ld\n\r ", potvar); delay_ms(500); set_adc_channel(1); delay_ms(5); lightvar=read_adc(); printf( "the light Vavue is %ld\n\r ", lightvar); delay_ms(500); } }