Society of Robots - Robot Forum

Software => Software => Topic started by: airman00 on June 25, 2008, 07:48:12 PM

Title: Quick question on digital I/O
Post by: airman00 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
Title: Re: Quick question on digital I/O
Post by: izua 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)
Title: Re: Quick question on digital I/O
Post by: bens 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...
Title: Re: Quick question on digital I/O
Post by: benji 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 
Title: Re: Quick question on digital I/O
Post by: airman00 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....)
Title: Re: Quick question on digital I/O
Post by: airman00 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 )
Title: Re: Quick question on digital I/O
Post by: izua 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
Title: Re: Quick question on digital I/O
Post by: Admin 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
}
//***************************************