Author Topic: Quick question on digital I/O  (Read 4216 times)

0 Members and 1 Guest are viewing this topic.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Quick question on digital I/O
« on: June 25, 2008, 07:48:12 PM »
I have the axon now and I just wanted to know how to read a digital input as well as output HIGH to a digital output
I saw something about setting and clearing on the AVR website but how do I do it on the Axon , like is there some easy function that admin put it?

Thanks,
Eric
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Quick question on digital I/O
« Reply #1 on: June 26, 2008, 12:51:09 AM »
I suppose it came with a manual (or there is an online one). Although for something as simple as this, it's just plain silly to ask for a function.
If not, since it's AVR based, you do it exactly like on an AVR (change port direction, read PINx, respectively, change port direction, write to PORTx)
« Last Edit: June 26, 2008, 12:52:08 AM by izua »
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline bens

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 335
  • Helpful? 3
Re: Quick question on digital I/O
« Reply #2 on: June 26, 2008, 12:58:12 AM »
I feel like this is something you could figure out by spending about two minutes looking at your AVR's datasheet...

Offline benji

  • Supreme Robot
  • *****
  • Posts: 830
  • Helpful? 0
Re: Quick question on digital I/O
« Reply #3 on: June 26, 2008, 01:53:24 AM »
its just like all atmegas
,you have a register to indicate the port as input or output DDR
,you have the PIN register to read form the port when its input
,you have the PORT register to write to it
also when a bit is set to be an input and you set the corespondant PORT bit you would include a pullup resistor 
good ol' BeNNy

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Quick question on digital I/O
« Reply #4 on: June 26, 2008, 06:03:20 AM »
ok thanks


I thought there would be a function the same way that the LED and button on the Axon had a function ( e.g. LED_ON() , LED_OFF....)
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Quick question on digital I/O
« Reply #5 on: June 26, 2008, 06:08:50 AM »
what do you know there is a function for it that admin wrote up

#define PORT_ON( port_letter, number )
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Quick question on digital I/O
« Reply #6 on: June 26, 2008, 06:28:32 AM »
that's a define. it's not really a function.
btw, do you really enjoy using brain bytes to store functions' names and avr cycles to call functions? :P it's really weird to do it just to access I/O pins, you know.

ps. you still need to set DDRx for that port to become an output :P
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Quick question on digital I/O
« Reply #7 on: July 04, 2008, 10:32:13 AM »
With 16 ADC, I figured most people would just use one of those ports for all input needs.

To create a digital input . . . in SoR_Utils.h, you need to change that port to an input. It should be self explanatory if you read the comments I put in that file.

For an example of reading the port, just look at the button code:
Code: [Select]
//*****************BUTTON****************
int button_pressed(void)
{
return (bit_is_clear(PING, 5));
//return ((PING) & (1<<PG5));//old version, went high when button pushed
}
//***************************************

 


Get Your Ad Here