' -----[ Title ]----------------------------------------------------------- ' Ds2760 ver 1.bsp ' Program for a Dallas DS2760 module with a Chromel/Alumel or ' Iron/Constantan or Copper/Constantan. This code will read temperatures ' from 0c to ' {$STAMP BS2p} ' {$PBASIC 2.5} ' -----[ Declarations ]---------------------------------------------------- temp VAR Byte r VAR Word rhi VAR Byte rlo VAR Byte tj VAR Byte x VAR Word v VAR Word y VAR Word s VAR Word rn VAR Byte y0 VAR y.BIT0 y1 VAR y.BIT1 y2 VAR y.BIT2 y3 VAR y.BIT3 y4 VAR y.BIT4 y5 VAR y.BIT5 y6 VAR y.BIT6 y7 VAR y.BIT7 y8 VAR y.BIT8 y9 VAR y.BIT9 y10 VAR y.BIT10 y11 VAR y.BIT11 y12 VAR y.BIT12 y13 VAR y.BIT13 y14 VAR y.BIT14 y15 VAR y.BIT15 z VAR Bit w VAR Nib tc VAR Nib p VAR Nib Owpin PIN 8 ' -----[ Initialization ]-------------------------------------------------- ' Each number relates to a different type of thermocouple ' 1 = 'C/A = Chromel/Alumel thermo ' 2 = 'I/C = Iron/Constantan thermo ' 3 = 'C/C = Copper/Constantan thermo Int: tc = 0 'to change type of thermocouple ' sets up display for thermocouple DEBUG 0,"Please pick type",CR DEBUG "1 = C/A = Chromel/Alumel thermocouple",CR DEBUG "2 = I/C = Iron/Constantan thermocouple",CR DEBUG "3 = C/C = Copper/Constantan thermocouple",CR,8 DEBUGIN tc IF tc = 1 THEN DEBUG 0,"You have picked Chromel/Alumel",CR GOTO start ELSEIF tc = 2 THEN DEBUG 0,"You have picked Iron/Constantan thermocouple",CR GOTO start ELSEIF tc = 3 THEN DEBUG 0,"You have picked Copper/Constantan thermocouple",CR GOTO start ENDIF GOTO Int ' -----[ Main Routine ]---------------------------------------------------- Start: 'turn on DS2760 OWOUT Owpin,%0011,[$cc,$6c,$31,%00000000] 'get the serial number OWOUT Owpin,%0001,[$33] OWIN Owpin,%0010,[SPSTR 8] DEBUG "Serial Number " FOR x = 0 TO 7 GET x,v DEBUG HEX2 v temp = V + V NEXT IF temp = 0 THEN xx PAUSE 500 DEBUG CR aa: p = 7+tc y = 0 OWOUT Owpin,%0001,[$cc,$69,$18] OWIN Owpin,%0110,[y3,y4,y5,y6,y7,y8,y9,z,z,z,z,z,z,y0,y1,y2] y = (y*127)/1024 tj=y STORE tc 'point to table location s = 2*y READ s,rhi 'read table READ s+1,rlo 'get the input voltage y = 0 OWOUT Owpin,%0001,[$cc,$69,$0c] OWIN Owpin,%0110,[y3,y4,y5,y6,y7,y8,y9,z,z,z,z,z,z,y0,y1,y2] y = ((y*10)/102)*50 DEBUG 2,0,8,"input voltage = ",DEC y," mv",CR 'get the TC output voltage y = 0 OWOUT Owpin,%0001,[$cc,$69,$0e] OWIN Owpin,%0110,[y5,y6,y7,y8,y9,y10,y11,z,z,z,z,y0,y1,y2,y3,y4] DEBUG ? y IF y<4060 THEN over y = 0 over: s = y*16 DEBUG "tc voltage = ",DEC s," uv",CR r = s+(rhi*256)+rlo rhi = r.HIGHBYTE:rlo=r.LOWBYTE FOR x=0 TO 2000 STEP 2 READ x,y IF y=rhi THEN over2 NEXT over2: FOR s=x+1 TO 2000 STEP 2 READ s,y READ s-1,rn IF rhi= rlo THEN over3 NEXT over3: s = s/2 DEBUG "TC = ",DEC s," deg C",CR v =((s*18)/10)+32 DEBUG "TC = ",DEC v," deg F",CR PAUSE 2000 GOTO aa xx: DEBUG 0,CR,CR,"No Thermocouple found" STOP