Files
@ e9fb1e1bfee0
Branch filter:
Location: seniordesign-firmware/slave/slave/lib/inputOutput.c
e9fb1e1bfee0
2.9 KiB
text/plain
Camera functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | /*
* io.c
*
* Created: 11/7/2012 7:17:52 PM
* Author: kripperger
*/
#include <avr/io.h>
#include "../config.h"
#include "inputOutput.h"
#include "led.h"
#include "sensors.h"
int8_t moduleID; // Slave Module ID from rotary dip switch (or EEPROM)
void io_configure()
{
// Configure ports/pins
DDRB |= (1 << DDB4); // Set PB4 to Output for Heater (also allows SCK (on SPI bus) to operate)
DDRC &= ~(1 << DDC2); // Set PC2 to input for rotary dip
DDRC &= ~(1 << DDC3); // Set PC3 to input for rotary dip
DDRC &= ~(1 << DDC4); // Set PC4 to input for rotary dip
DDRC &= ~(1 << DDC5); // Set PC5 to input for rotary dip
DDRA &= ~(1 << DDA7); // Set PA7 to input for battery voltage divider
//ADC register configurations for battery level detection on PA7
ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); // Set prescaler for ADC, 128 gives ADC freq of 125 KHz
ADMUX |= (1 << REFS0); // Set ADC reference voltage to AVCC
//ADMUX |= (1 << ADLAR); // Sets 10 bit ADC to 8 bit
ADMUX |= (1 << MUX2) | (1 << MUX1) | (1 << MUX0); // Select ADC7 as the conversion channel
ADCSRA |= (1 << ADATE); // Enables auto trigger, determined in ADCSRB bits ADTS
//ADCSRA |= (1 << ADIF); //
//ADCSRA |= (1 << ADIE); // ADC interrupt enable set
ADCSRB &= ~((1 << ADTS2) | (1 << ADTS1) | (1 << ADTS0));// Set ADC auto trigger source to free running mode
ADCSRA |= (1 << ADEN); // Enable ADC
ADCSRA |= (1 << ADSC); // Start ADC measurements. ADC should now continuously run conversions, which are stored in ADCH 0x79
}
void io_readModuleId()
{
// Get ID from rotary dip and return it.
moduleID = 0;
/*
// This method is temporary as the next release will read the module ID from EEPROM
PORTC |= (1 << PC2); // Pull pins on rotary dip high
PORTC |= (1 << PC3); // Pull pins on rotary dip high
PORTC |= (1 << PC4); // Pull pins on rotary dip high
PORTC |= (1 << PC5); // Pull pins on rotary dip high
moduleID = ((PINC & 0b00011100) >> 2); // Read Dip Encoder
moduleID = ~moduleID; //Invert Dip reading
moduleID = (moduleID & 0b0111); //Mask bits
*/
while(moduleID==0) //UNCOMMENT ALL THIS
{
moduleID = i2c_read(EEPROM_ADDR, 0x05);
}
}
uint8_t io_getModuleId()
{
return moduleID;
}
void io_heaterOn()
{
PORTB |= (1 << PB4); //ON
}
void io_heaterOff()
{
PORTB &= ~(1 << PB4); //OFF
}
uint8_t io_heaterStatus()
{
uint8_t state;
state = 0;
state = ((PORTB & 0b00010000) >> 4);
return state;
}
void io_regulateTemp()
{
// Gets board temperature and enables heater if below threshold
if (sensors_getBoardTemp() <= HEATER_THRESHOLD)
{
io_heaterOn();
led_on(3);
}
else if (sensors_getBoardTemp() > (HEATER_THRESHOLD + 5))
{
io_heaterOff();
led_off(3);
}
}
|