Tested and working.
This commit is contained in:
parent
6f878791e8
commit
b902b8085c
115
src/main.c
115
src/main.c
|
@ -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;
|
||||
|
||||
while(true){
|
||||
Timer_Start();
|
||||
_delay_ms(250);
|
||||
Timer_Disable();
|
||||
cnt = 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);
|
||||
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;
|
||||
|
||||
/*
|
||||
USART0_sendString(msg);
|
||||
USART0_sendString(maketime_msg);
|
||||
USART0_sendChar('\r');
|
||||
USART0_sendChar('\n');
|
||||
USART0_sendString(breaktime_msg);
|
||||
USART0_sendChar('\r');
|
||||
USART0_sendChar('\n');
|
||||
WaitForRelayConnect();
|
||||
Activate_Relay();
|
||||
WaitForRelayDisconnect();
|
||||
Deactivate_Relay();
|
||||
*/
|
||||
; //Do nothing until new Power cycle/reset occurs
|
||||
|
||||
while(true) {
|
||||
SW1_Wait();
|
||||
Activate_Relay();
|
||||
|
||||
Timer_Start();
|
||||
WaitForRelayConnect();
|
||||
Timer_Disable();
|
||||
|
||||
make_time = Timer_GetOverflowCount();
|
||||
|
||||
SW2_Wait();
|
||||
Deactivate_Relay();
|
||||
|
||||
Timer_Start();
|
||||
WaitForRelayDisconnect();
|
||||
Timer_Disable();
|
||||
|
||||
break_time = Timer_GetOverflowCount();
|
||||
|
||||
USART0_sendString(maketime_msg);
|
||||
USART0_sendChar((uint8_t)(0xFF & make_time));
|
||||
USART0_sendString(breaktime_msg);
|
||||
USART0_sendChar((uint8_t)(0xFF & break_time));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue