From c4b21121fb82cc5b4f9acdc49846c3671a4584c2 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 22 Oct 2013 02:17:59 +0300 Subject: [PATCH] Use symbolic constants for addressing I/O pins --- arducontrol/output.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/arducontrol/output.c b/arducontrol/output.c index c1d5148..4b66296 100644 --- a/arducontrol/output.c +++ b/arducontrol/output.c @@ -3,6 +3,10 @@ #include "output.h" #include "timer.h" +#define POLARITY PORTD2 +#define ENABLE PORTD3 +#define BIT(x) (1<<(x)) + OutputPacket packet; uint8_t out_bit; uint8_t out_time; @@ -12,7 +16,7 @@ uint8_t delay_time; void output_init() { DDRD = (DDRD&0xF3)|0x0C; - PORTD &= ~0x08; + PORTD &= ~BIT(ENABLE); timer_start_hz(0, 80000, 1); } @@ -27,9 +31,9 @@ void clear_packet() void output_set_power(uint8_t p) { if(p==POWER_ON) - PORTD |= 0x08; + PORTD |= BIT(ENABLE); else - PORTD &= ~0x08; + PORTD &= ~BIT(ENABLE); } uint8_t output_command() @@ -57,7 +61,7 @@ static inline void output_tick() ++out_bit; if(out_bit>=packet.length) { - PORTD &= ~0x04; + PORTD &= ~BIT(POLARITY); if(packet.repeat_count>1) { if(packet.repeat_count<0xFF) @@ -79,9 +83,9 @@ static inline void output_tick() out_data >>= 1; if(out_data&1) - PORTD |= 0x04; + PORTD |= BIT(POLARITY); else - PORTD &= ~0x04; + PORTD &= ~BIT(POLARITY); out_time = packet.bit_duration; } @@ -96,9 +100,9 @@ static inline void output_tick() out_time = packet.bit_duration; out_data = packet.data[0]; if(out_data&1) - PORTD |= 0x04; + PORTD |= BIT(POLARITY); else - PORTD &= ~0x04; + PORTD &= ~BIT(POLARITY); } } -- 2.45.2