Compare commits
	
		
			No commits in common. 'rewrite_for_hd774' and 'master' have entirely different histories. 
		
	
	
		
			rewrite_fo
			...
			master
		
	
		
	| @ -1,93 +0,0 @@ | |||||||
| #include <avr/io.h> |  | ||||||
| #include <avr/interrupt.h> |  | ||||||
| 
 |  | ||||||
| #include "adc.h" |  | ||||||
| 
 |  | ||||||
| void adc_init() |  | ||||||
| { |  | ||||||
|     ADMUX = 1 << REFS0 | 0 << REFS1; //Select external Vref
 |  | ||||||
| 
 |  | ||||||
|     //ADC Status Register A
 |  | ||||||
|     ADCSRA = 1 << ADEN   //Enable ADC
 |  | ||||||
|              | 1 << ADIE //Enable ISR after conversion complete
 |  | ||||||
|              //|  1<<ADATE //Freerunning-Mode
 |  | ||||||
|              //|  1<<ADLAR //2 results bits are left aligned
 |  | ||||||
|              | 1 << ADPS2 //Set clock-prescaler to 128
 |  | ||||||
|              | 1 << ADPS1 | 1 << ADPS0; |  | ||||||
|     ADCSRA |= 1 << ADSC; //Start first Conversion for "warmup"
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void set_ADC_Channel(uint8_t adr) |  | ||||||
| { |  | ||||||
|     if (adr < 11) |  | ||||||
|     { |  | ||||||
|         ADMUX &= (0b11110000); //Clear MUX-Address
 |  | ||||||
|         ADMUX |= adr;          //Set new MUX-Address
 |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| ISR(ADC_vect) |  | ||||||
| { |  | ||||||
|     //static uint8_t init[4] = {0,0,0,0};
 |  | ||||||
|     static uint8_t current_channel = 0; |  | ||||||
| 
 |  | ||||||
|     static uint16_t read_buffer[128]; |  | ||||||
|     static uint8_t buffer_pos = 0; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     //Reading 10bit conversion result
 |  | ||||||
|     uint16_t ADC_reading = ADCL;        //copy the first LSB bits
 |  | ||||||
|     ADC_reading |= ADCH << 8;           //copy remaing byte
 |  | ||||||
| 
 |  | ||||||
|     read_buffer[buffer_pos] = ADC_reading; |  | ||||||
|     buffer_pos++; |  | ||||||
| 
 |  | ||||||
|     if(buffer_pos == (sizeof(read_buffer) / sizeof(read_buffer[0]))){ |  | ||||||
|         uint32_t sum = 0; |  | ||||||
|         for(uint8_t i = 0; i < buffer_pos; i++){ |  | ||||||
|             sum += read_buffer[i]; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         //convert to temperature
 |  | ||||||
|         sum /= 3; |  | ||||||
| 
 |  | ||||||
|         switch(current_channel){ |  | ||||||
|             case 0: |  | ||||||
|                 temp_values[3] = sum/buffer_pos; |  | ||||||
|                 break; |  | ||||||
|             case 1: |  | ||||||
|                 temp_values[0] = sum/buffer_pos; |  | ||||||
|                 break; |  | ||||||
|             case 2: |  | ||||||
|                 temp_values[1] = sum/buffer_pos; |  | ||||||
|                 break; |  | ||||||
|             case 3: |  | ||||||
|                 temp_values[2] = sum/buffer_pos; |  | ||||||
|                 break; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         buffer_pos = 0; |  | ||||||
| 
 |  | ||||||
|         current_channel++; |  | ||||||
|         if(current_channel == 4) |  | ||||||
|             current_channel = 0; |  | ||||||
|         set_ADC_Channel(current_channel); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     ADCSRA |= (1 << ADSC); //Start next conversion
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     //TODO write non broken adc code
 |  | ||||||
|     //if(adc_buf[current_channel].position == BUFFER_SIZE-1){
 |  | ||||||
|     //    //if(init[current_channel]){
 |  | ||||||
|     //        //float tmp = (99*adc_avrg[current_channel]) + get_buffer_mean(&adc_buf[current_channel]);
 |  | ||||||
|     //        //tmp /= 100;
 |  | ||||||
|     //        adc_avrg[current_channel] = get_buffer_mean(&adc_buf[current_channel]);
 |  | ||||||
|     //    //}
 |  | ||||||
|     //    //else{
 |  | ||||||
|     //    //    adc_avrg[current_channel] = get_buffer_mean(&adc_buf[current_channel]);
 |  | ||||||
|     //    //    init[current_channel]=0;
 |  | ||||||
|     //    //}
 |  | ||||||
|     //}
 |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| @ -1,11 +0,0 @@ | |||||||
| #ifndef _ADC_H_ |  | ||||||
| #define _ADC_H_ |  | ||||||
| 
 |  | ||||||
| #include <stdint.h> |  | ||||||
| 
 |  | ||||||
| extern volatile uint16_t temp_values[4]; |  | ||||||
| 
 |  | ||||||
| void adc_init(void); |  | ||||||
| 
 |  | ||||||
| #endif//_ADC_H_
 |  | ||||||
| 
 |  | ||||||
| @ -0,0 +1,42 @@ | |||||||
|  | #include <util/atomic.h> | ||||||
|  | 
 | ||||||
|  | #include "buffer.h" | ||||||
|  | 
 | ||||||
|  | void insert_to_buffer(uint16_t val, volatile buffer_t* buf){ | ||||||
|  |     ATOMIC_BLOCK(ATOMIC_FORCEON){ | ||||||
|  |         buf->position++; | ||||||
|  |         if(buf->position == BUFFER_SIZE) | ||||||
|  |             buf->position = 0; | ||||||
|  |         buf->values[buf->position] = val; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | float get_buffer_mean(volatile buffer_t* buf){ | ||||||
|  | 
 | ||||||
|  |     ///* discard lowest and highest value */
 | ||||||
|  |     //uint16_t low=0xFFFF;
 | ||||||
|  |     //uint16_t high=0;
 | ||||||
|  |     //uint16_t index_l = 0;
 | ||||||
|  |     //uint16_t index_h = 0;
 | ||||||
|  |     //for(uint16_t i=0; i<BUFFER_SIZE; i++){
 | ||||||
|  |     //    if(buf->values[i] < low){
 | ||||||
|  |     //        low=buf->values[i];
 | ||||||
|  |     //        index_l = i;
 | ||||||
|  |     //    }
 | ||||||
|  |     //    if(buf->values[i] > high){
 | ||||||
|  |     //        high=buf->values[i];
 | ||||||
|  |     //        index_h = i;
 | ||||||
|  |     //    }
 | ||||||
|  |     //}
 | ||||||
|  |          | ||||||
|  | 
 | ||||||
|  |     uint32_t sum = 0; | ||||||
|  |     for(uint16_t i=0; i<BUFFER_SIZE; i++){ | ||||||
|  |         //if(i == index_h || i == index_l)
 | ||||||
|  |         //    continue;
 | ||||||
|  |         sum += buf->values[i]; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     uint16_t res = sum/(BUFFER_SIZE/*-2*/); | ||||||
|  |     return res; | ||||||
|  | } | ||||||
| @ -0,0 +1,11 @@ | |||||||
|  | #include <stdint.h> | ||||||
|  | 
 | ||||||
|  | #define BUFFER_SIZE 200 | ||||||
|  | 
 | ||||||
|  | typedef struct { | ||||||
|  |     uint16_t values[BUFFER_SIZE]; | ||||||
|  |     uint16_t position; | ||||||
|  | } buffer_t; | ||||||
|  | 
 | ||||||
|  | void insert_to_buffer(uint16_t val, volatile buffer_t* buf); | ||||||
|  | float get_buffer_mean(volatile buffer_t* buf); | ||||||
| @ -1,61 +0,0 @@ | |||||||
| /*
 |  | ||||||
|  * i2c.c |  | ||||||
|  * |  | ||||||
|  * Created: 20.01.2018 12:50:54 |  | ||||||
|  *  Author: Ulrich |  | ||||||
|  */  |  | ||||||
| 
 |  | ||||||
| #include "i2c.h" |  | ||||||
| 
 |  | ||||||
| void i2c_init(void){ |  | ||||||
| 	I2C_PORT |= (1 << SDA_PIN | 1 << SCL_PIN);			//Port Pullup
 |  | ||||||
| 	TWCR = 0; |  | ||||||
| 	TWSR = 0; |  | ||||||
| 	TWBR = ((F_CPU/SCL_CLOCK)-16)/2; |  | ||||||
| 	_delay_ms(50); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| //***************************************************************************************
 |  | ||||||
| uint8_t i2c_start (uint8_t addr){ |  | ||||||
| 	uint16_t timeout = 0; |  | ||||||
| 
 |  | ||||||
|     TWCR = (1 << TWINT | 1 << TWSTA | 1 << TWEN); |  | ||||||
|     while(!(TWCR & (1<<TWINT))){ |  | ||||||
| 	    if((timeout++) > 1000) return 1; |  | ||||||
| 	} |  | ||||||
|     TWDR = addr; |  | ||||||
|     TWCR = (1 << TWINT | 1 << TWEN); |  | ||||||
| 	timeout = 0; |  | ||||||
|     while(!(TWCR & (1<<TWINT))){ |  | ||||||
| 	    if((timeout++) > 1000) return 1; |  | ||||||
|     } |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| //***************************************************************************************
 |  | ||||||
| uint8_t i2c_byte (uint8_t byte){   |  | ||||||
| 	uint16_t timeout = 0; |  | ||||||
|     TWDR = byte; |  | ||||||
|     TWCR = (1 << TWINT | 1 << TWEN); |  | ||||||
|     while(!(TWCR & (1<<TWINT))){ |  | ||||||
| 		if((timeout++) > 1000) return 1; |  | ||||||
| 	} |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| //***************************************************************************************
 |  | ||||||
| uint8_t i2c_readNak(void) |  | ||||||
| { |  | ||||||
| 	uint16_t timeout = 0; |  | ||||||
| 	TWCR = (1<<TWINT) | (1<<TWEN); |  | ||||||
| 	while(!(TWCR & (1<<TWINT))){ |  | ||||||
| 		if((timeout++) > 1000) return 0; |  | ||||||
| 	} |  | ||||||
|     return TWDR; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| //***************************************************************************************
 |  | ||||||
| void i2c_stop (void){ |  | ||||||
|     TWCR = (1 << TWINT | 1 << TWSTO | 1 << TWEN); |  | ||||||
| 	TWCR = 0; |  | ||||||
| } |  | ||||||
| @ -1,26 +0,0 @@ | |||||||
| /*
 |  | ||||||
|  * i2c.h |  | ||||||
|  * |  | ||||||
|  * Created: 20.01.2018 12:51:11 |  | ||||||
|  *  Author: Ulrich |  | ||||||
|  */  |  | ||||||
| 
 |  | ||||||
| #ifndef I2C_H_ |  | ||||||
| 	#define I2C_H_ |  | ||||||
| 
 |  | ||||||
| 	#include <avr/io.h> |  | ||||||
| 	#include <util/delay.h> |  | ||||||
| 	 |  | ||||||
| 	//I2C
 |  | ||||||
| 	#define SDA_PIN			PC4 //PIN am Atmel
 |  | ||||||
| 	#define SCL_PIN			PC5 //PIN am Atmel
 |  | ||||||
| 	#define I2C_PORT		PORTC //PORT am Atmel
 |  | ||||||
| 	#define SCL_CLOCK		40000UL |  | ||||||
| 
 |  | ||||||
| 	void i2c_init(void); |  | ||||||
| 	uint8_t i2c_start (uint8_t); |  | ||||||
| 	uint8_t i2c_byte (uint8_t);   |  | ||||||
| 	uint8_t i2c_readNak(void); |  | ||||||
| 	void i2c_stop (void); |  | ||||||
| 
 |  | ||||||
| #endif /* I2C_H_ */ |  | ||||||
| @ -1,211 +0,0 @@ | |||||||
| /*
 |  | ||||||
|  * lcd.c |  | ||||||
|  * |  | ||||||
|  * Created: 20.01.2018 12:51:11 |  | ||||||
|  *  Author: Ulrich |  | ||||||
|  */  |  | ||||||
| 
 |  | ||||||
| #include "lcd.h" |  | ||||||
| 
 |  | ||||||
| volatile unsigned char char_counter = 0; |  | ||||||
| 
 |  | ||||||
| volatile uint8_t lcd_ctrl_reg = 0; |  | ||||||
| 
 |  | ||||||
| // output data to lcd
 |  | ||||||
| void lcd_out (unsigned char c) { |  | ||||||
| 	i2c_start(LCD_I2C_ADDR); |  | ||||||
| 	i2c_byte(c | LCD_BACKLIGHT); |  | ||||||
| 	i2c_stop(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| //***************************************************************************************
 |  | ||||||
| // CD = Command or Data
 |  | ||||||
| void lcd_nibble_out(unsigned char c, unsigned char cd) { |  | ||||||
| 	unsigned char out = 0; |  | ||||||
| 	unsigned char rs = 0; |  | ||||||
| 	 |  | ||||||
| 	if(cd) rs=LCD_RS; |  | ||||||
| 
 |  | ||||||
| 	//4 upper bits
 |  | ||||||
| 	if(c & (1<<4)) out |= LCD_D4; |  | ||||||
| 	if(c & (1<<5)) out |= LCD_D5; |  | ||||||
| 	if(c & (1<<6)) out |= LCD_D6; |  | ||||||
| 	if(c & (1<<7)) out |= LCD_D7; |  | ||||||
| 	lcd_out(out | rs | LCD_E); |  | ||||||
| 	_delay_ms(5); |  | ||||||
| 	lcd_out(out | rs); |  | ||||||
| 
 |  | ||||||
| 	//4 lower bits
 |  | ||||||
| 	out=0; |  | ||||||
| 	if(c & (1<<0)) out |= LCD_D4; |  | ||||||
| 	if(c & (1<<1)) out |= LCD_D5; |  | ||||||
| 	if(c & (1<<2)) out |= LCD_D6; |  | ||||||
| 	if(c & (1<<3)) out |= LCD_D7; |  | ||||||
| 	lcd_out(out | rs | LCD_E); |  | ||||||
| 	_delay_ms(5); |  | ||||||
| 	lcd_out(out | rs ); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void lcd_set_position(uint8_t row, uint8_t col){ |  | ||||||
|     if(col >= LCD_WIDTH) |  | ||||||
|         return; |  | ||||||
| 
 |  | ||||||
|     if(row==0) |  | ||||||
|         lcd_nibble_out(0x80|col, 0); |  | ||||||
|     if(row==1) |  | ||||||
|         lcd_nibble_out(0xC0|col, 0); |  | ||||||
|     if(row==2) |  | ||||||
|         lcd_nibble_out(0x80|(col+LCD_WIDTH), 0); |  | ||||||
|     if(row==3) |  | ||||||
|         lcd_nibble_out(0xC0|(col+LCD_WIDTH), 0); |  | ||||||
| 
 |  | ||||||
|     char_counter = (row * LCD_WIDTH) + col; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void lcd_cursor(uint8_t en){ |  | ||||||
|     if(en) |  | ||||||
|         lcd_nibble_out(0x08 | 0x04 | 0x02, 0); |  | ||||||
|     else |  | ||||||
|         lcd_nibble_out(0x08 | 0x04, 0); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| //***************************************************************************************
 |  | ||||||
| // clear LCD
 |  | ||||||
| void lcd_clear() { |  | ||||||
| 	lcd_nibble_out(0x01, 0); // clear display
 |  | ||||||
| 	lcd_nibble_out(0x80, 0); |  | ||||||
| 	char_counter = 0; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| //***************************************************************************************
 |  | ||||||
| // LCD home
 |  | ||||||
| void lcd_home() { |  | ||||||
| 	lcd_nibble_out(0x80, 0); |  | ||||||
| 	char_counter = 0; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| //***************************************************************************************
 |  | ||||||
| // Init LCD
 |  | ||||||
| void lcd_init() { |  | ||||||
| 	unsigned char loop=3; |  | ||||||
| 
 |  | ||||||
| 	while(loop--){ |  | ||||||
| 		lcd_out(LCD_D4 | LCD_D5 | LCD_E); |  | ||||||
| 		_delay_ms(10); |  | ||||||
| 		lcd_out(LCD_D4 | LCD_D5); |  | ||||||
| 		_delay_ms(100); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// 4 bit mode
 |  | ||||||
| 	lcd_out(LCD_D5 | LCD_E); |  | ||||||
| 	_delay_ms(10); |  | ||||||
| 	lcd_out(LCD_D5); |  | ||||||
| 	_delay_ms(10); |  | ||||||
| 
 |  | ||||||
| 	lcd_nibble_out(0x28, 0); |  | ||||||
| 	lcd_nibble_out(0x0C, 0); |  | ||||||
| 
 |  | ||||||
| 	lcd_clear(); |  | ||||||
|     lcd_cursor(0); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| //***************************************************************************************
 |  | ||||||
| void lcd_write_char (char c) { |  | ||||||
| 	if(char_counter == LCD_WIDTH) lcd_set_position(1,0); |  | ||||||
| 	if(char_counter == 2*LCD_WIDTH) lcd_set_position(2,0); |  | ||||||
| 	if(char_counter == 3*LCD_WIDTH) lcd_set_position(3,0); |  | ||||||
| 	if(char_counter == 4*LCD_WIDTH) lcd_set_position(0,0); |  | ||||||
| 	char_counter++; |  | ||||||
| 	lcd_nibble_out(c, 1); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| //***************************************************************************************
 |  | ||||||
| void lcd_print_str(char *str) { |  | ||||||
| 	while (*str != 0){ |  | ||||||
|         if(char_counter == LCD_WIDTH) lcd_set_position(1,0); |  | ||||||
|         if(char_counter == 2*LCD_WIDTH) lcd_set_position(2,0); |  | ||||||
|         if(char_counter == 3*LCD_WIDTH) lcd_set_position(3,0); |  | ||||||
|         if(char_counter == 4*LCD_WIDTH) lcd_set_position(0,0); |  | ||||||
|         char_counter++; |  | ||||||
| 		lcd_nibble_out(*str++, 1); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| //***************************************************************************************
 |  | ||||||
| void lcd_write_P (const char *Buffer,...) |  | ||||||
| { |  | ||||||
| 	va_list ap; |  | ||||||
| 	va_start (ap, Buffer);	 |  | ||||||
| 	 |  | ||||||
| 	int format_flag; |  | ||||||
| 	char str_buffer[10]; |  | ||||||
| 	char str_null_buffer[10]; |  | ||||||
| 	char move = 0; |  | ||||||
| 	char Base = 0; |  | ||||||
| 	int tmp = 0; |  | ||||||
| 	char by; |  | ||||||
| 	char *ptr; |  | ||||||
| 		 |  | ||||||
| 	//Ausgabe der Zeichen
 |  | ||||||
|     for(;;){ |  | ||||||
| 		by = pgm_read_byte(Buffer++); |  | ||||||
| 		if(by==0) break; // end of format string
 |  | ||||||
|              |  | ||||||
| 		if (by == '%'){ |  | ||||||
|             by = pgm_read_byte(Buffer++); |  | ||||||
| 			if (isdigit(by)>0){                    |  | ||||||
|  				str_null_buffer[0] = by; |  | ||||||
| 				str_null_buffer[1] = '\0'; |  | ||||||
| 				move = atoi(str_null_buffer); |  | ||||||
|                 by = pgm_read_byte(Buffer++); |  | ||||||
| 				} |  | ||||||
| 
 |  | ||||||
| 			switch (by){ |  | ||||||
|                 case 's': |  | ||||||
|                     ptr = va_arg(ap,char *); |  | ||||||
|                     while(*ptr) { lcd_write_char(*ptr++); } |  | ||||||
|                     break; |  | ||||||
| 				case 'b': |  | ||||||
| 					Base = 2; |  | ||||||
| 					goto ConversionLoop; |  | ||||||
| 				case 'c': |  | ||||||
| 					//Int to char
 |  | ||||||
| 					format_flag = va_arg(ap,int); |  | ||||||
| 					lcd_write_char (format_flag++); |  | ||||||
| 					break; |  | ||||||
| 				case 'i': |  | ||||||
| 					Base = 10; |  | ||||||
| 					goto ConversionLoop; |  | ||||||
| 				case 'o': |  | ||||||
| 					Base = 8; |  | ||||||
| 					goto ConversionLoop; |  | ||||||
| 				case 'x': |  | ||||||
| 					Base = 16; |  | ||||||
| 					//****************************
 |  | ||||||
| 					ConversionLoop: |  | ||||||
| 					//****************************
 |  | ||||||
| 					itoa(va_arg(ap,int),str_buffer,Base); |  | ||||||
| 					int b=0; |  | ||||||
| 					while (str_buffer[b++] != 0){}; |  | ||||||
| 					b--; |  | ||||||
| 					if (b<move){ |  | ||||||
| 						move -=b; |  | ||||||
| 						for (tmp = 0;tmp<move;tmp++){ |  | ||||||
| 							str_null_buffer[tmp] = '0'; |  | ||||||
| 							} |  | ||||||
| 						//tmp ++;
 |  | ||||||
| 						str_null_buffer[tmp] = '\0'; |  | ||||||
| 						strcat(str_null_buffer,str_buffer); |  | ||||||
| 						strcpy(str_buffer,str_null_buffer); |  | ||||||
| 						} |  | ||||||
| 					lcd_print_str (str_buffer); |  | ||||||
| 					move =0; |  | ||||||
| 					break; |  | ||||||
| 				} |  | ||||||
| 		}else{ |  | ||||||
| 			lcd_write_char (by);	 |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	va_end(ap); |  | ||||||
| } |  | ||||||
| @ -1,49 +0,0 @@ | |||||||
| /*
 |  | ||||||
|  * lcd.h |  | ||||||
|  * |  | ||||||
|  * Created: 20.01.2018 12:51:11 |  | ||||||
|  *  Author: Ulrich |  | ||||||
|  */  |  | ||||||
| 
 |  | ||||||
| #ifndef __LCD_H__ |  | ||||||
| #define __LCD_H__ |  | ||||||
| 
 |  | ||||||
| #include <inttypes.h> |  | ||||||
| #include <avr/io.h> |  | ||||||
| #include <avr/pgmspace.h> |  | ||||||
| #include <stdlib.h> |  | ||||||
| #include <stdarg.h> |  | ||||||
| #include <ctype.h> |  | ||||||
| #include <string.h> |  | ||||||
| #include <util/delay.h> |  | ||||||
| #include "i2c.h" |  | ||||||
| 
 |  | ||||||
| #define LCD_I2C_ADDR	0x4E |  | ||||||
| 
 |  | ||||||
| //Port Belegung am PCF8574 (1<<PORT)
 |  | ||||||
| #define LCD_RS			(1<<0) |  | ||||||
| #define LCD_RW			(1<<1) |  | ||||||
| #define LCD_E			(1<<2) |  | ||||||
| #define LCD_BACKLIGHT	(1<<3) |  | ||||||
| 
 |  | ||||||
| #define LCD_D4			(1<<4) |  | ||||||
| #define LCD_D5			(1<<5) |  | ||||||
| #define LCD_D6			(1<<6) |  | ||||||
| #define LCD_D7			(1<<7) |  | ||||||
| 
 |  | ||||||
| #define LCD_WIDTH 20 |  | ||||||
| #define LCD_ADDR_LINE1	(0x80) |  | ||||||
| #define LCD_ADDR_LINE2	(0xC0) |  | ||||||
| 
 |  | ||||||
| void lcd_init(void); |  | ||||||
| void lcd_clear(void); |  | ||||||
| void lcd_home(void); |  | ||||||
| void lcd_print_str (char *str); |  | ||||||
| void lcd_write_P (const char *Buffer,...); |  | ||||||
| 
 |  | ||||||
| void lcd_set_position(uint8_t row, uint8_t col); |  | ||||||
| void lcd_cursor(uint8_t en); |  | ||||||
| 
 |  | ||||||
| #define lcd_write(format, args...)   lcd_write_P(PSTR(format) , ## args) |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
| @ -1,145 +0,0 @@ | |||||||
| #include "lcd.h" |  | ||||||
| #include "menu.h" |  | ||||||
| #include <stdio.h> |  | ||||||
| 
 |  | ||||||
| // 0 = nothing selected
 |  | ||||||
| // 1 = change zone 1
 |  | ||||||
| // 2 = change zone 2
 |  | ||||||
| // 3 = change zone 3
 |  | ||||||
| volatile uint8_t menu_state = 0; |  | ||||||
| 
 |  | ||||||
| void write_heater_real_temp(uint8_t n, uint16_t temp){ |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void write_heater_set_temp(uint8_t n, uint16_t temp){ |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void update_cursor(){ |  | ||||||
|     switch(menu_state){ |  | ||||||
|         case 1: |  | ||||||
|             lcd_set_position(0,5); |  | ||||||
|             lcd_cursor(1);  |  | ||||||
|             break; |  | ||||||
|         case 2: |  | ||||||
|             lcd_set_position(0,9); |  | ||||||
|             lcd_cursor(1);  |  | ||||||
|             break; |  | ||||||
|         case 3: |  | ||||||
|             lcd_set_position(0,14); |  | ||||||
|             lcd_cursor(1);  |  | ||||||
|             break; |  | ||||||
|         case 4: |  | ||||||
|             lcd_set_position(2,9); |  | ||||||
|             lcd_cursor(1);  |  | ||||||
|             break; |  | ||||||
|         case 5: |  | ||||||
|             lcd_set_position(3,9); |  | ||||||
|             lcd_cursor(1);  |  | ||||||
|             break; |  | ||||||
|         default: |  | ||||||
|             lcd_cursor(0);  |  | ||||||
|             break; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void draw_menu(){ |  | ||||||
| 	lcd_clear(); |  | ||||||
|     lcd_set_position(0, 0); |  | ||||||
|     lcd_write("s:"); |  | ||||||
|     lcd_set_position(1, 0); |  | ||||||
|     lcd_write("r:"); |  | ||||||
|     lcd_set_position(2, 0); |  | ||||||
|     lcd_write("motor:"); |  | ||||||
|     lcd_set_position(3, 0); |  | ||||||
|     lcd_write("fan  :"); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void write_motor(){ |  | ||||||
|     char str[5]; |  | ||||||
|     str[4] = 0; //null terminated
 |  | ||||||
| 
 |  | ||||||
|     lcd_set_position(2, 7); |  | ||||||
|     sprintf(str, "%3i", OCR2B); |  | ||||||
|     lcd_print_str(str); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void write_temps(){ |  | ||||||
|     char str[5]; |  | ||||||
|     str[4] = 0; //null terminated
 |  | ||||||
| 
 |  | ||||||
|     lcd_set_position(1, 3); |  | ||||||
|     sprintf(str, "%3i", temp_values[0]); |  | ||||||
|     str[3] = 0xDF; |  | ||||||
|     lcd_print_str(str); |  | ||||||
| 
 |  | ||||||
|     lcd_set_position(1, 7); |  | ||||||
|     sprintf(str, "%3i", temp_values[1]); |  | ||||||
|     str[3] = 0xDF; |  | ||||||
|     lcd_print_str(str); |  | ||||||
| 
 |  | ||||||
|     lcd_set_position(1, 12); |  | ||||||
|     sprintf(str, "%3d", temp_values[2]); |  | ||||||
|     str[3] = 0xDF; |  | ||||||
|     lcd_print_str(str); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void write_setpoints(){ |  | ||||||
|     char str[5]; |  | ||||||
|     str[4] = 0; //null terminated
 |  | ||||||
| 
 |  | ||||||
|     lcd_set_position(0, 3); |  | ||||||
|     sprintf(str, "%3i", temp_setpoints[0]); |  | ||||||
|     str[3] = 0xDF; |  | ||||||
|     lcd_print_str(str); |  | ||||||
| 
 |  | ||||||
|     lcd_set_position(0, 7); |  | ||||||
|     sprintf(str, "%3i%%", temp_setpoints[1]); |  | ||||||
|     lcd_print_str(str); |  | ||||||
| 
 |  | ||||||
|     lcd_set_position(0, 12); |  | ||||||
|     sprintf(str, "%3i%%", temp_setpoints[2]); |  | ||||||
|     lcd_print_str(str); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void set_item(uint8_t page_num){ |  | ||||||
|     //if(menu_state=page_num)
 |  | ||||||
|     //    menu_state=0;
 |  | ||||||
|     //else
 |  | ||||||
|     menu_state = page_num; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void enc_init(){ |  | ||||||
|     PORTD |= (1<<6) | (1 << 7); |  | ||||||
|     PCICR |= (1<<PCIE2); |  | ||||||
|     PCMSK2 |= (1<<PCINT23); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| void encoder_isr(){ |  | ||||||
|     //TODO good quadrature reading code
 |  | ||||||
|     if((PIND & (1<<7))){ |  | ||||||
|         if((menu_state >= 1) && (menu_state <= 3)){ |  | ||||||
|             if(PIND & (1<<6)) |  | ||||||
|                 temp_setpoints[menu_state-1]--; |  | ||||||
|             else |  | ||||||
|                 temp_setpoints[menu_state-1]++; |  | ||||||
|         } |  | ||||||
|         if(menu_state == 4){ |  | ||||||
|             if(PIND & (1<<6) && (OCR2B > 0)) |  | ||||||
|                 OCR2B--; |  | ||||||
|             else if(!(PIND & (1<<6)) && (OCR2B < 255)) |  | ||||||
|                 OCR2B++; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     //if(PIND & (1<<7))
 |  | ||||||
|     //    if(PIND & (1<<6)){
 |  | ||||||
|     //        if(temp_setpoints[menu_state] > 0)
 |  | ||||||
|     //    }
 |  | ||||||
|     //    else{
 |  | ||||||
|     //        if(temp_setpoints[menu_state] < 300)
 |  | ||||||
|     //    }
 |  | ||||||
| } |  | ||||||
| @ -1,18 +0,0 @@ | |||||||
| #ifndef _MENU_H_ |  | ||||||
| #include <stdint.h> |  | ||||||
| 
 |  | ||||||
| extern volatile uint8_t menu_state; |  | ||||||
| 
 |  | ||||||
| extern volatile uint16_t temp_values[4]; |  | ||||||
| extern volatile uint16_t temp_setpoints[4]; |  | ||||||
| 
 |  | ||||||
| void write_temps(void); |  | ||||||
| void write_setpoints(void); |  | ||||||
| void write_motor(void); |  | ||||||
| void update_cursor(void); |  | ||||||
| void set_item(uint8_t page_num); |  | ||||||
| void draw_menu(void); |  | ||||||
| void enc_init(void); |  | ||||||
| void encoder_isr(void); |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
| @ -1,7 +0,0 @@ | |||||||
| make program |  | ||||||
| avrdude -c atmelice_isp -p m328p -U hfuse:w:0x99:m  |  | ||||||
| echo "Power cycle now!" |  | ||||||
| read |  | ||||||
| avarice -5 -w -P atmega328p :4242 & |  | ||||||
| read |  | ||||||
| avrdude -c atmelice_isp -p m328p  -U hfuse:w:0xD9:m |  | ||||||
| @ -1,3 +0,0 @@ | |||||||
| avarice -5 -w -P atmega328p :4242 & |  | ||||||
| sleep 2 |  | ||||||
| avrdude -c atmelice_isp -p m328p  -U hfuse:w:0xD9:m |  | ||||||
					Loading…
					
					
				
		Reference in New Issue