Page 1 of 1

Programmable pull-up resistors.

Posted: Tue Sep 03, 2013 7:22 pm
by Dutch
In my search to minimize the number of part in my project I discovered on a circuitboard from my work there are no pull up/down resistors used in parallel of a dip switch at the Bport of a 16F722 . Looking in the datasheet I learned this port can be programmed for ‘weak pull up resistors’. My question is ,is this a option I can switch on in the full version or is it a flowcode instruction somehow?

Re: Programmable pull-up resistors.

Posted: Tue Sep 03, 2013 7:47 pm
by kersing
It i not an option as far as I know, you will need to use a C icon to turn weak pull up on.

To turn weak pull up on for all pins:

Code: Select all

option_reg = option_reg & 0x7f;
wpub = 0b11111111;
Use wpub = 0b00000001 for B0 only, wpub = 0b00000010 for B1 only etc.

Re: Programmable pull-up resistors.

Posted: Tue Sep 03, 2013 8:23 pm
by Dutch
Aha! so it's possible to put C code in a custom 'window'. I'll try to create that in advance. Thanks!

Means possible I need to reverse all my bcd codes if a dip switch is ON to ground.. ah well.. keeps me from the street :?

Re: Programmable pull-up resistors.

Posted: Tue Sep 03, 2013 9:10 pm
by Dutch
:idea: found in the 16F628A the same pull up resistor possibility! .HAd not looked before! THAT I can try here!
but the datasheet does not tell much ... or is this enough?

First the litlle text i could find from the 16F628 datasheet. what should I put in the c block here? looks like one command turns all on

Second... i already tried something for the 16f722 when I get to that. would the C block look like that?

Re: Programmable pull-up resistors.

Posted: Tue Sep 03, 2013 9:34 pm
by kersing
C block looks good for 16f722, you might want to remove the comment as it is not required. The 16f628 has only one bit to enable the pull-ups for all pins on port B.

For the 16f628 the C code would be:

Code: Select all

option_reg = option_reg & 0x7f;

Re: Programmable pull-up resistors.

Posted: Tue Sep 03, 2013 9:59 pm
by medelec35
Hi Dutch,
Another way.
If you see in a data sheet to clear bit 7 of option_reg
Then you can use

Code: Select all

clear_bit(option_reg , 7);
Or if you know what register and bits are called:
E.g looking at page 25 of 722 data sheet and you want a weak pullup only on RB7 you have:
WPU1.png
(3.26 KiB) Downloaded 3915 times
Register is outlined in orange (You must use lower case)
Bit is outlined in red (You must use UPPER CASE)
then you can use:
clear_bit(wpub , WPUB7);
To set a bit you can use set_bit instead of clear_bit

If you need to set or clear more than on bit then you need to use masking just like in the format kersing posted.

If you need further help with bit masking just ask away.
Don't want to overwhelm with too much information

Martin

Re: Programmable pull-up resistors.

Posted: Tue Sep 03, 2013 11:03 pm
by Dutch
Thanks Kersing ! have new food for thoughts now :) will try that asap (too bad it's not a pull down option :wink: )

Sure will look into that Martin. opens up possibility's.
Hmm data sheet can be overwhelming. but that's all you see for the first time!

Your help earlier on already helped great! dramatically simplified my flowcharts
sure have tons of Q in the future...

thanks for your support both!