View previous topic :: View next topic |
Author |
Message |
meereck
Joined: 09 Nov 2006 Posts: 173
|
PORTB : pullups and using input_b() |
Posted: Fri Feb 09, 2007 8:54 pm |
|
|
Hello, this is really newbie question. Lower 4 bits of portB are outputs, higher are inputs.
Therefore I set set_tris_b(0xF0);
To the upper 4 bits buttons are connected. If there is an internal pullup it means that I can use a button without my own pullup resistor?
I suppose that these pullups can be set just for the 4 bits of the portB.
Another issue is that if I read a value of the portB (byte value = input_b();), all 4 outputs of the port goes to low. How can I aware changing states of outputs?
thanks in advance,
M. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Fri Feb 09, 2007 9:17 pm |
|
|
With most PICs you can't set pullups for individual pins or groups of pins. It's all or nothing. That said, the pullups only affect the pins that are set to be inputs. Your four buttons should be connected from the PIC pins to ground. Pushing the button should close the switch and short the PIC pin to ground.
The reason that an input_b() read of the port screws up the 4 output pins is because of the default standard_io in use. The compiler assumes that you want it to automatically take care of setting the port direction based on what you do in the code. An output_b() command would cause it to set the port to an output, and input_b() causes it to set the entire port to input.
The way you tell the compiler to let you take care of everything is through one of the #use io commands. The default, as I mentioned is #use standard_io(B). You want #use fast_io(B). Consult the compiler help and/or the manual for more information. |
|
|
meereck
Joined: 09 Nov 2006 Posts: 173
|
|
Posted: Sat Feb 10, 2007 11:58 am |
|
|
thank you
Regards |
|
|
|