PORTD = PORTD & B11110111;SPI.transfer(0x03);SPI.transfer(0xF0);PORTD = PRTD | B00001000;
PORTD = PORTD & B11110111; // clear bit 3 (D4, as an example) to enable device X slave selectSPI.transfer(0x03); // send out address byteSPI.transfer(0x03); // send out data bytePORTD = PRTD | B00001000; // set bit 3 to deselect device X
// define the magic numbers #define ENABLE_X_SLAVE B11110111#define DISABLE_X_SLAVE B00001000#define ADDRESS 0x03...uint8_t data = 0x03;PORTD = PORTD & ENABLE_X_SLAVE ; SPI.transfer(ADDRESS); SPI.transfer(data); PORTD = PORTD | DISABLE_X_SLAVE ;
if there is a way to just write a byte of data to set all output levels at once.
I have another bit of code that is getting a compile error on the following line: PORTA = (PORTA ^ B00000001);with a 'PORTA' was not declared in this scope ' error.I am using an atmel chip with the Uno bootloader and if I change the board type to a mega, it compiles without error.How can I set this up to load on my Uno without an error?thanks
I was wondering if instead of doing several digitalWrite commands to set individual output pin levels on an Arduino (e.g. digitalWrite(D0, HIGH) - digitalWrite(D7, HIGH)) if there is a way to just write a byte of data to set all output levels at once.Also, is there a way to set all of the pinModes at once also... (like writing a value to a register for example)thanks
pinMode(8, INPUT) == DDRB &= ~_BV(0)pinMode(8, OUTPUT) == DDRB |= _BV(0)digitalWrite(8, HIGH) == PORTB |= _BV(0)digitalWrite(8, LOW) == PORTB &= ~_BV(0)x = digitalRead(8) == x = PINB & _BV(0) ? 1 : 0Set pinmode of pins 7 through 0 as outputs in one shot:DDRD = 0b11111111;As all inputs:DDRD = 0b00000000;Bits 0...3 as input, 4...7 as outputs:DDRD = 0 | _BV(4) | _BV(5) | _BV(6) | _BV(7);
Please enter a valid email to subscribe
We need to confirm your email address.
To complete the subscription, please click the link in the
email we just sent you.
Thank you for subscribing!
via Egeo 16