' ADCIN USING 16F877 Pause 1000 ' Wait for LCD to initialise TRISB = %00000000 ' Set port B as output DEFINE OSC 20 ' Oscillator = 20MHz DEFINE LCD_DREG PORTB ' LCD o/p on port B DEFINE LCD_DBIT 4 ' LCD on lower 4 bits of port B DEFINE LCD_RSREG PORTB ' LCD reset on port B DEFINE LCD_RSBIT 1 ' LCD reset portB.4 DEFINE LCD_EREG PORTB ' LCD enable on port B DEFINE LCD_EBIT 3 ' LCD output on PortB.5 DEFINE LCD_BITS 4 ' LCD o/p is 4 bit data DEFINE LCD_LINES 2 ' Number of lines on LCD = 2 DEFINE ADC_BITS 10 ' 10 bit adc conversion DEFINE ADC_SAMPLEUS 50 ' Sampling time in microseconds DEFINE ADC_CLOCK 2 B VAR BYTE ADC VAR WORD LOW PORTB.2 LCDOut $FE,1 ' Clear LCD LCDOut "Starting ADC" ' Print start message LCDOut $FE, $C0 ' new line LCDOut "Conversion" Pause 1000 ' Wait 1 sec LCDOut $FE,1 ' Clear LCD SETUP: TRISA = 255 ' Port A to all inputs ADCON1 = %10000010 ' Port A is analog ADCON0 = %10000001 START: For B = 0 TO 4 ' loop count and channel select ADCIN B, ADC ' get ADC port value the easy way LCDout $fe,1 ' Clear LCD LCDOUT "PORTA ", DEC B, " ", DEC ADC ' print port and decimal value Pause 1000 ' wait 1 sec Next B ' get next port value GoTo SETUP ' Do forever