I changed it to use the new updated interface that I wrote for the LedController module.
115 lines
2.4 KiB
C
115 lines
2.4 KiB
C
/**
|
|
* @file main.c
|
|
* @author Jake G
|
|
* @date 15 June 2024
|
|
* @brief File contains the main function.
|
|
*
|
|
* This file contains the main logic loop and exists to setup the values
|
|
* specific to the micro-controller. All other functions and configuration are
|
|
* extracted into separate source files and headers for configuration.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#define F_CPU 3333333UL
|
|
|
|
// This can prevent issues with utils/delay.h library with the gcc toolchain
|
|
#define __DELAY_BACKWARD_COMPATIBLE__
|
|
|
|
#include "LedController.h"
|
|
#include "RegEdit.h"
|
|
#include "config.h"
|
|
#include "timer.h"
|
|
#include <avr/cpufunc.h> /* Required header file */
|
|
#include <avr/io.h>
|
|
#include <util/delay.h>
|
|
|
|
#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
|
|
|
|
// Set the function pointer for the delay func
|
|
void (*Delay_MicroSeconds)(double us) = _delay_us;
|
|
|
|
void SW1_Wait(void)
|
|
{
|
|
// poll the input.
|
|
while (PORTA.IN & SW1PIN) {}
|
|
}
|
|
|
|
void SW2_Wait(void)
|
|
{
|
|
// poll the input.
|
|
while (PORTA.IN & SW2PIN) {}
|
|
}
|
|
|
|
void Activate_Relay(void)
|
|
{
|
|
PORTA.OUT |= RELAYPIN;
|
|
}
|
|
|
|
void Deactivate_Relay(void)
|
|
{
|
|
PORTA.OUT &= ~RELAYPIN;
|
|
}
|
|
|
|
void WaitForRelayConnect(void)
|
|
{
|
|
while (!(PORTB.IN & RELAYREADINGPIN))
|
|
{
|
|
;
|
|
}
|
|
}
|
|
|
|
void WaitForRelayDisconnect(void)
|
|
{
|
|
while (PORTB.IN & RELAYREADINGPIN)
|
|
{
|
|
;
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
PORTA.DIR |= RELAYPIN;
|
|
PORTB.DIR &= ~RELAYREADINGPIN;
|
|
PORTA.DIR &= ~SW1PIN;
|
|
PORTA.DIR &= ~SW2PIN;
|
|
|
|
uint16_t make_time = 0;
|
|
uint16_t break_time = 0;
|
|
uint8_t temp = 0;
|
|
|
|
LedByte led_byte = LedController_New(&PORTA.OUT);
|
|
|
|
while (true)
|
|
{
|
|
SW1_Wait();
|
|
Activate_Relay();
|
|
|
|
Timer_Start();
|
|
WaitForRelayConnect();
|
|
Timer_Disable();
|
|
|
|
make_time = Timer_GetOverflowCount();
|
|
|
|
// Output the Make time via LEDS
|
|
temp = (uint8_t)(make_time & 0x0F);
|
|
LedController_ShowByte(&led_byte, temp);
|
|
|
|
SW2_Wait();
|
|
Deactivate_Relay();
|
|
|
|
Timer_Start();
|
|
WaitForRelayDisconnect();
|
|
Timer_Disable();
|
|
|
|
break_time = Timer_GetOverflowCount();
|
|
|
|
// Output the Break time via LEDS
|
|
temp = (uint8_t)(break_time & 0x0F);
|
|
LedController_ShowByte(&led_byte, temp);
|
|
|
|
|
|
}
|
|
}
|