Go Down

Topic: digitalWrite (Read 1 time) previous topic - next topic

dragonuv

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
Code: [Select]
uint8_t timer = digitalPinToTimer(pin);

and in the pins_arduino.h i found this line
Code: [Select]
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )

and this line
Code: [Select]
extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];

so basically all i have in my arduino program is this :
Code: [Select]

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.

Coding Badly

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

Yes and yes.

But first, why are you doing this?

dragonuv

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

Coding Badly

#3
Oct 29, 2009, 08:41 am Last Edit: Oct 29, 2009, 08:41 am by bcook Reason: 1
Quote
It will sound crazy.

I was already thinking that.   ;)

Quote
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...

Code: [Select]
#include <avr\pgmspace.h>

mem

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  : http://www.pjrc.com/teensy/teensyduino.html

dragonuv

Thanks guys for supporting :)

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

mem

Quote
whats wrong with the original way?

That was the question I was going to ask you  ;)

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

perhaps you can you clarify

dragonuv

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?)

mem

#8
Oct 29, 2009, 11:28 am Last Edit: Oct 29, 2009, 11:29 am by mem Reason: 1
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

Go Up