- use switch for leaving error mode - use Uart with message fifo - fixed portGet, added PwrSwitch_in git-svn-id: http://moon:8086/svn/projects/HendiControl@33 fda53097-d464-4ada-af97-ba876c37ca34
57 lines
921 B
C
57 lines
921 B
C
/*
|
|
* port.c
|
|
*
|
|
* Created: 20.02.2019 20:54:33
|
|
* Author: jens
|
|
*/
|
|
|
|
#include <avr/io.h>
|
|
#include "port.h"
|
|
|
|
void port_init()
|
|
{
|
|
DDRB = 0x03;
|
|
DDRC = 0x01;
|
|
PORTB = 0x03;
|
|
PORTC = 0x01;
|
|
|
|
}
|
|
|
|
typedef struct _sPort_t
|
|
{
|
|
uint8_t port;
|
|
uint8_t pin;
|
|
uint8_t pol;
|
|
} Port_t;
|
|
|
|
const Port_t portItems[NUM_ITEMS] =
|
|
{
|
|
{0x05, 0, 1},
|
|
{0x05, 1, 1},
|
|
{0x05, 2, 1},
|
|
{0x08, 0, 1},
|
|
{0x06, 1, 1},
|
|
};
|
|
|
|
void portSet(int portItem, int enable)
|
|
{
|
|
uint8_t addr = portItems[portItem].port;
|
|
uint8_t pin_mask = 1 << portItems[portItem].pin;
|
|
|
|
if (enable ^ portItems[portItem].pol)
|
|
{
|
|
_SFR_IO8(addr) |= pin_mask;
|
|
}
|
|
else
|
|
{
|
|
_SFR_IO8(addr) &= ~pin_mask;
|
|
}
|
|
}
|
|
|
|
int portGet(int portItem)
|
|
{
|
|
uint8_t addr = portItems[portItem].port;
|
|
uint8_t pin_mask = 1 << portItems[portItem].pin;
|
|
int enable = (_SFR_IO8(addr) & pin_mask) != pin_mask;
|
|
return enable ^ portItems[portItem].pol;
|
|
} |