'****************************************************************
'* Name : 16f872 multi ADC.BAS *
'* Author : Platform = PicBasicPro Program written by BigAl *
'* Notice : With help from many, too numerous to list *
'* : No Rights Reserved *
'* Date : 18/06/2012 *
'* Version : 3.0 *
'* Notes : Program to display both negative and positive of *
'* : PSU 15-0-15 *
'****************************************************************
DEFINE OSC 8
' Define LCD pins
Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTB
Define LCD_RSBIT 2
Define LCD_EREG PORTB
Define LCD_EBIT 3
' Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
TRISA = %00000111
' variables
posval var WORD
negval var WORD
static var WORD
adval Var Word ' Create adval to store result
ADCON1 = %10000010 ' Set PortA to A/D inputs
Pause 100 ' Wait for LCD to start
Goto mainloop ' Skip subroutines
' Subroutine to read a/d converter
getad:
PAUSEUS 50 ' Wait for A/D channel acquisition time
ADCON0.2 = 1 ' Start conversion
WHILE ADCON0.2 ' Wait for it to complete
adval.highbyte = ADRESH 'Write conversion result
adval.lowbyte = ADRESL
adval = (adval */ 500)>>2 ' Equates to: (adval * 500)/1024
WEND
Return
' Subroutine to get pot x value
getposval:
ADCON0 = $49 ' Set A/D to Fosc/8, Channel 0, On
Gosub getad
posval = (adval * 41)
Return
' Subroutine to get pot negval value
getnegval:
ADCON0 = $41 ' Set A/D to Fosc/8, Channel 1, On
Gosub getad
negval = (adval * 46)
Return
' Subroutine to get static value : not implemented yet
getstatic:
ADCON0 = $51 ' Set A/D to Fosc/8, Channel 2, On
Gosub getad
static = adval
Return
mainloop:
Gosub getposval ' Get + value
Gosub getnegval ' Get - value
'Gosub getstatic ' Get 5v value
LCDOut $fe,1,"POS Volts= ",DEC (posval/1000),".", DEC3 posval ' Display the decimal value
LCDOut $fe,$c0,"NEG Volts= ",DEC (negval/1000),".", DEC3 negval ' Display the decimal value
Pause 200 ' Do it about 5 times a second
Goto mainloop ' Do it forever
End