View previous topic :: View next topic |
Author |
Message |
overmindx
Joined: 06 Oct 2008 Posts: 43
|
internal pull-ups 26k20 |
Posted: Tue Jan 11, 2011 3:34 am |
|
|
hi in the datasheet of an 18f26k20, it says:
Quote: |
10.3.1 WEAK PULL-UPS
Each of the PORTB pins has an individually controlled
weak internal pull-up. When set, each bit of the WPUB
register enables the corresponding pin pull-up. When
cleared, the RBPU bit of the INTCON2 register enables
pull-ups on all pins which also have their corresponding
WPUB bit set. When set, the RBPU bit disables all
weak pull-ups.
|
in my understanding (correct me if im wrong) but it seems, it indicates that you could manually enable pull-ups for each pin.. am i correct? if yes, how can i do this? i tried to set the individual bits of WPUB but it doesnt work.. i dont want to use PORT_B_PULLUPS since it will enable all pull-ups in PORTB.. please help.. thanks in advance |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Tue Jan 11, 2011 5:24 am |
|
|
Port_b_pullups.....
Read the manual about this. It has _two_ modes of operation, depending on the chip involved. On chips that only have pullups on _all_ pins, it simply enables them all. However on chips that allow individual bits to be turned on separately, it can be used like:
port_b_pullups(0b10101010);
and will then just enable the pullups on B1,B3 etc..
So it doesn't "enable all pull-ups in PORTB". If the chip supports enabling them individually, so does the function.
Best Wishes |
|
|
overmindx
Joined: 06 Oct 2008 Posts: 43
|
|
Posted: Tue Jan 11, 2011 7:29 am |
|
|
it seems when i tested it, using port_b_pullups enables all pull-ups. its because when i used port_b_pullups(0b11101111), it still enables the pull-up on pin_B4. is there a way to enable the pullup on a specific pin using 18f26k20? if there is, please help.. thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Tue Jan 11, 2011 8:29 am |
|
|
Obvious question. What compiler version?.
Have just tested with 4.114, and it correctly disables the pull up on B4, with port_b_pullups(0b11101111);
I'd not put is past a significantly older version to get the control 'wrong', since unlike most chips, on this one, you have to disable the 'port b pullups' enable bit, to use the individual bits. 4.114, does this correctly. 4.099, handles the control wrongly, enabling all the pullups, so it is something that has been fixed between these versions
Best Wishes |
|
|
overmindx
Joined: 06 Oct 2008 Posts: 43
|
|
Posted: Tue Jan 11, 2011 9:00 pm |
|
|
too bad.. i am using v.4.096...
thanks for reply.. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Wed Jan 12, 2011 3:21 am |
|
|
OK. In which case you will have to go 'manual'.
As you surmised, you need to enable the bits manually in WBPU, but you also need to _clear_ the pull up enable bit, which otherwise overrides these. So something like:
Code: |
#byte INTCON2 = getenv("SFR:INTCON2")
#byte WPUB = getenv("SFR:WPUB")
#bit RBPU = INTCON2.7
void my_port_b_pullups(int8 mask) {
RBPU=0;
WPUB=mask;
}
|
Then use just like 'port_b_pullups', so in the future if you upgrade to a compiler that works, you can just switch to the supplied function.
Best Wishes |
|
|
overmindx
Joined: 06 Oct 2008 Posts: 43
|
|
Posted: Thu Jan 13, 2011 3:28 am |
|
|
THANKS!! |
|
|
|