/* * Stektermometer.c * * Created: 2015-04-01 12:27:28 * Author: digpi16 */ #include #include #include int currentTemp; int goalTemp; void initDisplay() { PORTA = 0x40; //default E högt PORTD = 0x3C; //Function set PORTA = 0x00; //Ner med E PORTA = 0x40; //E högt _delay_ms('50'); PORTD = 0x0E; //Display on/off PORTA = 0x00; //Ner med E PORTA = 0x40; //E högt _delay_ms('50'); PORTD = 0x1C; //Cursor/display shift PORTA = 0x00; //Ner med E PORTA = 0x40; //E högt _delay_ms('50'); clearDisplay(); } void clearDisplay(){ PORTA = 0x40; //default E högt PORTD = 0x01; //Clear display PORTA = 0x00; //Ner med E PORTA = 0x40; //E högt _delay_ms('150'); } //position hex enl datablad void writeChar(char output, char position){ PORTA = 0x40; PORTD = position; PORTA = 0x10; PORTA = 0x50; displayReady(); PORTD = output; PORTA = 0x10; PORTA = 0x50; } void displayReady() { DDRD = 0x00; while(PIND==0x80) { } DDRD=0xFF; } void setTemp(int temp) { goalTemp = temp; } void printInitText(){ writeChar('C', 0x80); writeChar('u', 0x81); writeChar('r', 0x82); writeChar('r', 0x83); writeChar('e', 0x84); writeChar('n', 0x85); writeChar('t', 0x86); writeChar(':', 0x87); writeChar(0xDF, 0x8B); writeChar('C', 0x8C); writeChar('G', 0xC0); writeChar('o', 0xC1); writeChar('a', 0xC2); writeChar('l', 0xC3); writeChar(':', 0xC4); writeChar(0xDF, 0xC8); writeChar('C', 0xC9); } void testTemp(){ int newTemp = voltToCelc(); if(newTemp != currentTemp) { currentTemp = newTemp; printCurrentTemp(); } if((goalTemp == currentTemp) || (goalTemp < currentTemp)){ PORTC = 0x80; } } void printCurrentTemp(){ char ut [2]; sprintf(ut,"%d",currentTemp); writeChar(ut[0], 0x89); writeChar(ut[1], 0x8A); } int voltToCelc() { ADCSRA = 0xC0; while(ADCSRA==0xC0) { //ADCSRA blir 0x90 } int rawvoltage = ADC; int millivolts = rawvoltage*5; //5160/1024 int celsius= (millivolts)/10; return celsius; } int main(void) { DDRA = 0x70; DDRB = 0x00; DDRC = 0xC0; DDRD = 0xFF; ADCSRA = 0x80; ADMUX = 0x47; initDisplay(); printInitText(); printCurrentTemp(); while (1) { if(PINB & (1<