' .................................................... ' Program : ADC_DIGITAL ' Function : Test toggle of A/D - Digital modes ' Author : Bill Findlay ' Date : Apr. 24, 2000 ' Copyright : Who cares. Use as you wish ' Processor : Pic 16F877 ' Compiler : PicBasic Pro V2.3 ' Ports used ' PortA.0 - Analog/Digital input ' PortB - LCD display, see code for pinout ' PortC.6 - Button inputs ' ICD : EPE Icebreaker ' Remarks: ' PortA.0 - Limited to input only for test. ' Mode switche uses ADCON1 register, ' see code for values used. ' ADCON1 defines PortA configuration, ' See 16F877 data sheet for more information. ' Icebreaker reserves PortB 2*MSB for comms. '........................................................... Pause 1000 ' Wait for LCD to initialise ' PBP definitions DEFINE OSC 20 ' Oscillator = 20MHz DEFINE LCD_DREG PORTB ' LCD o/p on port B DEFINE LCD_DBIT 0 ' LCD on lower 4 bits of port B DEFINE LCD_RSREG PORTB ' LCD reset on port B DEFINE LCD_RSBIT 4 ' LCD reset portB.4 DEFINE LCD_EREG PORTB ' LCD enable on port B DEFINE LCD_EBIT 5 ' LCD enable pin 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 ' Internal clock 'Initialise port settings TRISA = 255 ' Port A as analog input TRISB = 0 ' Set port B as output TRISC = 255 ' Port C as input ' Program variables Port VAR porta.0 ' digital - PortA.0 ADC VAR WORD ' Analog - PortA.0 PMode VAR Byte ' Mode selected LCDOut $FE,1 ' Clear LCD LCDOut "Starting " ' Print start message LCDOut $FE, $C0 ' new line LCDOut "Test" Pause 1000 ' Wait 1 sec LCDOut $FE,1 ' Clear LCD ' start with port A in analog mode GOTO ADCINIT PortValues: LCDout $fe,1 ' Clear LCD if pmode = 0 then LCDout "A : " ' Analog mode input if pmode = 1 then LCDout "D : " ' Digital mode input ADCIN Port, ADC ' get ADC port value LCDOUT "ADC : ",DEC ADC ' Lets see analog result LCDOUT $FE,$C0," " ' New line LCDOUT "Dig : ",DEC Port ' Lets see Digital result return ADCINIT: pmode = 0 trisA.0 = 1 ' PortA.0 to i/p ADCON1 = %10000000 ' Port A is analog ADCON0 = %10000000 ' Fosc/32 ANALOG: Pause 1000 ' delay 1 sec if portc.6 = 0 then diginit ' Switch i/p mode to digital gosub PortValues ' Print values goto analog DIGINIT: pmode = 1 ' digital adcon1 = %10000110 ' Port A is all digital digital: Pause 1000 ' delay 1 sec if portc.6 = 0 then adcinit ' Switch i/p mode to analog gosub PortValues ' Print values goto digital END