Tested and working.

This commit is contained in:
jakeg00dwin 2024-08-05 16:40:04 -07:00
parent 6f878791e8
commit b902b8085c
1 changed files with 75 additions and 40 deletions

View File

@ -23,65 +23,100 @@
#include <avr/io.h>
#include <util/delay.h>
#define SW1PIN (1<<5)
#define SW2PIN (1<<4)
#define RELAYPIN (1<<1)
#define RELAYREADINGPIN (1<<7) //It would be better to use PA7 so USART worked
//char msg[] = "Attiny404:\n\r";
char maketime_msg[] = "\r\nMake Time(10Khz):";
char hi_msg[] = " Hi byte: ";
char lo_msg[] = " Lo byte: ";
char overflow_count_msg[] = " Overflows: ";
//char breaktime_msg[] = "Break Time(10Khz):";
char hex_msg[3];
char breaktime_msg[] = "\r\nBreak Time(10Khz):";
//Set the function pointer for the delay func
void (*Delay_MicroSeconds)(double us) = _delay_us;
void delay_period()
void SW1_Wait(void)
{
Timer_Enable();
Timer_BlockingWait();
Timer_Disable();
//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(!(PORTA.IN & RELAYREADINGPIN)){;}
}
void WaitForRelayDisconnect(void)
{
while(PORTA.IN & RELAYREADINGPIN){;}
}
int main(int argc, char **argv)
{
USART0_Init();
//Timer_SelectClock();
//Timer_Period();
PORTA.DIR |= (1<<7);
uint16_t cnt = 0;
uint8_t hi, lo;
PORTA.DIR |= RELAYPIN;
PORTA.DIR &= ~RELAYREADINGPIN;
PORTA.DIR &= ~SW1PIN;
PORTA.DIR &= ~SW2PIN;
//PORTA.OUT |= RELAYPIN;
//uint16_t cnt = 0;
//uint8_t hi, lo;
uint16_t make_time = 0;
uint16_t break_time = 0;
/*
WaitForRelayConnect();
Activate_Relay();
WaitForRelayDisconnect();
Deactivate_Relay();
*/
while(true) {
SW1_Wait();
Activate_Relay();
while(true){
Timer_Start();
_delay_ms(250);
WaitForRelayConnect();
Timer_Disable();
cnt = Timer_GetOverflowCount();
make_time = Timer_GetOverflowCount();
SW2_Wait();
Deactivate_Relay();
Timer_Start();
WaitForRelayDisconnect();
Timer_Disable();
break_time = Timer_GetOverflowCount();
USART0_sendString(maketime_msg);
hi = (uint8_t)(cnt >> 8);
lo = (uint8_t) (cnt & 0x00FF);
USART0_sendString(hi_msg);
USART0_sendChar(hi);
//USART0_sendString(hex_msg);
USART0_sendString(lo_msg);
USART0_sendChar(lo);
/*
USART0_sendString(msg);
USART0_sendString(maketime_msg);
USART0_sendChar('\r');
USART0_sendChar('\n');
USART0_sendChar((uint8_t)(0xFF & make_time));
USART0_sendString(breaktime_msg);
USART0_sendChar('\r');
USART0_sendChar('\n');
*/
; //Do nothing until new Power cycle/reset occurs
USART0_sendChar((uint8_t)(0xFF & break_time));
}
}