# difference between digitalWrite and bitWrite functions

Is there any difference between digitalWrite() and bitWrite() functions ?

ultimately it write the bit 1 (+Vcc) to the specified pin.

• The speed of writing pins is MUCH quicker with the bitWrite methods compared to the standard digitalWrite methods

Thanks, VASHI

can you explain these?

means How much times bitWrite is faster than digitalWrite ?

and I don,t know the parameter x and n in function bitWrite(x,n,b), plz explain these.

For example, if you wanted to send a logic 1 (high) to digital pin 13,

you would normally do it like this:  " digitalWrite(13, HIGH); "

The IDE knows where digital pin 13 is connected on the microcontroller. So if you wanted to use the bitWrite function on digital pin 13, you first have to find out the PORT and pin number of that port, that digital 13 belongs to.

So in order to send a logic 1 to digital pin 13 using the bit Write function, you do it likes this: " bitWrite(PORTB,5,1); ".

if you are using digitalWrite, The manual work is less. but compiler work is more and vise-versa.

Thanks, VASHI

plz, give me example of bitWrite() function using GR-Kaede board' PORT.

I have error in online compiler in bitWrite function.

Function definition :

#define bitRead(value, bit) (((value) >> (bit)) & 0x01)

#define bitSet(value, bit) ((value) |= (1UL << (bit)))

#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))

#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))

Example :

```// sets x to 33 (00100001 in binary)
byte x = 33;
// writes a 1 to the second bit bit of x, now x is 00100101 (37 in decimal)
bitWrite(x, 2, 1);```

but I want to write to PORT Pin not in data byte.

so with which I have to replace x ?

I have tried PC,PORTC.

Hi friend,

I took one sample code. given below.

#include <Arduino.h>

void setup()

{

pinMode(13,OUTPUT);

}

void loop()

{

bitWrite(PORTB,5,1);

delay(1000);

bitWrite(PORTB,5,0);

delay(1000);

}

I compiled by using Arduino IDE. It compiled successfully. But i compiled using Renesas web compiler. its giving error.

Because arduino uno board contain ATMEGA328. ATMEGA internally contain registers like PORT, PIN , DIR. This registers

are used for I/O control.

But our  GR-KAEDE board is arduino compatible. I am not sure about all the functions work as like Arduino IDE.

Registers are vary from one  microcontroller to another. Better u go to digitalWrite function.