Files
pa50contr/relay.c
Олег Бородин 2ccb2b6da2 update
2024-08-21 10:44:56 +02:00

141 lines
2.5 KiB
C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <tool.h>
void button_init(void) {
/* D3 PD3: Set key input */
REG_SETDOWN_BIT(DDRD, PD3);
REG_SETUP_BIT(PORTD, PD3);
}
bool button_is_pressed(void) {
if (REG_BIT_VALUE(PIND, PD3)) {
return true;
}
return false;
}
/* D4 PD4: Set input relay 5 output */
void relaytx_init(void) {
REG_SETUP_BIT(DDRD, PD4);
}
void relaytx_on(void) {
REG_SETUP_BIT(PORTD, PD4);
}
void relaytx_off(void) {
REG_SETDOWN_BIT(PORTD, PD4);
}
void relaytx_onoff(void) {
if (REG_BIT_VALUE(PIND, PD4)) {
relaytx_off();
} else {
relaytx_on();
}
}
/* D6 PD6: Set 10M relay 1 output */
void relay10m_init(void) {
REG_SETUP_BIT(DDRD, PD6);
}
void relay10m_on(void) {
REG_SETUP_BIT(PORTD, PD6);
}
void relay10m_off(void) {
REG_SETDOWN_BIT(PORTD, PD6);
}
/* D7 PD7: Set 20M relay 2 output */
void relay20m_init(void) {
REG_SETUP_BIT(DDRD, PD7);
}
void relay20m_on(void) {
REG_SETUP_BIT(PORTD, PD7);
}
void relay20m_off(void) {
REG_SETDOWN_BIT(PORTD, PD7);
}
/* D8 PB0: Set 40M relay 3 output */
void relay40m_init(void) {
REG_SETUP_BIT(DDRB, PB0);
}
void relay40m_on(void) {
REG_SETUP_BIT(PORTB, PB0);
}
void relay40m_off(void) {
REG_SETDOWN_BIT(PORTB, PB0);
}
/* D9 PB1: Set 80M relay 4 output */
void relay80m_init(void) {
REG_SETUP_BIT(DDRB, PB1);
}
void relay80m_on(void) {
REG_SETUP_BIT(PORTB, PB1);
}
void relay80m_off(void) {
REG_SETDOWN_BIT(PORTB, PB1);
}
/* D10 PB2: Set buzzer output */
void buzzer_init(void) {
REG_SETUP_BIT(DDRB, PB2);
}
void buzzer_on(void) {
REG_SETUP_BIT(PORTB, PB2);
}
void buzzer_off(void) {
REG_SETDOWN_BIT(PORTB, PB2);
}
void buzzer_onoff(void) {
if (REG_BIT_VALUE(PINB, PB2)) {
buzzer_off();
} else {
buzzer_on();
}
}
/* D12 PB4: Set fan output */
void fan_init(void) {
REG_SETUP_BIT(DDRB, PB4);
}
void fan_on(void) {
REG_SETUP_BIT(PORTB, PB4);
}
void fan_off(void) {
REG_SETDOWN_BIT(PORTB, PB4);
}
void fan_onoff(void) {
if (REG_BIT_VALUE(PINB, PB4)) {
fan_off();
} else {
fan_on();
}
}
bool fan_is_on(void) {
if (REG_BIT_VALUE(PINB, PB4)) {
return true;
}
return false;
}
/* D13 PB5: Set attenuator relay output */
void atten_init(void) {
REG_SETUP_BIT(DDRB, PB5);
}
void atten_on(void) {
REG_SETUP_BIT(PORTB, PB5);
}
void atten_off(void) {
REG_SETDOWN_BIT(PORTB, PB5);
}