Pages: [1]   Go Down
Author Topic: digitalWrite  (Read 1254 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 87
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

so basically all i have in my arduino program is this :
Code:
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.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

But first, why are you doing this?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 87
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It will sound crazy.
I was already thinking that.   smiley-wink

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:
#include <avr\pgmspace.h>
« Last Edit: October 29, 2009, 02:41:56 am by bcook » Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 87
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys for supporting smiley

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

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
whats wrong with the original way?
That was the question I was going to ask you  smiley-wink

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

perhaps you can you clarify
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 87
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: October 29, 2009, 05:29:38 am by mem » Logged

Pages: [1]   Go Up
Jump to: