|
|
View previous topic :: View next topic |
Author |
Message |
iso9001
Joined: 02 Dec 2003 Posts: 262
|
Trying to float multible pins and lower one effiecently |
Posted: Mon Apr 25, 2005 11:12 am |
|
|
This is kind of a continuation of my other thread, but I've changed the ules a bit.
I'm constantly picky one pin determined from an input somewhere else in my code. And when I see a pin has to be selected, I make it output_low and float the rest, easy enough. I'm using C7, C6, C5, C4, B1, and B2. When I'm setting or floating however I can not change any other pins (ie: B0, C2, etc) I have some code that looks good to me, but isnt working.
Code: |
#byte portb = 0x06
#byte portb_tris = 0x86
#byte portc = 0x07
#byte portc_tris = 0x87
...
if (value>800)
state=64;
else if (value>700)
state=32;
else if (value>600)
state=8;
else if (value>500)
state=4;
else if (value>300)
state=2;
else if (value>100)
state=1;
portc_tris |= 15; //0b00001111 float C4,C5,C6,C7
portb_tris |= 96; //0b01100000 float B1,B2
if (state > 8)
portb_tris ^= state;
else
portc_tris ^= state;
|
I get no change on any of the ports. I got the port number right, any idea whats going on here ? Its a pic 16F872 part |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 25, 2005 12:36 pm |
|
|
Not sure what you're trying to do, but if you want to switch a pin
between a Logic-low state and floating, then set all the pins that
you're using to a low level. Then to switch between Low and Floating,
just change the TRIS for those bits to be either an output or an input.
This is how CCS does it in their software i2c library code.
They set the port latch bits for SDA and SCL low, and then they
switch those pins between having a low-level out and floating
by just flipping the TRIS bits. Of course, those pins have pull-ups
on them, so when they're in a float condition the pull-ups bring
the pins up to a logic high level. |
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Mon Apr 25, 2005 11:04 pm |
|
|
Thats exactly what my code is doing, or at least supposed to do.
I cant set all the ports to float because I am only interest in 6 pins across two ports. I supposed I could use a output_float for each one, but that should be what this is doing:
Code: |
portc_tris |= 15;
portb_tris |= 96;
|
Where four bits on portc are made to float, two bits on portb. All while not affecting the other pins on each port. Then
Code: |
portb_tris ^= state;
|
should be taking the bit place of the pin I want to lower and making it an output
I have not yet hooked it up to the debugger (its a process for this circuit board). So I figured I'de use the ol' noggin to figure it out. Ofcourse that lasted about an hour.
Anyway, any ideas why my code isn't working ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 25, 2005 11:12 pm |
|
|
I don't see any code where you actually write to the port registers
(portb or portc). Your code only writes to the TRIS registers.
Ideally, you should post a complete test program. Then we can
see everything you're doing, including any #use statements. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|