I知 having a problem with getting the correct remainder using // remainder.
I have a 10K res connected to the power rail using the centre pot connected to AN2 of a 16F690.
With the pot at VDD I get a reading of 1023 which I divide by 213 to get the 4.79 voltage rail.
I have a volt meter connected to the wiper of the pot to compare the displayed LCD results.
The remainder does not display correctly.
What am I doing wrong?
'***************************************************** ***********
ANSEL = %00000100
ANSELH = %00000000
TRISA = %11111110 'All digital except PortA 0
TRISB = %00000000
TRISC = %00000000
DEFINE OSC 4
' Define LCD registers and bits
DEFINE LCD_DREG PORTC
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 5
DEFINE LCD_RWREG PORTB
DEFINE LCD_RWBIT 4
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 6
DEFINE LCD_BITS 8
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
'################################################# ######################
' Set up AD
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 2 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50
ANSEL = %00000100 'enable AN2, ALL THE REST DIGITAL
ANSELH = %00000000 'AN8-11 DIGITAL
adcVal var word '
adcVal1 var word
adcVal2 var word
adcVal3 var word
ADCON0 = %10001000 ' ADC Control 1
' 7=1 -1 = Right just, 0 = Left just
' 6=0 -1 = Vref pin, 0= Vdd
' 5=0 -Analog Channel Select Bits
' 4=0 -Analog Channel Select Bits
' 3=1 -Analog Channel Select Bits
' 2=1 -Analog Channel Select Bits
' 1=1 -1 = A/D in progress, 0 = Compleated
' 0=0 -1 = ADC enable, 0 = Disable
ADCON1 = %00000000 ' 7=0 -Unimplimented read as 0
' 6=0 -A/D clock conversion bots
' 5=0 -A/D clock conversion bots
' 4=0 -A/D clock conversion bots
' 3=0 -Unimplimented read as 0
' 2=0 -Unimplimented read as 0
' 1=0 -Unimplimented read as 0
' 0=0 -Unimplimented read as 0
Pause 500 ' Wait .5 second LCD Stablise
start:
Display:
ADCIN 2, adcVal
pauseus 50
adcVal1 = adcVal / 213 'Voltage
adcVal2 = adcVal // 213 'Remainder
Lcdout $fe, $80, "A/D Conversion"
lcdout $fe, $C0, dec adcval,"_",dec adcVal1, ".",dec adcVal2
Pause 500 ' Wait .5 second
Goto Display ' Do it forever
Bookmarks