0% found this document useful (0 votes)
3 views

max6675(cpp)

IC max

Uploaded by

tts506990
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

max6675(cpp)

IC max

Uploaded by

tts506990
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <avr/pgmspace.

h>
#include <util/delay.h>
#include <stdlib.h>
#include "max6675.h"

MAX6675::MAX6675(int8_t SCLK, int8_t CS, int8_t MISO) {


sclk = SCLK;
cs = CS;
miso = MISO;

//define pin modes


pinMode(cs, OUTPUT);
pinMode(sclk, OUTPUT);
pinMode(miso, INPUT);

digitalWrite(cs, HIGH);
}
double MAX6675::readCelsius(void) {

uint16_t v;

digitalWrite(cs, LOW);
_delay_ms(1);

v = spiread();
v <<= 8;
v |= spiread();

digitalWrite(cs, HIGH);

if (v & 0x4) {
// uh oh, no thermocouple attached!
return NAN;
//return -100;
}

v >>= 3;

return v*0.25;
}

double MAX6675::readFahrenheit(void) {
return readCelsius() * 9.0/5.0 + 32;
}
byte MAX6675::spiread(void) {
int i;
byte d = 0;

for (i=7; i>=0; i--)


{
digitalWrite(sclk, LOW);
_delay_ms(1);
if (digitalRead(miso)) {
//set the bit to 0 no matter what
d |= (1 << i);
}

digitalWrite(sclk, HIGH);
_delay_ms(1);
}

return d;
}
Desktop version

You might also like