Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
what is a comperater module that has analog input. (sorry for my dumb question)
'for Sim only
Define SIMULATION_WAITMS_VALUE = 1
Dim temp1 As Word
Dim vref1 As Word
Dim vrhi As Word
Dim vrlo As Word
'LCD assignments
Define LCD_LINES = 4
Define LCD_CHARS = 16
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 1
Define LCD_EREG = PORTB
Define LCD_EBIT = 2
'make AN0,,1,2,3 as Inputs
TRISA = %00001111
TRISB = %00000000 'outputs
'comparator settings
CMCON.C2OUT = 0
CMCON.C1OUT = 0
CMCON.C2INV = 1
CMCON.C1INV = 1
CMCON.CIS = 0 'comparator selection PA.0/1 to PA.3/2
CMCON.CM2 = 0 'mode set for internal Vref connected
CMCON.CM1 = 1
CMCON.CM0 = 0
'Vref settings
VRCON.VREN = 1
VRCON.VROE = 0
VRCON.VRR = 0 'select Vref low=1 or Vref high =0
VRCON.VR3 = 1 'Vref 2^3 bit
VRCON.VR2 = 1
VRCON.VR1 = 1
VRCON.VR0 = 1 'Vref 2^0 bit
Lcdinit
'this section converts the binary to decimal value of the Vref settings
'as selected by Vr3,2,1,0 , decimal 0 thru 15
If VRCON.VR3 = 1 Then
temp1 = 8
Endif
If VRCON.VR2 = 1 Then
temp1 = temp1 + 4
Endif
If VRCON.VR1 = 1 Then
temp1 = temp1 + 2
Endif
If VRCON.VR0 = 1 Then
temp1 = temp1 + 1
Endif
'* 1000 to allow for lack of decimal fractions
temp1 = temp1 * 1000
'test if in Low or High range of Vref options
If VRCON.VRR = 1 Then 'low range
temp1 = (temp1 / 24) * 5
vrhi = temp1 / 1000
vrlo = (temp1 - (vrhi * 1000)) / 10
Else 'high range
temp1 = 1250 + ((temp1 / 32) * 5)
vrhi = temp1 / 1000
vrlo = (temp1 - (vrhi * 1000)) / 10
Endif
'show on LCD line 1
Lcdout "Vref= ", #vrhi, "." #vrlo
'above Vref value displayed once only
main:
CMCON.CIS = 0
Lcdcmdout LcdLine3Home
'test for IF PORTA.0 is > or < than Vref, display result
If CMCON.6 = 1 Then
Lcdout "A.0>Vr"
Else
Lcdout "A.0<Vr"
Endif
Lcdcmdout LcdLine3Pos(10)
'test for IF PORTA.1 is > or < than Vref
If CMCON.7 = 1 Then
Lcdout "A.1>Vr"
Else
Lcdout "A.1<Vr"
Endif
'switch from PA.0 and PA.1 to PA.3 and PA.2 analog inputs
CMCON.CIS = 1
'repeat the Vref for PA.3 and PA.2 , display result
Lcdcmdout LcdLine4Home
If CMCON.7 = 1 Then
Lcdout "A.2>Vr"
Else
Lcdout "A.2<Vr"
Endif
Lcdcmdout LcdLine4Pos(10)
If CMCON.6 = 1 Then
Lcdout "A.3>Vr"
Else
Lcdout "A.3<Vr"
Endif
Goto main
Thank you very much, I got it. It's a analog Comperator instead of ADC