View previous topic :: View next topic |
Author |
Message |
umka
Joined: 28 Aug 2007 Posts: 99 Location: New Zealand
|
Pin definition help |
Posted: Mon Dec 01, 2008 2:17 am |
|
|
I want to be able to have a code segment that will output_high(Output_(i)) or output_low(output_(i)), were output_(i) is assigned to a certain pin, such as #define output_0 pin_a0, #define output_1 pin_b3 ect. The idea is to have (i) as an int8 that can be manipulated easily between 0 and the number of outputs required and thus minimize my code.
Don’t really know how to do it for the output. For reading inputs it was easy all I did was.
Code: | void ReadInput (void)
{
set_adc_channel(i)
delay_us(25);
ADCValue[i] = read_adc();
} |
|
|
 |
crystal_lattice
Joined: 13 Jun 2006 Posts: 164
|
|
Posted: Mon Dec 01, 2008 2:29 am |
|
|
Make an int16 array with the number of elements equal to the number of outputs you want to switch. then initialize the array with the pin defines. This does require more processing power if I'm not mistaken....
Code: |
int16 my_outputs[4] = {pin_a0,pin_c3,pin_b2,pin_e1}
//in your code you will access the outputs like this:
output_high(my_outputs[0]);
output_low(my_outputs[3]);
....
|
|
|
 |
umka
Joined: 28 Aug 2007 Posts: 99 Location: New Zealand
|
|
Posted: Mon Dec 01, 2008 2:55 am |
|
|
cheers for the fast reply.
what do you mean Quote: | then initialize the array with the pin defines |
|
|
 |
|