Hab mir mal PicNics Vorschlag näher angeschaut..
Über die Typendefinition hab ich automatisch DDR,PIN und PORT? Wenn ja wäre dies ja super.
Könnt ja nochmal über diesen code schauen. Compiliert mit 0 warnings. Noch nicht getestet.Code:typedef struct { uint8_t PIN; uint8_t DDR; uint8_t PORT; } IO_REG; uint8_t outSet(IO_REG* port, uint8_t pin, uint8_t level) { port->DDR |= (1 << pin); //DDR as output if (level) { port->PORT |= (1 << pin); } else { port->PORT &= ~(1 << pin); } return level; } uint8_t inGet(IO_REG* port, uint8_t pin, uint8_t pullup) { port->DDR &= ~(1 << pin); //DDR as input if (pullup) { port->PORT |= (1 << pin); } else { port->PORT &= ~(1 << pin); } if (port->PIN & (1 << pin)) { return 1; } else { return 0; } }
Gruß







Zitieren

Lesezeichen