Esempio n. 1
0
void moduleinit() {
	DDRD = 0xf0;
	DDRB = 0x03;
	// initialize lcd
	init_lcd();
	writecommand(0x01);

	// leds 					(blue wire)
	DDRD |= (1 << PD2) | (1 << PD3);
	// rotary encoder (yellow wire)
	DDRC &=	~(1 << PC1) | ~(1 << PC2);
	PORTC |= (1 << PC1) |  (1 << PC2);
	// buttons 				(green wire)
	DDRB &= ~(1 << PB3) | ~(1 << PB4);
	PORTB |= (1 << PB3) |  (1 << PB4);
	
	//enable interrupts
	sei();
	PCICR |= (1 << PCIE0) | (1 << PCIE1);	
	PCMSK0 |= (1 << PB3) | (1 << PB4);
	PCMSK1 |= (1 << PC1) | (1 << PC2);
	
	//serial interface
	UBRR0 = 103; // Set baud rate
	UCSR0B |= (1 << TXEN0 | 1 << RXEN0); 	// Enable RX and TX
	UCSR0C = (3 << UCSZ00); 							// Async., no parity,
 	// 1 stop bit, 8 data bits
	DDRC |= (1 << PC3);
	PORTC &= ~(1 << PC3);

	//initialize thermometer
	ds1631_init();
	ds1631_conv();

	// template
	stringout("Temp:");
	moveto(8);
	stringout("Rmt :");
	moveto(0x40);
	stringout("Low :");
	moveto(0x48);
	stringout("High:");
}
Esempio n. 2
0
int main(void)
{
    init_lcd();
    writecommand(0x01);
    updateScreen();

    DDRD |= (1 << PD2);//output for green LED
    DDRD |= (1 << PD3);//output for red LED

    //button pullup resistors:
    PORTB |= (1 << PB3) | (1 << PB4);

    //rotary encoder initializations:
    initialize_rotary();
    sei();

    PORTC |= (1 << PC4) | (1 << PC5);//i2c pullup resistors

    //enable line
    PORTC |= (1 << PC3);
    DDRC |= (1 << PC3); //set as output

    //DS1631
    ds1631_init();
    ds1631_conv();
    unsigned char temp[2];
    //serial communication
    init_serial();

    while (1) {
        PORTC &= ~(1 << PC3);//set enable to 0
        ds1631_temp(temp);
        int tempCelsius = temp[0];
        //convert from celsius to fahrenheit:
        if(temp[1] == 0){
            tempF = (tempCelsius*9)/5 + 32;
        }
        else{
            tempF = tempCelsius * 10 + 5;
            tempF = (tempF*9)/5 + 320;
            tempF /= 10;
        }

        if(oldTempF != tempF){//if temperature changes, update + transmit data
            //update temp
            updateTop();
            char temp[5];
            snprintf(temp, 5, "%d", tempF);
            transmitData(temp, &tempF);
        }

        oldTempF = tempF;//update old temp

        if((PINB & (1 << PB3)) == 0){//if high button is pressed
            buttonState = 1;//high
        }
        if((PINB & (1 << PB4)) == 0){//if low button is pressed
            buttonState = 0;//low
        }

        if(bufferValidFlag == 1){//valid data received
            //convert to int stored inside remoteVal
            int hundreds = (receivedDataBuffer[1]-0x30)*100;
            int tens = (receivedDataBuffer[2]-0x30)*10;
            int ones = receivedDataBuffer[3]-0x30;
            remoteVal = hundreds + tens + ones;
            if(receivedDataBuffer[0] == '-'){
                remoteVal = 0 - remoteVal;
            }
            updateTop();
            bufferValidFlag = 0;//reset
        }

        if(change == 1){
            updateScreen();
            change = 0;//reset
        }

        updateLED();
    }
    return 0;   /* never reached */
}