Author Topic: PORT_ON etc. Macros on Axon  (Read 1644 times)

0 Members and 1 Guest are viewing this topic.

Offline ResilientTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 4
PORT_ON etc. Macros on Axon
« on: February 15, 2009, 05:49:19 PM »
I am reading through the code and am a bit confused about what my Ping))) code is actually doing.

Take for example, the following:


Code: [Select]
#define PINGPIN    7          // assign a pin to the Ping Sensor
#define DDR        DDRF

PORT_ON(DDR, PINGPIN);   // Switch PingPin to OUPUT

I follow this over to SoR_Utils.h and see that

Code: [Select]
#define PORT_ON( port_letter, number ) port_letter |= (1<<number)
is there.  I understand that this runs the PORT_ON macro using DDRF and 7 as the arguments.  So it does a bitwise operation on them.  But what happens then?  I don't see where something is done with that new bitwise piece.  It seems like some function must be called with it, but I don't see where that's happening.

Thanks
J

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: PORT_ON etc. Macros on Axon
« Reply #1 on: February 15, 2009, 07:05:02 PM »
The answer lies in the use of the "|=" operator as opposed to just the "|" operator.

So the last part:-
Code: [Select]
port_letter |= (1<<number)
is the same thing as
Code: [Select]
port_letter = port_letter | (1<<number)
So it reads the port, uses a bitwise OR to set the relevant bit, and writes the answer back to the port
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline ResilientTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 4
Re: PORT_ON etc. Macros on Axon
« Reply #2 on: February 15, 2009, 09:28:56 PM »
But it seems like there needs to be some sort of function using port_letter that would actually write it to the port?

Or is the variable DDRF in this case, actually the port, so when you change DDRF you change the port?

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: PORT_ON etc. Macros on Axon
« Reply #3 on: February 16, 2009, 06:57:49 AM »
Yes - the microcontrollers have variables at the low end of the flash memory that are mapped onto the physical IO ports. So reading/writing these 'variables' are actually reading/writing the port.

In this case DDRF is the 'data direction register' for 'Port F'.  So the example code will change F7 to be an output pin. To change the output pin value you will need to write to the port itself. ie

PORT_ON(PORTF, 7);   // will set the output pin higih
PORT_OFF(PORTF,7);  // set the output pin low
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here

data_list