controlling ports


i thought had ports working, got confused. how write 8 bits on consecutive pins d2 - d9?


code: [select]

byte volt2 = 255;

void setup()
{
  serial.begin(9600);

  ddrd = b11111100;
  ddrb = b00000011;
}

void loop() {
  while (serial.available() > 0) {
    volt2 =  serial.read();
    serial.write(volt2);
  }
  dac2();
}

void dac2(){
  portd = (volt2>>2);
  portb = (volt2<<6);
}


when input 0 bits 5&6 still high.

i thought had ports working, got confused. how write 8 bits on consecutive pins d2 - d9?


code: [select]

byte volt2 = 255;

void setup()
{
  serial.begin(9600);

  ddrd = b11111100;
  ddrb = b00000011;
}

void loop() {
  while (serial.available() > 0) {
    volt2 =  serial.read();
    serial.write(volt2);
  }
  dac2();
}

void dac2(){
  portd = (volt2>>2);
  portb = (volt2<<6);
}


when input 0 bits 5&6 still high.
when input 0 serial monitor, it's '0', (the ascii character).
'0' ascii 0x30, or 0b00110000

(bits 4 , 5 high.)

to convert '0' 0, subtract 0x30.
same goes other ascii digits, multiple digit number, you'll need capture full input string convert, maybe 'atoi()'.


Arduino Forum > Using Arduino > Programming Questions > controlling ports


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'