Hi Steve,
It took some time but I finally got around to trying to get the sensor up and running but I'm not having any success. I'm pretty sure I have everything configured ok with your code. Could you please have a look and see if there's something that you can see that I've done wrong here? Any help from anyone would be very much appreciated. I included the schematics I used in an attachment here.
Thanks
jessey
Code:'************************************************************************** '* Name : Furnace Temperature Probe * '* Author : Jessey Montgomery * '* Includes: Byte_Butchers code to read temperature using a MAX6675 * '* Date : April 24/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 Pic16F688-I/P 04470AY. * '************************************************************************** '(1) Comments & Objectives ' ===================== ' this program is used to display the temperature from a K type sensor using a ' MAX6675 interface... '------------------------------------------------------------------------------' 'Connections for the PICKIT 2 Programmer for a 16F688 'Pickit 2 pins 16f688 pins '============= =========== ' 1 ...... Connect to ...... pin 4 RA3/MCLR/VPP ' 2 ...... Connect to ...... pin 1 VDD (positive) ' 3 ...... Connect to ...... pin 14 VSS (ground) ' 4 ...... Connect to ...... pin 13 RA0/AN0/C1IN+/ICSPDAT/ULPWU ' 5 ...... Connect to ...... pin 12 RA1/AN1/C1IN-/VREF/ICSPCLK ' 6......................................no connection '*Note 'Put a 0.1mf capicator on pin 1 of 16f688 to ground '------------------------------------------------------------------------------' ' -------------- ' | 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 ' | | ' -------------- '------------------------------------------------------------------------------' ' -------------------------------------------------------------------------------- ' Configuration Of Pins ' ===================== ' ------------ ' | 16f688 | ' VDD+ |1 14| VSS- ' | | ' Not Used |2 13| Clock output for 6675 to pin 5 ' | | ' Not Used |3 12| Chip Select output for 6675 pin 6 ' | | ' Not Used |4 11| Serial input from 6675 to pin 7 ' | | ' Blue/White.........Enable bit |5 10| Data bit 4...............Blue ' | | ' Orange/Black..Register select |6 9| Data bit 5..............White ' | | ' Orange.............Data bit 7 |7 8| Data bit 6..............Green ' | | ' ------------ '------------------------------------------------------------------------------' ' -------------- ' | MAX6675 | ' -5 VSS |1 8| No Connection ' | | ' T- Alumel Lead (Red) |2 7| Serial Output to 688 pin 11 ' | | ' T+ Chromel Lead (yellow)|3 6| Chip Select input to 688 pin 12 ' | | ' +5 VDD |4 5| Serial Clock in from 688 pin 13 ' -------------- '(2) PIC Config Fuse Definitions for 16f688 ' ====================================== @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF & _BOD_ON @ ERRORLEVEL -306; ' turns off cross page boundary message alerts after compile '(3) PIC Hardware Definitions (ie Pin-Out & Port Assignments) ' ======================================================== 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 '------------------------------------------------------------------------------' '------------- 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) ...................................... MXSCLK VAR PORTA.0 TRISA.1 = 0 '(pin 12) .........................................MXCS VAR PORTA.1 TRISA.2 = 1 '(pin 11) .........................................MXSO VAR PORTA.2 TRISA.3 = 1 '(pin 4) ............... NOT USED VAR PORTA.3 TRISA.4 = 1 '(pin 3) ............... NOT USED VAR PORTA.4 TRISA.5 = 1 '(pin 2) ............... NOT USED 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 ANSEL = %00000000 ' set all adc pins to digital CMCON0 = 7 ' turn off comparators 'Alias pins - MAX6675 temp sensor MXSCLK var PORTA.0 'pin 13 of 16f688 (Clock) to pin 5 of MAX6675 MXCS var PORTA.1 'pin 12 of 16f688 (Chip Select) to pin 6 of MAX6675 MXSO Var PORTA.2 'pin 11 of 16f688 (Serial) to pin 7 of MAX6675 'Allocate MAX6875 Variables MXTemp var word 'raw data from 6675/type K sensor TempC var word 'converted to degrees C a VAR BIT ' a always equals zero, used in IF-THEN's instead of using GOTO's a = 0 INCLUDE "modedefs.bas" '5. Actual Program Start (usually a "Goto MainLoop" jump) ' ===================================================== Pause 1000 ' Pause for LCD to initialize LCDOut $fe, 1, "Temp 6675 Laptop" PAUSE 2500 IF a = 0 THEN MainLoop '------------------------------------------------------------------------------' MainLoop: '-----------Read and display temperature from MAX6675----------- MXCS = 0 'Chip select low shiftin MXSO, MXSCLK, 0, [MXTemp\16] 'read the data to MXTemp MXCS = 1 'Chip select high TempC = MXtemp >> 5'right shift data 5 places to get degrees C (in data sheet) LCDOut $fe, 1,"Temp = ", DEC TempC, " C " 'Spit it out on an LCD PAUSE 100 'reduce lcd flicker IF a = 0 THEN MainLoop ' a always equals zero, use instead of GOTO... End





Bookmarks