Hello, I'm trying to get this sensor working with PIC16F1519. It is connected to PORTD.1 and MAX7219 display to PORTC. Nothing else. I'm using 4.7k resistor to deliver voltage to it. But it does not works. If I use 4.7k or 5.6k resistor, it will return 127, if I use 2.2k or 10k resistors, it will return 85. I've tried replacing chip, playing with ANSELD and TRISD registers - no luck. I'm using "classic" code from melabs example. What I'm doing wrong?

Code:
;----[16F1519 Hardware Configuration]-------------------------------------------
#IF __PROCESSOR__ = "16F1519"
  #DEFINE MCU_FOUND 1
#CONFIG
cfg1 = _FOSC_INTOSC           ; INTOSC oscillator: I/O function on CLKIN pin
cfg1&= _WDTE_OFF              ; WDT disabled
cfg1&= _PWRTE_OFF             ; PWRT disabled
cfg1&= _MCLRE_OFF             ; MCLR/VPP pin function is MCLR
cfg1&= _CP_OFF                ; Program memory code protection is disabled
cfg1&= _BOREN_OFF             ; Brown-out Reset disabled
cfg1&= _CLKOUTEN_OFF          ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
cfg1&= _IESO_OFF              ; Internal/External Switchover mode is disabled
cfg1&= _FCMEN_OFF             ; Fail-Safe Clock Monitor is disabled
  __CONFIG _CONFIG1, cfg1
cfg2 = _WRT_OFF               ; Write protection off
cfg2&= _VCAPEN_OFF            ; VCAP pin function disabled
cfg2&= _STVREN_ON             ; Stack Overflow or Underflow will cause a Reset
cfg2&= _BORV_LO               ; Brown-out Reset Voltage (Vbor), low trip point selected.
cfg2&= _LPBOR_OFF             ; Low-Power BOR is disabled
cfg2&= _LVP_OFF               ; High-voltage on MCLR/VPP must be used for programming
  __CONFIG _CONFIG2, cfg2
#ENDCONFIG
#ENDIF
;----[Verify Configs have been specified for Selected Processor]----------------
;       Note: Only include this routine once, after all #CONFIG blocks
#IFNDEF MCU_FOUND
  #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
#ENDIF

'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : [select VIEW...EDITOR OPTIONS]                    *
'*  Notice  : Copyright (c) 2018 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 11.12.2018                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
'SERVOCONTROLLER SYSTEM
                        
'init
include "modedefs.bas"
OSCCON = %01111010  'SET INTOSC TO 16MHZ
ANSELC=%00000000
ANSELD=%00000000
TRISC=%00000000 'set PORTC as output all
TRISD=%11111111 'set PORTD as output all
DEFINE OSC 16
dqd var PORTD.1
tvla var word
temperature var word
'DEFINES:
 Clk     Var PORTC.6  ' Data is clocked on rising edge of this pin            mcvane
 Dta   Var PORTC.5  ' Bits are shifted out of this pin          KVITELI
 Load    Var PORTC.4  ' Transfers data to LEDs when Pulsed   lurji
 
 
 'MAX7219 STUFF
    ' ** Declare Constants **
 Decode_Reg  Con 9 ' Decode register, a 1 turns on BCD decoding for each digit. 
 Lum_Reg  Con 10 ' Intensity register.
 Scan_Reg Con 11 ' Scan-limit register.
 Switch_Reg Con 12 ' On/Off Register.
 Test_Reg Con 15 ' Test mode register (all digits on, 100% bright)
 Max_Digit Con 4 ' Amount of LED Displays being used.
' ** Declare Variables **
   Counter  Var Word ' Variable used for the Demo Counting routine
 Max_Disp Var Word ' 16-bit value to be displayed by the MAX7219
 Max_Dp  Var Byte ' Digit number to place Decimal point (0-4)
 Register Var Byte ' Pointer to the Internal Registers of the MAX7219
 R_Val  Var Byte ' Data placed in Each Register
 Digit  Var Byte ' Position of individual numbers within MAX_Disp (0-3)
 Position Var Byte ' Position of each LED display (1-4)
 
 ' Turn Off test mode
 Register=Scan_Reg  ' Point to the Scan Register
 R_Val=7    ' send 3, (Four LED Displays 0-3)
 Gosub Transfer   ' Transfer this 16-bit Word to the MAX7219
 Register=Lum_Reg  ' Point to the Luminance Register
 R_Val=1    ' Send 5, (Value for Brightness)
 Gosub Transfer   ' Transfer this 16-bit Word to the MAX7219
 Register=Decode_Reg  ' Point to BCD Decode Register
 R_Val=%00001111 ' Decode the first 8 digits
 Gosub Transfer   ' Transfer this 16-bit Word to the MAX7219
 Register=Switch_Reg  ' Point to the Switch Register 
 R_Val=1    ' Set to One, (switches the display ON)
 Gosub Transfer   ' Transfer this 16-bit Word to the MAX7219
 Register=Test_Reg  ' Point to the Test Register
 R_Val=0    ' Reset to Zero, (turns off Test mode)
 Gosub Transfer   ' Transfer this 16-bit Word to the MAX7219

 Max_Dp=0   ' Display number for Decimal Point
REGISTER=8      'display some name
R_VAL=124
GOSUB TRANSFER
REGISTER=7
R_VAL=110
GOSUB TRANSFER 
REGISTER=6
R_VAL=120
GOSUB TRANSFER 
REGISTER=5
R_VAL=57
GOSUB TRANSFER 

TTK:
pause 500 
gosub gradus1
max_disp=temperature
GOSUB DISPLAY
GOTO TTK



GRADUS1:
        OWOUT DQD, 1, [$CC, $44] ' Start temperature conversion
        pause 750
        OWOUT DQD, 1, [$CC, $BE]         ' Read the temperature
        OWIN DQD, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
        temperature = temperature */ 1600
        TEMPERATURE=TEMPERATURE/100

  
return
 
Display:
 Digit=0      ' Start at Digit 0 of Max_Disp Variable
 For Position=4 to 1 step -1   ' Start at Farthest Right of Display   
 Register=5-Position    ' Place Position into Register
 R_Val=Max_Disp Dig Digit   ' Extract the individual numbers from Max_Disp   
 If Max_Disp<10 and Position=3 then R_Val=15 ' Zero Suppression for the second digit
 If Max_Disp<100 and Position=2 then R_Val=15 ' Zero Suppression for the Third digit
 If Max_Disp<1000 and Position=1 then R_Val=15 ' Zero Suppression for the Forth digit
 If Max_Disp<10000 and Position=0 then R_Val=15 ' Zero Suppression for the Fifth digit
 If Digit=Max_Dp then R_Val.7=1   ' Place the decimal point, held in Max_DP
 Gosub Transfer     ' Transfer the 16-bit Word to the MAX7219
 If Digit>=3 then Digit=0   ' We only need the first four digits
 Digit=Digit+1     ' Point to next Digit within Max_Disp
 Next Position     ' Close the Loop
 Return
' Send a 16-bit word to the MAX7219 
Transfer:
   Shiftout Dta,Clk,msbfirst,[Register,R_Val] ' Shift Out the Register first, then the data
 High Load    ' The data is now acted upon
 PAUSEUS 100
@ Nop
@ Nop     ' A small delay to ensure correct clocking times
 Low Load    ' Disable the MAX7219 
 Return     ' Exit from Subroutine