Changeset - 72e77cc21515
[Not reviewed]
tip default
0 2 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-04-29 20:58:32
ethanzonca@CL-ENS241-08.cedarville.edu
Digital read fixes
2 files changed with 13 insertions and 6 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/sensors.c
Show inline comments
 
@@ -12,49 +12,50 @@
 
#include <avr/interrupt.h>
 
#include "../config.h"
 
#include <util/delay.h>
 
#include "sensors.h"
 
#include "spi.h"
 
#include "i2c.h"
 
 
int16_t	spiTemp;	// Thermocouple Temperature (from spi)
 
int8_t	boardTemp;	// Board Temperature (from i2c)
 
int32_t ut;			// Temperature from BMP085 (from i2c)
 
int32_t up;			// Pressure from BMP085 (from i2c)
 
uint16_t humid;		// Humidity (from i2c)
 
uint8_t lightH;		// Higher byte from light sensor (from i2c)
 
uint8_t lightL;		// Lower byte from light sensor
 
uint8_t exponent;	// Exponent for Lux
 
uint8_t mantissa;	// Mantissa for Lux
 
uint32_t lux;		// Calculated Lux value
 
uint8_t battL;		// Low byte of ADC
 
uint16_t batt;		// Read battery voltage from ADC
 
uint16_t vBatt;		// battery voltage
 
 
int8_t analogL;		// Low byte of ADC
 
int16_t analog[8];		// Read analog voltage from ADC
 
 
uint8_t digital;	// Byte that contains the digital inputs from PORTA
 
uint8_t digitalA;	// Byte that contains the digital inputs from PORTA
 
uint8_t digitalD;	// Byte that contains the digital inputs from PORTD
 
 
int16_t ac1;		// The following 11 variables are the calibration values for the BMP085
 
int16_t ac2;
 
int16_t ac3;
 
uint16_t ac4;
 
uint16_t ac5;
 
uint16_t ac6;
 
int16_t b1;
 
int16_t b2;
 
int16_t mb;
 
int16_t mc;
 
int16_t md;
 
 
int32_t x1;			// The following variables are needed to calculate the true pressure
 
int32_t x2;
 
int32_t x3;
 
int32_t b3;
 
uint32_t b4;
 
int32_t b5;
 
int32_t b6;
 
uint32_t b7;
 
int32_t trueTemp;
 
int32_t pressure;
 
uint32_t altitude;
 
@@ -236,80 +237,85 @@ void sensors_readBatt()
 
 
void sensors_readAnalog(uint8_t pin)
 
{
 
	// Reads analog input on PORTA on the pin (0-7) specified.
 
	
 
	DDRA &= ~(1 << pin);		// Set pin to input
 
	
 
	ADMUX &= 0xF8;
 
	ADMUX |= pin;
 
	
 
	analogL = ADCL;				// Read low battery byte from ADC (all 8 bits)
 
	analog[pin] = ADCH;				// Read high battery byte from ADC (only two LSBs)
 
	
 
	analogL = ADCL;				// Second Read low battery byte from ADC (all 8 bits)
 
	analog[pin] = ADCH;				// Second Read high battery byte from ADC (only two LSBs)
 
	
 
	analog[pin] = analog[pin] << 8;
 
	analog[pin] |= analogL;
 
	analog[pin] = (analog[pin] * 10.0) / 67.4;
 
}
 
 
void sensors_readDigitalPORTA(uint8_t pin)
 
{
 
	DDRA &= ~(1 << pin);		// Set pin to input
 
	digital |= (~(1 << pin)) & PINA;
 
	digitalA |= (~(1 << pin)) & PINA;
 
}
 
 
void sensors_readDigitalPORTD(uint8_t pin)
 
{
 
	if(pin > 3 && pin < 7)
 
	{
 
		DDRD &= ~(1 << pin);		// Set pin to input
 
		digital |= (~(1 << pin)) & PIND;
 
		digitalD |= (~(1 << pin)) & PIND;
 
	}
 
}
 
 
int16_t sensors_getSpiTemp(void)	// Gets spi temperature from variable
 
{
 
	return spiTemp;
 
}
 
 
int8_t sensors_getBoardTemp(void)	// Gets board temperature from variable
 
{
 
	return boardTemp;
 
}
 
 
int32_t sensors_getPressure(void)	// Gets pressure from variable
 
{
 
	return pressure;
 
}
 
 
uint16_t sensors_getHumid(void)			// Gets relative humidity from variable
 
{
 
	return humid;
 
}
 
 
uint32_t sensors_getLux(void)		// Gets light from variable
 
{
 
	return lux;
 
}
 
 
uint16_t sensors_getBatt(void)		// Gets battery voltage from variable
 
{
 
	return vBatt;
 
}
 
 
int16_t sensors_getAnalog(uint8_t pin)		// Gets battery voltage from variable
 
{
 
	return analog[pin];
 
}
 
 
uint8_t sensors_getDigital(uint8_t pin)		// Gets battery voltage from variable
 
uint8_t sensors_getDigitalPORTA(uint8_t pin)		// Gets battery voltage from variable
 
{
 
	return ((digital >> pin) & 1);
 
	return ((digitalA >> pin) & 1);
 
}
 
 
uint8_t sensors_getDigitalPORTD(uint8_t pin)		// Gets battery voltage from variable
 
{
 
	return ((digitalD >> pin) & 1);
 
}
 
 
uint32_t sensors_getAltitude(void)
 
{
 
	return altitude;
 
}
 
\ No newline at end of file
slave/slave/lib/sensors.h
Show inline comments
 
@@ -8,27 +8,28 @@
 
 
#ifndef SENSORS_H_
 
#define SENSORS_H_
 
 
 
void sensors_setupPressure(void);	// Reads pressure calibration values
 
void sensors_readSpiTemp(void);		// Reads spi temperature
 
void sensors_readBoardTemp(void);	// Reads board temperature
 
void sensors_readPressure(void);	// Reads pressure
 
void sensors_readHumid(void);		// Reads humidity
 
void sensors_readLux(void);			// Reads lux
 
void sensors_readBatt(void);		// Reads battery voltage from ADC
 
void sensors_readAnalog(uint8_t pin);	// Reads generic analog voltage from ADC
 
void sensors_readDigitalPORTA(uint8_t pin);	// Read digital pin on PORTA
 
void sensors_readDigitalPORTD(uint8_t pin); // Read digital pin on PORTD
 
 
int16_t sensors_getSpiTemp(void);	// Gets spi temperature from variable
 
int8_t sensors_getBoardTemp(void);	// Gets board temperature from variable
 
int32_t sensors_getPressure(void);	// Gets pressure from variable
 
uint16_t sensors_getHumid(void);	// Gets humidity from variable
 
uint32_t sensors_getLux(void);		// Gets lux from variable
 
uint16_t sensors_getBatt(void);		// Gets battery voltage from variable
 
uint32_t sensors_getAltitude(void);	// Gets altitude from variable
 
int16_t sensors_getAnalog(uint8_t pin);		// Gets battery voltage from variable
 
uint8_t sensors_getDigital(uint8_t pin);		// Gets battery voltage from variable
 
uint8_t sensors_getDigitalPORTA(uint8_t pin);		// Gets battery voltage from variable
 
uint8_t sensors_getDigitalPORTD(uint8_t pin);
 
 
#endif /* SENSORS_H_ */
 
\ No newline at end of file
0 comments (0 inline, 0 general)