You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
2.0 KiB
C
132 lines
2.0 KiB
C
7 years ago
|
#include "hw.h"
|
||
|
#include <avr/io.h>
|
||
|
#include <avr/interrupt.h>
|
||
|
#include <avr/eeprom.h>
|
||
|
#include "hbw.h"
|
||
|
|
||
|
uint8_t relais1state;
|
||
|
uint8_t relais2state;
|
||
|
uint8_t pc0state;
|
||
|
uint8_t pc1state;
|
||
|
|
||
|
void hbw_read_config(void)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
uint8_t hbw_get_channel(uint8_t channel, uint8_t data[])
|
||
|
{
|
||
|
if (channel == 0) {
|
||
|
if (bit_is_clear(PINB, Relais1))
|
||
|
data[0] = 0;
|
||
|
else
|
||
|
data[0] = 200;
|
||
|
return 1;
|
||
|
}
|
||
|
if (channel == 1) {
|
||
|
if (bit_is_clear(PINB, Relais2))
|
||
|
data[0] = 200;
|
||
|
else
|
||
|
data[0] = 0;
|
||
|
return 1;
|
||
|
}
|
||
|
if (channel == 2) {
|
||
|
if (bit_is_clear(PINC, PC0))
|
||
|
data[0] = 200;
|
||
|
else
|
||
|
data[0] = 0;
|
||
|
return 1;
|
||
|
}
|
||
|
if (channel == 3) {
|
||
|
if (bit_is_clear(PINC, PC1))
|
||
|
data[0] = 200;
|
||
|
else
|
||
|
data[0] = 0;
|
||
|
return 1;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void hbw_set_channel(uint8_t channel, uint8_t len, uint8_t data[])
|
||
|
{
|
||
|
if (channel == 0) {
|
||
|
if (data[0])
|
||
|
PORTB |= (1<<Relais1);
|
||
|
else
|
||
|
PORTB &= ~(1<<Relais1);
|
||
|
}
|
||
|
if (channel == 1) {
|
||
|
if (data[0])
|
||
|
PORTB |= (1<<Relais2);
|
||
|
else
|
||
|
PORTB &= ~(1<<Relais2);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void hbw_receive_key(uint8_t channel, uint8_t count, uint8_t flag)
|
||
|
{
|
||
|
if(channel == 0)
|
||
|
PORTB ^= (1<<Relais1);
|
||
|
if(channel == 1)
|
||
|
PORTB ^= (1<<Relais2);
|
||
|
}
|
||
|
|
||
|
int main(void)
|
||
|
{
|
||
|
uint8_t state;
|
||
|
|
||
|
DDRB |= (1<<Relais1);
|
||
|
DDRB |= (1<<Relais2);
|
||
|
|
||
|
DDRC &= ~(1<<PC0);
|
||
|
DDRC &= ~(1<<PC1);
|
||
|
|
||
|
PORTB &= ~(1<<Relais1);
|
||
|
PORTB &= ~(1<<Relais2);
|
||
|
|
||
|
PORTC |= (1<<PC0);
|
||
|
PORTC |= (1<<PC1);
|
||
|
|
||
|
relais1state = 0;
|
||
|
relais2state = 0;
|
||
|
pc0state = 0;
|
||
|
pc1state = 0;
|
||
|
|
||
|
hbw_init();
|
||
|
|
||
|
while(1) {
|
||
|
hbw_loop();
|
||
|
|
||
|
if (bit_is_clear(PINC, PC0) && (!pc0state)) {
|
||
|
state = 200;
|
||
|
|
||
|
if (hbw_send_channel(2, 1, &state)) {
|
||
|
pc0state = ~0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (bit_is_set(PINC, PC0) && pc0state) {
|
||
|
state = 0;
|
||
|
|
||
|
if (hbw_send_channel(2, 1, &state)) {
|
||
|
pc0state = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (bit_is_clear(PINC, PC1) && (!pc1state)) {
|
||
|
state = 200;
|
||
|
|
||
|
if (hbw_send_channel(3, 1, &state)) {
|
||
|
pc1state = ~0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (bit_is_set(PINC, PC1) && pc1state) {
|
||
|
state = 0;
|
||
|
|
||
|
if (hbw_send_channel(3, 1, &state)) {
|
||
|
pc1state = 0;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|