/* * Pin.h * * Created: 2/20/2016 11:49:05 AM * Author: MQUEZADA * * Not the fastest way to access and control the * IO registers of the AVR but a good balance between * using direct port manipulations and readability * for those of us getting started with AVR programming. * * @copyrigt Licensed for non-commercial use under the Beerware license. * If you use this code and we meet some day, you buy me a beer :). * You must include this license message in your implementation of this * code. Feel free to hack away at it, but give me credit for my work :). */ #include #ifndef PIN_H_ #define PIN_H_ #ifndef LOW #define LOW 0x00 #endif #ifndef HIGH #define HIGH 0xFF #endif class Pin { public: Pin(volatile uint8_t *ddr, volatile uint8_t *port, volatile uint8_t *in, uint8_t pin) : DDR(ddr), Port(port), Pinp(in), Nip(pin) {} void SetOutput() const { *DDR |= _BV(Nip); } void SetInput() const { *DDR &= ~(_BV(Nip)); } void Set(uint8_t hl) { (hl != 0x00) ? *Port |= _BV(Nip) : *Port &= ~(_BV(Nip)); } void Pullup(uint8_t hl) { Set(hl); } uint8_t Get() { return(bit_is_set(*Pinp, Nip) ? 0xFF : 0x00); } volatile uint8_t *DDR; volatile uint8_t *Port; volatile uint8_t *Pinp; uint8_t Nip; }; #endif /* PIN_H_ */