Code:
define OSC 20
@ DEVICE PIC16F877A,HS_OSC,WDT_ON,MCLR_OFF,BOD_Off,LVP_OFF,PROTECT_OFF
include "modedefs.bas"
'----- Data Output To Pc Without MAX232 at 9600bauds reverse ----
DataTx var portc.6 'TX serial data to PC
BaudTx con 16468 '9600 bauds reverse
'Alias pins - MAX31855 temp sensor
MXSCLK var PORTD.0 'MAX31855 Clock
MXCS var PORTD.1 'MAX31855 Chip Select
MXSO Var PORTD.3 'MAX31855 Serial Data
'--Variables-----------------------
TCtemp var word 'raw data from MAX31855
tempC var word 'temperature in degrees C
tempF var word 'temp C converted to degrees F
CJtemp var word 'raw data from MAX31855
tempcjC var word 'temperature ColdJuction in degrees C
tempcjF var word 'ColdJuction C converted to degrees F
'-----------Read and display temperature from MAX31855-----------
main:
'Read Temp of Thermocouple
LOW MXCS 'chip select low
shiftin MXSO, MXSCLK, 0, [TCtemp\16] 'shift in the data
HIGH MXCS 'chip select high
tempC = TCtemp >> 4 'side shift to ditch the stuff to the right of the decimal point and just show whole degrees)
tempF = ((tempC * 18)/10) + 32 'convert C to F
'--------- Send Temp To PC ------------------
if TempC.bit11 = 0 then 'Positive Sign of Temperature
SEROUT2 DataTx,BaudTx, ["Theromocouple ",dec tempc ," degrees C ",dec tempF," degrees F " ,10,13 ] 'display the data on PC
PAUSE 1000
else
SEROUT2 DataTx,BaudTx, ["OUT of Range ",10,13 ]
pause 1000
endif
'Read Temp of ColdJuction
LOW MXCS 'chip select low
shiftin MXSO, MXSCLK, 0, [CJtemp\32] 'shift in the data
HIGH MXCS 'chip select high
tempcjC = CJtemp>> 8 'side shift to ditch the stuff to the right of the decimal point and just show whole degrees)
tempcjF = ((tempcjC * 18)/10) + 32 'convert C to F
'--------- Send Cj Temp To PC ------------------
SEROUT2 DataTx,BaudTx, ["ColdJuction ",dec tempcjc ," degrees C ",dec tempcjF," degrees F " ,10,13 ] 'display the data on PC
pause 1000
'Check Thermocouple Status
IF CJtemp.bit0=1 THEN
SEROUT2 DataTx,BaudTx, [" NO CONNECTION " ,10,13 ] 'display the data on PC
pause 1000
ENDIF
IF CJtemp.bit1=1 THEN
SEROUT2 DataTx,BaudTx, [" SHORT to GND " ,10,13 ] 'display the data on PC
pause 1000
ENDIF
IF CJtemp.bit2=1 THEN
SEROUT2 DataTx,BaudTx, [" SHORT to VCC " ,10,13 ] 'display the data on PC
PAUSE 1000
ENDIF
goto main
end
Bookmarks