bitWrite function code to use with PIC microcontroller

1

I am therefore an Arduino code for the PIC pro compiler MikroC. I came up with a part that contains the following:

byte data[3];

// pulse the clock pin 24 times to read the data
for (byte j = 3; j--;) {
    for (char i = 8; i--;) {
        digitalWrite(PD_SCK, HIGH);
        bitWrite(data[j], i, digitalRead(DOUT));
        digitalWrite(PD_SCK, LOW);
    }
}

I managed to fix it for:

byte data[3];
int j;
int i;

// pulse the clock pin 24 times to read the data
for (j = 3; j--;) {
    for (i = 8; i--;) {
        RD1_bit = 1;
        bitWrite(data[j], i, RD0_bit);
        RD1_bit = 0;
    }
}

So, it only lacks the function bitWrite(data[j], i, RD0_bit); to work, but I did not reach conclusive results.

I currently have the following code, which is not running:

void bitWrite(uint8_t &x, unsigned int n, int b1) {
    if (n <= 7 && n >= 0) {
        if (b1) {
            x |= (1u << n);
        } else {
            x &= ~(1u << n);
        }
    }
}

Note: Only% w_that I am using is include

    
asked by anonymous 16.10.2015 / 21:29

1 answer

0

I was able to work with the following code:

void bitWrite(char *x, char n, char value) {
   if (value)
      *x |= (1 << n);
   else
      *x &= ~(1 << n);
}
    
25.10.2015 / 00:57