#include #include #include #include #include "defines.h" #include "uart/uart.h" #define SETPIN(port, pins) port |= pins #define UNSETPIN(port, pins) port &= ~pins typedef enum { RELAIS_1, RELAIS_2, RELAIS_3, RELAIS_4, RELAIS_5, NOF_RELAIS } Relais_te; typedef struct { const uint8_t pin; bool state_b; } Relais_ts; static Relais_ts relais_as[NOF_RELAIS] = { [RELAIS_1] = { .pin = (1 << PINB1), .state_b = false }, [RELAIS_2] = { .pin = (1 << PINB2), .state_b = false }, [RELAIS_3] = { .pin = (1 << PINB3), .state_b = false }, [RELAIS_4] = { .pin = (1 << PINB4), .state_b = false }, [RELAIS_5] = { .pin = (1 << PINB5), .state_b = false } }; static void relaisInit_v(void); static void relaisInit_v(void) { char c; uint8_t relais_e = RELAIS_5; for (uint8_t relais_e=0; relais_epin == 0) { c = 0 + '0'; } else { c = 1 + '0'; } //c = relais_ps->pin + '0'; uart_characterPut(c); SETPIN(PORTB, relais_ps->pin); relais_ps->state_b = false; } } //static bool relaisSwitch_b(const Relais_te relais_e, const uint8_t state_u8); //static bool relaisSwitch_b(const Relais_te relais_e, const uint8_t state_u8) //{ // uint8_t retVal_u8 = 0u; // Relais_ts* relais_ps = &relais_as[relais_e]; // // if (0u == state_u8) // { // UNSETPIN(PORTB, relais_ps->pin); // relais_ps->state_b = false; // } // else if (1u == state_u8) // { // SETPIN(PORTB, relais_ps->pin); // relais_ps->state_b = true; // } // else // { // } // // retVal_u8 = relais_ps->state_b; // // return retVal_u8; // return true; //} int main(void) { DDRB |= (1 << PINB1); DDRB |= (1 << PINB2); DDRB |= (1 << PINB3); DDRB |= (1 << PINB4); DDRB |= (1 << PINB5); PORTB &= ~(1 << PINB1); PORTB &= ~(1 << PINB2); PORTB &= ~(1 << PINB3); PORTB &= ~(1 << PINB4); PORTB &= ~(1 << PINB5); char data[16]; char cArr[4] = {'0', '0', '0', '0'}; uint8_t strLen_u8 = 0; uart_init(MYUBRR); uart_flush(); relaisInit_v(); while(1) { strLen_u8 = uart_stringGet(&data[0], 16); if (strLen_u8 > 0) { for (uint8_t x=0; x