From: Olivier Matz Date: Thu, 23 May 2013 17:54:33 +0000 (+0200) Subject: use macros to read/write ports X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=9b05952e09169f0d32f1dfcae129cab2fba20e95;p=beacon-rx-433.git use macros to read/write ports --- diff --git a/main.c b/main.c index 5dd4f1d..e794376 100644 --- a/main.c +++ b/main.c @@ -19,9 +19,19 @@ #endif /* port B */ -#define BUZ_BIT 0 -#define RADIO_BIT 2 -#define LED_BIT 4 +#define BUZZER_BIT 0 +#define BUZZER_ON() PORTB |= _BV(BUZZER_BIT) +#define BUZZER_OFF() PORTB &= (~_BV(BUZZER_BIT)) + +#define RADIO_BIT 2 +#define RADIO_READ() (!!(PINB & (_BV(RADIO_BIT)))) + +#define BUTTON_BIT 3 +#define BUTTON_IS_PRESSED() (!!(PINB & (_BV(BUTTON_BIT)))) + +#define LED_BIT 4 +#define LED_ON() PORTB |= _BV(LED_BIT) +#define LED_OFF() PORTB &= (~_BV(LED_BIT)) static uint32_t bitfield; @@ -330,7 +340,7 @@ static uint8_t get_input(int i) #ifdef HOST_VERSION return !!x[i]; #else - return !!(PINB & (1 << RADIO_BIT)); + return RADIO_READ(); #endif } @@ -348,15 +358,15 @@ static void set_output(int16_t i) i, pow_fond, pow_harm1, pow_other, cpt_filter, detected); #else if (detected) - PORTB |= (1 << LED_BIT); + LED_ON(); else - PORTB &= ~(1 << LED_BIT); + LED_OFF(); /* when we receive, output a square signal at 625 hz */ if ((detected == 1) && (i & 4)) - PORTB |= (1 << BUZ_BIT); + BUZZER_ON(); else - PORTB &= ~(1 << BUZ_BIT); + BUZZER_OFF(); #endif } @@ -373,7 +383,7 @@ int main(void) /* led and buzzer are outputs */ #if defined(__AVR_ATtiny45__) - DDRB |= (1 << LED_BIT) | (1 << BUZ_BIT); + DDRB |= (1 << LED_BIT) | (1 << BUZZER_BIT); #endif i = 0;