Changeset - 6314aa4c9143
[Not reviewed]
default
0 3 0
ethanzonca@CL-SEC241-08.cedarville.edu - 12 years ago 2012-12-04 12:09:39
ethanzonca@CL-SEC241-08.cedarville.edu
Updated LED library to support multiple ports. Currently has operation issues likely due to 100% SRAM usage.
3 files changed with 58 insertions and 22 deletions:
0 comments (0 inline, 0 general)
master/master/lib/led.c
Show inline comments
 
@@ -12,44 +12,44 @@
 
 
#include "../config.h"
 
#include <avr/io.h>
 
#include <util/delay.h>
 
#include "led.h"
 
 
 
void led_setup() 
 
{
 
	// Configure ports/pins for LEDs
 
	DDRA = 0xff;
 
	//PORTA = 0x00;
 
	for(int i=0; i<NUM_LEDS; i++)  {
 
		*(ledList[i].direction) |= (1<<ledList[i].pin); // set pin to output
 
		*(ledList[i].port) &= ~(1<<ledList[i].pin); // set pin low
 
}
 
 
}
 
 
// Turn the specified LED on
 
void led_on(uint8_t led) 
 
{
 
	// Turn the specified LED on
 
	PORTA |= (1<<led);
 
	*(ledList[led].port) |= (1<<ledList[led].pin);
 
}
 
 
	// Turn the specified LED off
 
void led_off(uint8_t led) 
 
{
 
	// Turn the specified LED off
 
	PORTA &= ~(1<<led);
 
	*(ledList[led].direction) &= ~(1<<ledList[led].pin);
 
}
 
 
void led_toggle(uint8_t led) 
 
{
 
	// Toggle the specified LED 
 
}
 
 
 
// Flashes error LED a set amount of times, then leaves it on
 
void led_errorcode(uint8_t code) 
 
{
 
	_delay_ms(400);
 
	for(int i=0; i<code; i++) 
 
	{
 
		led_on(ERROR);
 
		led_on(LED_ERROR);
 
		_delay_ms(150);
 
		led_off(ERROR);
 
		led_off(LED_ERROR);
 
		_delay_ms(150);
 
	}
 
	_delay_ms(400);
 
	led_on(ERROR);
 
	led_on(LED_ERROR);
 
}
 
\ No newline at end of file
master/master/lib/led.h
Show inline comments
 
@@ -11,18 +11,54 @@
 
 */
 
 
 
#ifndef LED_H_
 
#define LED_H_
 
 
#define POWER PB2
 
#define ERROR PB1
 
#define STAT PB0
 
#define OK 2
 
#include <avr/io.h>
 
 
enum leds {
 
	LED_ACT0 = 0,
 
	LED_ACT1,
 
	LED_ACT2,
 
	LED_ACT3,
 
	
 
	LED_POWER,
 
	LED_STATUS,
 
	LED_ERROR,
 
	LED_SIDEBOARD,
 
	LED_ACTIVITY,
 
	LED_CYCLE
 
};
 
 
typedef struct {uint8_t* direction; uint8_t* port; uint8_t pin;} led_t;
 
 
// Match order of leds enum
 
static led_t ledList[] = {
 
	{&DDRA, &PORTA, PA4}, // ACT0
 
	{&DDRA, &PORTA, PA5}, // ACT1
 
	{&DDRA, &PORTA, PA6}, // ACT2
 
	{&DDRA, &PORTA, PA7}, // ACT3
 
 
//pcb:
 
//	{&DDRB, &PORTB, PB4}, // POWER
 
//	{&DDRB, &PORTB, PB3}, // STATUS
 
//	{&DDRB, &PORTB, PB2}, // ERROR
 
 
//breadboard:
 
	{&DDRA, &PORTA, PA2}, // POWER
 
	{&DDRA, &PORTA, PA0}, // STATUS
 
	{&DDRA, &PORTA, PA1}, // ERROR
 
 
	{&DDRD, &PORTD, PD6}, // SIDEBOARD
 
	{&DDRD, &PORTD, PD5}, // ACTIVITY
 
	{&DDRD, &PORTD, PD4}, // CYCLE
 
};
 
 
#define NUM_LEDS 10
 
 
void led_setup();
 
void led_on(uint8_t led);
 
void led_off(uint8_t led);
 
void led_toggle(uint8_t led);
 
void led_errorcode(uint8_t code);
 
 
#endif /* LED_H_ */
master/master/master.c
Show inline comments
 
@@ -58,13 +58,13 @@ int main(void)
 

	
 
	//serial0_sendString("\r\n\r\n---------------------------------\r\n");
 
	//serial0_sendString("HAB Controller 1.0 - Initialized!\r\n");
 
	//serial0_sendString("---------------------------------\r\n\r\n");
 
	//serial0_sendString("\f\r\n\r\Hello.\r\n\r\n");
 
	
 
	led_on(POWER);
 
	led_on(LED_POWER);
 
	
 
	// Buffer for string operations
 
	char logbuf[16];
 
	
 
	// Software timers	
 
	uint32_t lastAprsBroadcast = 0;
 
@@ -78,16 +78,16 @@ int main(void)
 
	
 
	while(1)
 
    {
 
		// Periodic: Logging
 
		if(time_millis() - lastLog > LOGGER_RATE) 
 
		{
 
			led_on(STAT);
 
			led_on(LED_STATUS);
 
			snprintf(logbuf, 16, "%lu,%d,\r\n", time_millis(), sensordata_get(HUMIDITY));
 
			logger_log(logbuf);
 
			led_off(STAT);
 
			led_off(LED_STATUS);
 
			lastLog = time_millis();
 
		}		
 
		
 
		// Periodic: APRS transmission
 
		if(time_millis() - lastAprsBroadcast > APRS_TRANSMIT_PERIOD) 
 
		{
0 comments (0 inline, 0 general)