Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Pajeci_stanice_2012.c
- * Processor: Atmel ATmega16
- * Created: 6.6.2012 23:15:40
- * Author: Luboš Fukan, Czech Republic
- */
- #include <avr/io.h>
- #include <util/delay.h>
- #include <compat/deprecated.h>
- #define LCD
- #include "lcd_lib.h"
- char text[8];
- void max6675_select() {
- cbi(PORTB, 4);
- PORTA=0b11111110; //led diode indication instead of debugger :((
- }
- void max6675_deselect() {
- sbi(PORTB, 4);
- PORTA=0b01111111; //led diode indication instead of debugger :((
- }
- uint8_t send_spi(uint8_t spi_data)
- {
- SPDR = spi_data;
- while (!(SPSR & (1<<SPIF)));
- return SPDR;
- }
- void max6675_read_temp()
- {
- /* Enable SPI, Master, set clock rate fck/16 */
- SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
- short value = 0;
- float temp = 0;
- uint8_t highByte=0;
- uint8_t lowByte=0;
- max6675_select();
- _delay_ms(1000);
- highByte = send_spi(0);
- lowByte = send_spi(0);
- max6675_deselect();
- if (lowByte & (1<<2)) {
- LCDGotoXY(0,0);
- sprintf(text,"TC NOT C");
- LCDstring(text,8);
- LCDGotoXY(0,1);
- sprintf(text,"ONNECTED");
- LCDstring(text,8);
- } else {
- value = (highByte << 5 | lowByte>>3);
- temp = (value*0.25);
- // Multiply the value by 0.25 to get temp in ˚C
- LCDGotoXY(0,0);
- sprintf(text,"TC TEMP:");
- LCDstring(text,8);
- LCDGotoXY(0,1);
- sprintf(text,"%0.8d", temp);
- LCDstring(text,8);
- }
- }
- int main(void)
- {
- DDRA=0b11111111;
- LCDinit();
- LCDclr();
- LCDGotoXY(0,0);
- sprintf(text," MAX667");
- LCDstring(text,8);
- LCDGotoXY(0,1);
- sprintf(text,"5 TEST ");
- LCDstring(text,8);
- while (1)
- {
- max6675_read_temp();
- _delay_ms(500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement