Hello Everyone,

I've been trying to get my DS1820 to work on my 16f688 and can't figure out why it won't display the proper temperature but the exact same code on my 16f877 works good. This code will only display 31 degrees F. Would anyone have any suggestions as to why it's not functioning properly? It's a real stumper for me and any help would be much appreciated.

Thanks
jessey

Code:
'*********************************************************************************
'* Name    : Test Program for DS1820 & 4 x 20 LCD                                *
'* Author  : Jessey Montgomery                                                   *
'* Includes: Darrel Taylor's EE_Vars.PBP                                         *  
'* Date    : April 20/th 2009                                                    *
'* Version : Using PicBasic Pro Ver 2.50, MPASM Ver 5.20, Using MicroCode Studio *
'*         : 3.0.0.5, PICkit 2 programmer - Application Version 2.50.02 - Device *
'*         : File Version 1.5100 - OS Firmware Version 2.30.01. Using a 16F688.  *
'*********************************************************************************


'(1) Comments & Objectives
'   =====================
' this program is just a test program for checking out the new 4 x 20 lcd and
' also displaying temperature using a DS1820. This program communicates with a
' 16f877 to turn On/Off X10 appliance modules using a fireCracker.

'                               --------------
'                               |   16f688   |
'                   VDD+ (--->) |1         14| (<---) VSS-
'                               |            |
'   RA5/TICKI/OSC1/CLKIN (<-->) |2         13| (<-->) RA0/AN0/C1IN+/ICSPDAT/ULPWU 
'                               |            |
'RA4/AN3/TIG/OSC2/CLKOUT (<-->) |3         12| (<-->) RA1/AN1/C1IN-/Vref/ICSPCLK 
'                               |            |
'            RA3/MCLR/Vpp(--->) |4         11| (<-->) RA2/AN2/TOCKI/INT/C1OUT
'                               |            |
'              RC5/RX/DX (<-->) |5         10| (<-->) RC0/AN4/C2IN+
'                               |            |
'        RC4/C2OUT/TX/CX (<-->) |6          9| (<-->) RC1/AN5/C2IN-
'                               |            |
'                RC3/AN7 (<-->) |7          8| (<-->) RC2/AN6
'                               |            |
'                               --------------


'              Clear Each Port Before Setting The TRIS Registers
'              =================================================

                                
 Clear   ' Set all ram registers to zero
 PORTA = 0
 PORTC = 0                           

'                            VSS VDD MCLR Ect. Pins
'                            ====================== 
 
'VDD +       '(pin 1)
'VSS -       '(pin 14)
                       
 '                    SET THE TRIS
 '                    ============

 '                     PORTA PINS 
 '                     ==========
 TRISA.0 = 0 '(pin 13) ............................Out_To_877_Pin_37 VAR PORTA.0   
 TRISA.1 = 0 '(pin 12) ............................Out_To_877_Pin_38 VAR PORTA.1     
 TRISA.2 = 0 '(pin 11) ............................Out_To_877_Pin_39 VAR PORTA.2
 TRISA.3 = 1 '(pin 4)  .......................................... DQ VAR PORTA.3       
 TRISA.4 = 0 '(pin 3)  ..........................................Led VAR PORTA.4         
 TRISA.5 = 1 '(pin 2)  .................................... Button_5 VAR PORTA.5      
                                                      
 '                     PORTC PINS
 '                     ==========
 TRISC.0 = 0 '(pin 10) Blue........... Lcd Data bit 4   
 TRISC.1 = 0 '(pin 9)  White.......... Lcd Data bit 5 
 TRISC.2 = 0 '(pin 8)  Green.......... Lcd Data bit 6              
 TRISC.3 = 0 '(pin 7)  Orange......... Lcd Data bit 7  
 TRISC.4 = 0 '(pin 6)  Orange/Black... Lcd Register select     
 TRISC.5 = 0 '(pin 5)  Blue/White..... Lcd Enable bit  


'(2) PIC Config Fuse Definitions for 16f688
'   ====================================== 
 @ __CONFIG _INTOSCIO & _WDT_ON & _MCLRE_OFF & _CP_OFF  
 @ ERRORLEVEL -306; ' turns off cross page boundary message alerts

'(3) PIC Hardware Definitions (ie Pin-Out & Port Assignments)
'   ========================================================
 ANSEL = 0
 CMCON0 = 7         ' turn off comparators 

 DEFINE LCD_RSREG PORTC' LCD Register Select Port  
 DEFINE LCD_RSBIT 4    ' LCD Register Select 
 DEFINE LCD_EREG PORTC ' LCD Enable Port  
 DEFINE LCD_EBIT 5     ' LCD Enable      
 DEFINE LCD_DREG PORTC ' LCD Data Port 
 DEFINE LCD_DBIT 0     ' LCD data starting bit 0 or 4

 Out_To_877_Pin_37 VAR PORTA.0 ' pin 13
 Out_To_877_Pin_38 VAR PORTA.1 ' pin 12
 Out_To_877_Pin_39 VAR PORTA.2 ' pin 11
 Button_5 VAR PORTA.5          ' pin 2 
 Led VAR PORTA.4               ' pin 3

 a VAR BIT ' a always equals zero, used in IF-THEN's instead of using GOTO's
 a = 0 
 Timer VAR byte
 Timer = 0

 temp VAR	WORD          ' Temperature storage
 count_remain VAR BYTE    ' Count remaining
 count_per_c VAR	BYTE  ' Count per degree C
 Sign  VAR  BIT           ' bit determines id - sign is needed 
 DQ VAR PORTA.3           ' One-wire data pin (pin 4) 


 Is_Pressed CON 0
 Is_Not_Pressed CON 1
 Is_Turned_On CON 1
 Is_Turned_Off CON 0
        
  
'4a. EEPROM Assignments
'    ==================  
 INCLUDE "EE_Vars.PBP"   

'        'Declare The EE Variable' 'Load A Default Setting For The EE Variable'
                     X  VAR  BYTE : @  EE_var  _X, BYTE,0
                     Y  VAR  BYTE : @  EE_var  _Y, BYTE,0
                     Z  VAR  BYTE : @  EE_var  _Z, BYTE,0
                                                 
'         To write to the eeprom   @  EE_write_var  _X
'         ============================================  
  

' Reset all three PORT outputs to the states they were before the power-loss
' ==========================================================================

 IF X = 1 THEN 
    Out_To_877_Pin_37 = 1
 ELSE '                  PORTA.0 pin 13 
    Out_To_877_Pin_37 = 0
 ENDIF

 IF Y = 1 THEN ' pin 12
    Out_To_877_Pin_38 = 1
 ELSE '                  PORTA.1 pin 12  
    Out_To_877_Pin_38 = 0
 ENDIF

 IF Z = 1 THEN 'pin 11
    Out_To_877_Pin_39 = 1
 ELSE '                  PORTA.2 pin 11  
    Out_To_877_Pin_39 = 0
 ENDIF 
 Led = Is_Turned_Off

 LCDOUT  254,64,14,10,14,0,0,0,0,0 ' Cust Char #0 - degree sign

 PAUSE 500 ' For LCD 

IF a = 0 THEN MainLoop ' a always equals zero, use instead of GOTO...


Turn_On_Or_Off_3:
    if Y = 0 then ' Y toggles the #3 X10 module On/Off with each button press 
       Y = 1      ' Turn On #3 X10 module
    ELSE
       Y = 0      ' Turn Off #3 X10 module
    ENDIF 
    @  EE_write_var  _Y ' remember Y in case of a power failure 
    IF Y = 0 THEN Out_To_877_Pin_38 = 0 ' #3 X10 module is Off   
    if Y = 1 then Out_To_877_Pin_38 = 1 ' #3 X10 module is On  
RETURN


Turn_On_Or_Off_4:
    if X = 0 then ' X toggles the #4 X10 module On/Off with each button press 
       X = 1      ' Turn On #4 X10 module
    ELSE
       X = 0      ' Turn Off #4 X10 module
    ENDIF 
    @  EE_write_var  _X ' remember X in case of a power failure 
    IF X = 0 THEN Out_To_877_Pin_37 = 0 ' #4 X10 module is Off   
    if X = 1 then Out_To_877_Pin_37 = 1 ' #4 X10 module is On    
RETURN


Turn_On_Or_Off_5:
    if Z = 0 then ' Z toggles the #5 X10 module On/Off with each button press 
       Z = 1      ' Turn On #5 X10 module
    ELSE
       Z = 0      ' Turn Off #5 X10 module
    ENDIF 
    @  EE_write_var  _Z ' remember Z in case of a power failure 
    IF Z = 0 THEN Out_To_877_Pin_39 = 0 ' #5 X10 module is Off   
    if Z = 1 then Out_To_877_Pin_39 = 1 ' #5 X10 module is On 
RETURN 


Check_Temperature:
  OWOut DQ, 1, [$CC, $44]    ' Start Temp conversion
 waitloop:
  OWIn DQ, 4, [count_remain]	' Check for still busy converting
	IF count_remain = 0 THEN waitloop

	OWOut DQ, 1, [$CC, $BE]		  ' Read the Temp
  OWIn DQ, 0, [temp.LOWBYTE, temp.HIGHBYTE, _
                        Skip 4, count_remain, count_per_c]
    ' Calculate temp in degrees Celsius to 2 decimal places 
     Sign = temp.15
     temp = ((ABS(temp) >> 1) * 100)
     if Sign then temp = -temp
     temp = temp - 25 _
                     + (((count_per_c - count_remain) * 100) / count_per_c)

    ' Convert Celsius to Fahrenheit before returning   
     Sign = temp.15
     temp = (ABS(temp) */ 461)
     if Sign then temp = -temp
     temp = temp + 3200
RETURN


MainLoop:

 GOSUB Check_Temperature
 
 IF Button_5 = Is_Pressed THEN  
   Timer = 0
   WHILE Button_5 = Is_Pressed
     Led = Is_Turned_On  
     Timer = Timer + 1 
     IF Timer = 4 THEN Timer = 1
     lcdout $fe, 1, "Release Sw When ? #",DEC Timer
     LCDOut $fe, $c0, "If # = 1 then X10-3 "
     lcdout $fe,$94, "If # = 2 then X10-4 "  
     lcdout $fe,$d4,"If # = 3 then X10-5 " 
     PAUSE 1000
   WEND
   Led = Is_Turned_Off                
   PAUSE 100 ' Debounce Push Button   
   IF Timer = 1 THEN GOSUB Turn_On_Or_Off_3
   IF Timer = 2 THEN GOSUB Turn_On_Or_Off_4 
   IF Timer = 3 THEN GOSUB Turn_On_Or_Off_5
 ENDIF

  LCDOut $fe, 1, "X10Temp Demo Program"
  LCDOut $fe, $c0," Jessey Montgomery  "  
  lcdout $fe,$94,"#3 = ",DEC Out_To_877_Pin_38, _
                 " #4 = ",DEC Out_To_877_Pin_37," #5 = ",DEC Out_To_877_Pin_39
  lcdout $fe,$d4
  LCDOut "  Temp = "
  if temp.15 = 1 then LCDOut "-"
  temp = ABS(temp)
  LCDOut DEC temp / 100,0
  LCDOut "F   "       

  Pause 100
        
IF a = 0 THEN MainLoop ' a always equals zero, use instead of GOTO... 

End