|
ME Labs, Inc. 719-520-5323 |
|
|
|
ME Labs, Inc. | 1-719-520-5323 | Example Program - adcx.pbpPICBASIC PRO program to read pots on 16F887 ADC' Name : adcx.pbp
' Compiler : PICBASIC PRO Compiler 2.60
' Assembler : PM or MPASM
' Target PIC : 40-pin 16F887
' Hardware : Lab-X1
' Oscillator : 4MHz external crystal
' Keywords : ADC, ANALOG, LCDOUT, LCD
' Description : PICBASIC PRO program to read pots on 16F887 ADC
' Define LCD pins
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
' Define ADCIN parameters ********************************
ADCON1 = %00000000 ' Left-Justify result in ADRESH:ADRESL registers
ANSEL = %00001011 ' Set AN0, AN1, AN3 to analog, others digital
ANSELH = %00000000 ' Set AN8 and higher channels to digital operation
'**********************************************************
' Allocate variables
x Var Byte
y Var Byte
z Var Byte
Low PORTE.2 ' LCD R/W line low (W)
Pause 100 ' Wait for LCD to start
Goto mainloop ' Skip subroutines
' Subroutine to read a/d convertor
getad:
Pauseus 100 ' Wait for channel to setup
ADCON0.1 = 1 ' Start conversion
Pauseus 100 ' Wait for conversion
Return
' Subroutine to get pot x value
getx:
ADCON0 = $41 ' Set A/D to Fosc/8, Channel 0, On
Gosub getad
x = ADRESH
Return
' Subroutine to get pot y value
gety:
ADCON0 = $45 ' Set A/D to Fosc/8, Channel 1, On
Gosub getad
y = ADRESH
Return
' Subroutine to get pot z value
getz:
ADCON0 = $4D ' Set A/D to Fosc/8, Channel 3, On
Gosub getad
z = ADRESH
Return
mainloop:
Gosub getx ' Get x value
Gosub gety ' Get y value
Gosub getz ' Get z value
Lcdout $fe, 1, "x=", #x, " y=", #y, " z=", #z ' Send values to LCD
Pause 100 ' Do it about 10 times a second
Goto mainloop ' Do it forever
End
Download the program file. |
|
Copyright 2022 ME Labs, Inc. PO Box 8250 Asheville NC 28814 (719) 520-5323 (719) 520-1867 fax email: support@melabs.com |
|