View difference between Paste ID: aKk58z36 and 20S9f4hi
SHOW: | | - or go back to the newest paste.
1
/*
2
 * Pajeci_stanice_2012.c
3
 * Processor: Atmel ATmega16
4
 * Created: 6.6.2012 23:15:40
5
 * Author: Luboš Fukan, Czech Republic
6
 */ 
7
8
#include <avr/io.h>
9
#include <util/delay.h>											
10
#include <compat/deprecated.h>									
11
12
#define LCD
13
#include "lcd_lib.h"											 
14
char text[8];													
15
16
void max6675_select() {
17
    cbi(PORTB, 4);
18-
	PORTA=0b11111110;
18+
    PORTA=0b11111110; //led diode indication instead of debugger :((
19
}
20
21
void max6675_deselect() {
22-
	sbi(PORTB, 4);  
22+
    sbi(PORTB, 4);  
23-
	PORTA=0b01111111;  
23+
    PORTA=0b01111111; //led diode indication instead of debugger :((
24
}
25
26
uint8_t send_spi(uint8_t spi_data)
27
{
28
  SPDR = spi_data;
29
  while (!(SPSR & (1<<SPIF)));
30
  return SPDR;
31
}
32
33
void max6675_read_temp()
34
{
35
	/* Enable SPI, Master, set clock rate fck/16 */ 
36
    SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0); 
37
	
38
    short value = 0;
39
    float temp = 0;
40
    
41
    uint8_t highByte=0;
42
    uint8_t lowByte=0;
43
    
44
    max6675_select();
45
    _delay_ms(1000);
46
    highByte = send_spi(0);
47
    lowByte = send_spi(0);
48
    max6675_deselect();
49
50
    if (lowByte & (1<<2)) {
51
		LCDGotoXY(0,0);												
52
  		sprintf(text,"TC NOT C");
53
  		LCDstring(text,8);   
54
  		LCDGotoXY(0,1);												
55
  		sprintf(text,"ONNECTED"); 
56
  		LCDstring(text,8);  		
57
    } else {
58
        value = (highByte << 5 | lowByte>>3);
59
		temp = (value*0.25); 
60
		// Multiply the value by 0.25 to get temp in ˚C	
61
		LCDGotoXY(0,0);												
62
  		sprintf(text,"TC TEMP:");
63
  		LCDstring(text,8);   
64
  		LCDGotoXY(0,1);												
65
  		sprintf(text,"%0.8d", temp); 
66
  		LCDstring(text,8);
67
    }
68
	  
69
}
70
71
int main(void)
72
{	
73
	DDRA=0b11111111;
74
	
75
	LCDinit();											
76
	LCDclr();													
77
	
78
  	LCDGotoXY(0,0);												
79
  	sprintf(text,"  MAX667");
80
  	LCDstring(text,8);   
81
  	LCDGotoXY(0,1);												
82
  	sprintf(text,"5 TEST  "); 
83
  	LCDstring(text,8);  
84
	  
85
	while (1)
86
	{
87
		max6675_read_temp();
88
		_delay_ms(500);
89
	}
90
}