mirror of
1
0
Fork 0

Add macro for disabling and enabling internal pullups.

This commit is contained in:
Mika Tuupola 2011-10-17 22:40:58 +03:00
parent 5eba9dde1c
commit 6b889b0ae5
2 changed files with 18 additions and 33 deletions

View File

@ -32,9 +32,7 @@
void init(void) {
/* Make PORTD2..7 PORTD0..1 (Arduino digital 2..10) input by clearing bits in DDR */
//DDRD &= ~(_BV(PORTD2) | _BV(PORTD3) | _BV(PORTD4) | _BV(PORTD5) | _BV(PORTD6) | _BV(PORTD7));
//DDRB &= ~(_BV(PORTB0) | _BV(PORTB1));
/* Switch inputs. */
pin_mode(2, INPUT);
pin_mode(3, INPUT);
pin_mode(4, INPUT);
@ -48,33 +46,21 @@ void init(void) {
/* you dont connect anything to pin and if you try to read it, it will read as 1. Now, */
/* when you externally drive that pin to zero(i.e. connect to ground / or pull-down), */
/* only then it will be read as 0. */
/* Enable pullups by setting bits in PORT. Default state is now high. */
PORTD |= (_BV(PORTD2) | _BV(PORTD3) | _BV(PORTD4) | _BV(PORTD5) | _BV(PORTD6) | _BV(PORTD7));
PORTB |= (_BV(PORTB0) | _BV(PORTB1));
/* Disable pullups by clearing bits in PORT. Default state is now low. */
/*
PORTD &= ~(_BV(PORTD2) | _BV(PORTD3) | _BV(PORTD4) | _BV(PORTD5) | _BV(PORTD6) | _BV(PORTD7));
PORTB &= ~(_BV(PORTB0) | _BV(PORTB1));
*/
pin_pullup(2, DISABLE);
pin_pullup(3, DISABLE);
pin_pullup(4, DISABLE);
pin_pullup(5, DISABLE);
pin_pullup(6, DISABLE);
pin_pullup(7, DISABLE);
pin_pullup(8, DISABLE);
pin_pullup(9, DISABLE);
/* Make PORTB5 (Arduino digital 13) an output by setting bit in DDR. */
//DDRB |= _BV(PORTB5);
/* Blinken led. */
pin_mode(13, OUTPUT);
}
/*
int digital_read(int input_register, int pin) {
return bit_is_set(input_register, pin) != 0 ? 1 : 0;
}
void digital_write(int input_register, int pin) {
input_register |= _BV(pin);
}
*/
int main(void) {
init();
@ -83,18 +69,11 @@ int main(void) {
stdin = &uart_input;
int value;
//char buffer[9];
while (1) {
/* Blink led by toggling state of PORTB5 (Arduino digital 13). */
PORTB ^= _BV(PORTB5);
/*
puts("PINB");
value = PINB;
itoa(value, buffer, 2);
puts(buffer);
*/
value = digital_read(2);
printf("%d", value);

View File

@ -25,7 +25,8 @@
#define INPUT 0x0
#define OUTPUT 0x1
#define ENABLE 0x1
#define DISABLE 0x0
#define ARDUINOPIN_TO_TIMERID(x) TIMER_AT_PIN_##x
#define ARDUINOPIN_TO_TCCRID(x) TCCR_AT_PIN_##x
@ -548,9 +549,14 @@
#define D_WRITE_0x1(pin) D_WRITE_HIGH(pin)
#define D_WRITE_0x0(pin) D_WRITE_LOW(pin)
#define D_WRITE_ENABLE(pin) D_WRITE_HIGH(pin)
#define D_WRITE_DISABLE(pin) D_WRITE_LOW(pin)
#define SET_OUTPUT(pin) EXPAND_WRAPPER(_SET_OUTPUT, ARDUINOPIN_TO_PORTID(pin), ARDUINOPIN_TO_PORTMSK(pin) )
#define SET_INPUT(pin) EXPAND_WRAPPER(_SET_INTPUT, ARDUINOPIN_TO_PORTID(pin), ARDUINOPIN_TO_PORTMSK(pin) )
#define pin_mode(pin, mode) SET_##mode(pin)
#define pin_pullup(pin, val) D_WRITE_##val(pin)
#endif /* PINS_H */