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