Fixed indentation
This commit is contained in:
parent
9f20dee3ab
commit
e847304d23
46
lab_3/main.c
46
lab_3/main.c
@ -25,21 +25,21 @@ void pin_init() {
|
||||
}
|
||||
|
||||
/** @brief Initializes ADC with required settings
|
||||
*/
|
||||
*/
|
||||
void adc_init() {
|
||||
/* ADC Settings
|
||||
* Use AVcc as Vref
|
||||
* Use 1v1 reference as Vref
|
||||
* Initially set input as GND
|
||||
* Data right-adjusted
|
||||
* No Interrupts
|
||||
*/
|
||||
// Set Vref
|
||||
ADMUX |= (1 << REFS1) | (1 << REFS0);
|
||||
// Set Vref
|
||||
ADMUX |= (1 << REFS1) | (1 << REFS0);
|
||||
// Set the clock prescaler to 128 (slower ADC means more accurate measurements)
|
||||
ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
|
||||
|
||||
// Enable ADC
|
||||
ADCSRA |= (1 << ADEN);
|
||||
|
||||
// Enable ADC
|
||||
ADCSRA |= (1 << ADEN);
|
||||
}
|
||||
|
||||
/** @brief Blocking function to read an ADC conversion from a selected ADC input.
|
||||
@ -83,16 +83,16 @@ int8_t lm35_convert(uint16_t adc_reading) {
|
||||
* @return Measured temperature, configure parameters in main.h
|
||||
*/
|
||||
int8_t diode_convert(uint16_t adc_reading) {
|
||||
int16_t value_diff = adc_reading - DIODE_VALUE_25C;
|
||||
int16_t temp_diff = value_diff / DIODE_SENSITIVITY;
|
||||
int16_t value_diff = adc_reading - DIODE_VALUE_25C;
|
||||
int16_t temp_diff = value_diff / DIODE_SENSITIVITY;
|
||||
return temp_diff + 25;
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Initialise display
|
||||
// NOTE: LCD uses PB0-PB6
|
||||
lcd_init(LCD_DISP_ON);
|
||||
|
||||
// Initialise display
|
||||
// NOTE: LCD uses PB0-PB6
|
||||
lcd_init(LCD_DISP_ON);
|
||||
|
||||
// Initialise peripherals
|
||||
pin_init();
|
||||
adc_init();
|
||||
@ -100,31 +100,31 @@ int main() {
|
||||
|
||||
|
||||
while (1) {
|
||||
// Reset position
|
||||
lcd_gotoxy(0, 0);
|
||||
|
||||
// Reset position
|
||||
lcd_gotoxy(0, 0);
|
||||
|
||||
// Read LM35 value, and write to LCD
|
||||
uint16_t lm35_value = adc_run_conversion(1);
|
||||
uint16_t lm35_value = adc_run_conversion(1);
|
||||
int8_t lm35_temp = lm35_convert(lm35_value);
|
||||
// Convert measured value to string
|
||||
sprintf(lm35_string, "LM35 : %4d %3dC", lm35_value, lm35_temp);
|
||||
|
||||
// Display temp on LCD
|
||||
lcd_puts((const char*) lm35_string);
|
||||
|
||||
lcd_gotoxy(0, 1);
|
||||
|
||||
lcd_gotoxy(0, 1);
|
||||
|
||||
|
||||
// Read diode value, and write to
|
||||
uint16_t diode_value = adc_run_conversion(0);
|
||||
int8_t diode_temp = diode_convert(diode_value);
|
||||
int8_t diode_temp = diode_convert(diode_value);
|
||||
sprintf(diode_string, "Diode: %4d %3dC", diode_value, diode_temp);
|
||||
|
||||
// Display diode info on LCD
|
||||
lcd_puts((const char*) diode_string);
|
||||
|
||||
|
||||
// Refreshing too fast can make the data appear weird
|
||||
_delay_ms(500);
|
||||
_delay_ms(500);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -7,15 +7,12 @@
|
||||
#include <stdio.h>
|
||||
#include "lcd.h"
|
||||
|
||||
// Comment out to run in "normal" mode
|
||||
#define CALIBRATION
|
||||
|
||||
#define ADC_VREF 1.1
|
||||
#define ADC_RESOLUTION 1023 // (2^ 10 - 1, 10 bits resolution)
|
||||
|
||||
#define DIODE_VALUE_25C 436 // ADC value for diode at 0C
|
||||
#define DIODE_SENSITIVITY -1.85 // ADC value / degree C, tuneable
|
||||
#define DIODE_VALUE_25C 440 // ADC value for diode at 0C
|
||||
#define DIODE_SENSITIVITY -1.66 // ADC value / degree C, tuneable
|
||||
|
||||
#define LM35_SENSITIVITY 0.01 // V / degree C, see LM35 datasheet
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user