Arduino mega 2560 rev 3 pinout3/7/2024 (0<<PB7) does not mean anything until it is used with a register. Using the DDRB and PORTB, what code would you use to do this for PB7? So your pin 11 and pin 12 commands should be combined into: "DDRB = (1<<PB6)|(1<<PB5) "Īs I mentioned in my code earlier, to set as INPUT_PULLUP, you have to set as an output, send the pin high, and then set the pin as an input. DDRA is for port A and so on.įor multiple DDRx commands, it is better to use the "OR" operator. So DDRB = (1<<PBy) is setting the direction of port B pin "y" to be an output. So digital pin 13 on the Mega is port B pin 7. The "x" in "DDRx" is the port, so for PB7, "B" is the port and "7" is the pin. Confusion is often the first step toward knowledge. Thank you, bos1714, that is already very heplful. I could easily write your code for you, but I think it would be infinitely better if you were to learn the experience yourself With that said, look at each pin and see what port it is located at, that will tell you what DDRx and PORTx to use. You can also go the pins_arduino.h file in your Arduino installation location, but I would recommend against that as messing with the file will give you a headache. You can also look at the header file I have attached below which shows what each port and pin each Mega pin is mapped to. It will also show you the port and pin numbers for each pin. What you can do is look through the schematic of the Mega that is posted on the Mega Product Page under "documentation" the schematic will show you a big rectangle that is the mega2560 chip. In my example, it says PB7 is pin 13, which it is. : then PULLUP.?Įach of the pins of the Mega (1, 15, 53, etc) has a port and pin number. ![]() n = 0 -7Īctually the variables are completely puzzling me because I still don't know anything about PORTx, PINx, DDRx, it's differences, and all that. Instructions for single bit data read/write operation (not tested) digitalWrite(DPin, HIGH/LOW) īitSet(DDRX, n) //X = A, B, C. Instructions for 8-bit data read/write operations with ports (not tested) byte z = PORTX ģ. Instructions to set directions of the IO lines (not tested) pinMode(DPin, INPUT) ĭDRX = 0xnn // nn = 00 - FF LH makes output LL makes inputĢ. Internal Structure of a typical Port-pin:ġ. ![]() Register Name Output Register Name Input Register Name Size DPins Port-A PORTA PINA 8ĭDRDX (X = A, B, C, D, E, F, G, H, J, K) : Data Direction Register Here is a brief summary of the Registers and DPins of ATmega2650 - (for DPins please see schematic)
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |