|
Re: Problems reading io pins as a group
Quote:
|
Originally Posted by emusteve
I'm trying to read a group of 4 io pins to get a numerical value as the status of an outboard device. I'm trying it out using the edubot controller so I'm looking at io pins 1-4 which translates to PortA bits 0-3. I was trying to do the following:
sensor_value = (PORTA & 0x0f);
iIt compiles ok, but the result is always 0. I double-checked that I have set the pins to INPUT, and have set the number of analog channels to NO_ANALOG. sensor_value is an unsigned char.
I also tried reading the pins individually as rc_dit_in01 through rc_dig_in04 and got the proper values, so I know the hardware is ok. Anyone know what gives here? Any help would be appreciated.
|
We're doing the same thing with a BCD switch.
I tested this on the EDU controller and it worked.
With unconnected pins you get 0x0F
With dig I/O 1 signal-to-gnd you get 0x0E
With dig I/O 1&2 connected you get 0x0C
Code:
in user_routines.c, User_Initialization()
Set_Number_of_Analog_Channels(NO_ANALOG); /* See ifi_aliases.h */
IO1 = IO2 = INPUT;
IO3 = IO4 = IO5 = INPUT;
IO6 = IO8 = IO10 = INPUT;
// IO3 = IO4 = OUTPUT;
// IO5 = IO7 = IO9 = OUTPUT;
IO7 = IO9 = OUTPUT;
IO11 = IO13 = IO15 = OUTPUT;
// rc_dig_out03 = rc_dig_out04 = 0;
// rc_dig_out05 = 0;
in user_routines.c, Process_Data_From_Master_uP()
PrintString((char *) "PORTA = ");
PrintByte(PORTA & 0x0f);
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
Last edited by Mark McLeod : 11-02-2004 at 14:46.
|