Setup code to run.

This commit is contained in:
jakeg00dwin 2024-08-26 09:46:22 -07:00
parent 318c0a289f
commit bd85f08a2a
3 changed files with 52 additions and 12 deletions

View File

@ -12,14 +12,9 @@
#include "LedController.h"
#include "avr/io.h"
#define PA_B1 (1 << 2)
#define PA_B2 (1 << 3)
#define PA_B3 (1 << 6)
#define PA_B4 (1 << 7)
#define LED_BM_PORTA (1 << 6)|(1 << 1)|(1 << 2)|(1 << 3)
#define LED_BM_PORTB (1 << 3)|(1 << 2)|(1 << 0)|(1 << 1)
#define BITS_IN_BYTE (1 << 2) | (1 << 3) | (1 << 6) | (1 << 7)
#define HALF_BYTE_BM
LedByte LedController_New(uint8_t *port)
{

View File

@ -18,7 +18,7 @@
*/
typedef struct Led
{
uint8_t *port;
volatile uint8_t *port;
uint8_t pin_num;
bool state;
} Led;
@ -28,6 +28,7 @@ typedef struct LedByte
Led leds[8];
} LedByte;
/**
* Returns a instance of the LedByte structure.
*/

View File

@ -25,8 +25,11 @@
#define SW1PIN (1 << 5)
#define SW2PIN (1 << 4)
#define RELAYPIN (1 << 1)
#define RELAYREADINGPIN (1 << 2) // It would be better to use PA7 so USART worked
#define RELAYPIN (1 << 7)
#define RELAYREADINGPIN (1 << 0) // It would be better to use PA7 so USART worked
#define LED_BM_PORTA (1 << 6)|(1 << 1)|(1 << 2)|(1 << 3)
#define LED_BM_PORTB (1 << 3)|(1 << 2)|(1 << 0)|(1 << 1)
// Set the function pointer for the delay func
void (*Delay_MicroSeconds)(double us) = _delay_us;
@ -69,6 +72,44 @@ void WaitForRelayDisconnect(void)
}
}
void LedSetup(LedByte *led_byte)
{
PORTA.DIR |= LED_BM_PORTA;
PORTB.DIR |= LED_BM_PORTB;
//pin 13, bit 0, PA3
led_byte->leds[0].port = (void *) &PORTA.OUT;
led_byte->leds[0].pin_num = 3;
//pin 12, bit 1, PA2
led_byte->leds[1].port = &PORTA.OUT;
led_byte->leds[1].pin_num = 2;
//pin 11, bit 2, PA1
led_byte->leds[2].port = &PORTA.OUT;
led_byte->leds[2].pin_num = 1;
//pin 9, bit 3, PB0
led_byte->leds[3].port = &PORTB.OUT;
led_byte->leds[3].pin_num = 0;
//pin 8, bit 4, PB1
led_byte->leds[4].port = &PORTB.OUT;
led_byte->leds[4].pin_num = 1;
//pin 2, bit 5, PB2
led_byte->leds[5].port = &PORTB.OUT;
led_byte->leds[5].pin_num = 2;
//pin 3, bit 6, PB3
led_byte->leds[6].port = &PORTB.OUT;
led_byte->leds[6].pin_num = 3;
//pin 3, bit 7, PA6
led_byte->leds[7].port = &PORTA.OUT;
led_byte->leds[7].pin_num = 6;
}
int main(int argc, char **argv)
{
PORTA.DIR |= RELAYPIN;
@ -81,6 +122,9 @@ int main(int argc, char **argv)
uint8_t temp = 0;
LedByte led_byte = LedController_New(&PORTA.OUT);
LedSetup(&led_byte);
//wait for a second then disable UPDI
while (true)
{
@ -94,7 +138,7 @@ int main(int argc, char **argv)
make_time = Timer_GetOverflowCount();
// Output the Make time via LEDS
temp = (uint8_t)(make_time & 0x0F);
temp = (uint8_t)(make_time & 0xFF);
LedController_ShowByte(&led_byte, temp);
SW2_Wait();
@ -107,7 +151,7 @@ int main(int argc, char **argv)
break_time = Timer_GetOverflowCount();
// Output the Break time via LEDS
temp = (uint8_t)(break_time & 0x0F);
temp = (uint8_t)(break_time & 0xFF);
LedController_ShowByte(&led_byte, temp);