Hi guys,
I don't understand how to use this code in arduino. I have found this code on sensor datasheet.
#define XDIR DDRD.2
#define XDOUT PORTD.2
#define XDIN PIND.2
Do you have any idea to translate this code in arduino language ?
Hi guys,
I don't understand how to use this code in arduino. I have found this code on sensor datasheet.
#define XDIR DDRD.2
#define XDOUT PORTD.2
#define XDIN PIND.2
Do you have any idea to translate this code in arduino language ?
Do you have any idea to translate this code in arduino language ?
I have the idea that you should post the datasheet where you got that.
A wild guess (very wild) is that DDRD.2 means pin 2 on DDRD. In Arduino speak that would be something like
DDRD &= 0b00000100;
I don't know how to express that as a #define
...R
Hi
Yep, i try to use this PIR sensor: LowPowerDigipyro
Especially to test Serial data clock page 3
Thank's
#define XDIR DDRD.2
#define XDOUT PORTD.2
#define XDIN PIND.2
The meanings of the symbolic names of DDRD.2, PORTD.2, and PIND.2 are being explained with the help of the following diagram that belongs to Bit-2 of Port-D Register of the ATmega328P MCU of Arduino UNO. XDIR, XDOUT, and XDIN are the alternate (software) names for DDRD.2, PORTD.2, and PIND.2 respectively.
Figure-1: Internal structure of Bit-2 of Port-D Register
Port-D is the name that we use to refer to Port-D Register when the directions of its IO lines are not yet set either as input or as output.
PORTD is the software name of Port-D Register when its IO lines are configured to work as output.
PIND is the software name of Port-D Register when its IO lines are configured to work as input lines.
DDRD is the software name of the Data Direction Register that is used to configure the directions (either as input or output) of the IO lines of Port-D Register.
DDRD.2 = Bit-2 of DDRD Register = DDRD2 in Fig-1.
PORTD.2 = Bit-2 of PORTD Register = POTRD2 in Fig-1.
PIND.2 = Bit-2 of PIND Register = PIND2 in Fig-1.
When LH is written into DDRD2 (aka DDRD.2) bit, the corresponding line PORTD2 (PD2 in Fig-1) of PORTD Register works as output. When LL is written, the same line is configured to work as input.
In Arduino UNO, DPin-2 (Digital Pin 2) of the connector is physically connected with Bit-2 of Port-D Register.
Example-1: Set DPin-2 as output
LH ----> DDRD2 (DDRD.2, XDIN) : The Arduino Code :
(a) pinMode(2, OUTPUT);
(b) bitSet(DDRD, 2);
(c) bitWrite(DDRD, 2, HIGH);
(d) DDRD = 0b00000100; //Bit-2 is output; all other bits are input without internal pull-up
Example-2 Writing LH at PORTD2 (PD2)
LH ---> PORTD2 (PORTD.2, XDOUT) : The Arduino Code :
(a) digitalWrite(2, HIGH);
(b) bitSet(PORTD, 2);
(c) bitWrite(PORTD, 2, HIGH);
Example-3 Set DPin-2 as input
LL ----> DDRD2 (DDRD.2, XDIN) : The Arduino Code :
(a) pinMode(2, INPUT); //if input pull-up is needed, use: pinMode(2, INPUT_PULLUP);
(b) bitClear(DDRD, 2); //without internal pull-up
(c) bitWrite(DDRD, 2, LOW); //without internal pull-up.
(d) DDRD = 0b11111011; //Bit-2 is input without internal pull-up; all other bits are output
Example-4 Reading 1-bit data from DPin-2 (Bit-2 of Port-D as input)
(a) bool n = digitalRead(2);
(b) bool n = bitRead(PIND, 2);
(c) bool n = bitRead(POTRD, 2); //doesn't read pin signal; it reads value what was written on PD2
That syntax (PORT.pin) is particular to a compiler/IDE, CodeVisionAVR if memory serves. It is not applicable anywhere else in the world.
Thank you very much everybody, and thank's for the good explanation GolamMostafa.
After your explanation, it become really simple, my code works
Iirc, the .2 syntax is used in a number of C compilers for early micros (from when being standard was less important.). Microchip PIC and 8051?
Syntax like PX_n = 1; is also used in MIDE-51 Studio SDCC Compiler
place(i, j);
delay(50000);
P3_0=1;
delay(500);
j++;