BerraStation v1.0
  • Home
  • Report
  • FTDI Tutorial
  • Source:
    • Java - MainApp UI)
    • Java - Serial Read
    • AVR C-Code
    • Libraries
    • JavaFX
    • jSSC Library
First slide

BerraStation v1.0

By: Daniel Wisenhoff & Oscar Gustavsson (i13)

Read Report (PDF)

Second slide

Java & C

Built with JavaFX presentation, FTDI and C on Atmega16

View Code

Third slide

The Masterpiece

Previous Next

Java-SerialReader.java

/*
 * BerraStationv1.c
 *
 * Created: 2016-03-30 11:26:45
 *  Author: digpi07
 */ 

#define F_CPU 8000000ul

#include <avr/io.h>
#include <util/delay.h>


void USART_Init( unsigned int baud )  // SERIAL INITIALIZATION

{

	/* Set baud rate */

	UBRRH = (unsigned char)(baud>>8);

	UBRRL = (unsigned char)baud;

	/* Enable receiver and transmitter */

	UCSRB = (1<<RXEN)|(1<<TXEN);

	/* Set frame format: 8data, 2stop bit */

	UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); //(1<<URSEL) | (3<<UCSZ0);

}

void USART_Transmit( unsigned char data ) //SERIAL TRANSMIT

{

	/* Wait for empty transmit buffer */

	while ( !( UCSRA & (1<<UDRE)) );

	

	/* Put data into buffer, sends the data */

	UDR = data;

}


int voltToCelc() { // READ TEMP
	ADCSRA |= _BV(ADSC); //Start Conversion
	
	while((ADCSRA & _BV(ADCSRA)) != 0) {
		//Wait for ADCSRA false
	}
	int adcvalue = ADCL | (ADCH << 8); 
	
		return (adcvalue);
}

void init_adc()
{
	ADCSRA |= _BV(ADEN); // Enable AD
	ADMUX |= _BV(REFS0); // AVCC External Capacitor
	//ADMUX |= _BV(ADLAR); // Left-adjust of bits
	
}

int main(void)
{
	
	init_adc();
	int baud = 56;
	int celsius; 
	DDRB |= _BV(0);
	int test = 150;
	
    
		
		USART_Init(baud); // Set Baud-Rate
		
		while (1) 
		{
		
		celsius = 0; //Clear Old Value
		
		PORTB |= _BV(0);
		
		
		for(int i=0;i < 5; i++){
			celsius = celsius + voltToCelc();  // Get Celsius
			_delay_ms(100);	
			
		}
		celsius = celsius/5;
		 
		
		char adhigh = celsius >> 8; //Get rid of lows
		char adlow = celsius & 0xff; //Get rid of highs ( 0b0000000011111111)
		
		USART_Transmit(adhigh);		//Transmit highs
		USART_Transmit(adlow);		//Transmit lows
		
		
		_delay_ms(100);				//Delay 2s
		
		
		
		 PORTB &= ~_BV(0); 
		
		_delay_ms(100);	//vänta lite
		
		
		}
		
       
    
}

Back to top

© 2015 Company, Inc. · Privacy · Terms