digitalWrite

I've been trying to use the Void of digitalWrite without really typing digitalWrite, so I looked inside the wiring_digital.c file and I saw how the digitalWrite is made.

the first line is

uint8_t timer = digitalPinToTimer(pin);

and in the pins_arduino.h i found this line

#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )

and this line

extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];

so basically all i have in my arduino program is this :

extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];

#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )

void setup() 
{
  
}
void loop() 
{
uint8_t timer = digitalPinToTimer(1);
}

but I'm stuck, whenever I try to compile I get the error message: " error: expected initializer before 'digital_pin_to_timer_PGM' "

anyone knows what can cause this? and how do I solve it?

Thanks very much.

anyone knows what can cause this? and how do I solve it?

Yes and yes.

But first, why are you doing this?

It will sound crazy.
I'm trying to write my own langage for the AVR assembly commands, my own version of arduino.

It will sound crazy.

I was already thinking that. :wink:

I'm trying to write my own langage for the AVR assembly commands, my own version of arduino.

Crazy and ambitious. I hope you're successful (not because I dislike the Arduino but because I'm extremely curious about your plan).

Add this to the top of your Sketch...

#include <avr\pgmspace.h>

If you are doing this to make improvements then you would be better off finding a different way to do the pin number translation.

For example, have a look at the way its done by teensyduino, see pins_teensy.c after getting the download from : Teensyduino - Add-on for Arduino IDE to use Teensy USB development board

Thanks guys for supporting :slight_smile:

mem - why would I want to find a different way to translate the pins of atmega? whats wrong with the original way?

whats wrong with the original way?

That was the question I was going to ask you :wink:

I guess I don't understand what you want to do an why you want to do it.

perhaps you can you clarify

Well, it could be a good way of teaching myself how the arduino language is made.
I dont have an intention of changing the pins_arduino.c because there are no commands there, only definition of each pin (right?)

Yes, pins_arduino.c contains information on the mapping of pins to physical ports and timers. This information is stored in program memory to minimse the RAM usage.

wiring_digital.c and wiring_analog.c contain the commands that use this information to do something with the pins.

studying those three files should help you see how arduino uses pins