# pull-up resistors

Status
Not open for further replies.

#### RonDumas

##### New Member
Can I use the built in pull ups in the 16F876 for a 7 segment led?
How do I enable them in the options register?
Trying to do this with PBC and the Melabs bootloader.
Is it easier to do with PBP?

Thanks for any help.

#### Exo

##### Active Member
You can't use the build in pull-up's to drive leds! The pull-ups can only be enabled when the particular pin is in input mode. And the only purpose of these pull-ups is to keep the input in a known state (1) when the pin is left floating.

Use external resistors in series with the leds to drive them.

#### andy.davies

##### New Member
what is the code to do this? this may help with a problem that has been frustrating me for a long time. if it dosent help, than ill post a question.

#### RonDumas

##### New Member
Pull-up resistor code

Sorry Andy but I don't know the code either. that was part of my question. If you find out please let me know.

sure thing

#### Exo

##### Active Member
Clear Bit RBPU of OPTION_REG. (OPTION_REG is in bank1)
It's all explained in the datasheets

like this...
Code:
BCF     STATUS, RP1
BSF     STATUS, RP0         ;Goto bank1
BCF     OPTION_REG, RBPU    ;enable pullups (only works on pins in INPUT mode)
;code to go back to the desired bank here

#### andy.davies

##### New Member
one other question, will this work with the 16F84A ?

#### RonDumas

##### New Member
Just a newbie question but, How about the PicBasic code. I don't know assembly.
I think I've got this figured out.
Code would be:
Poke Option_Reg, 128 ' enable PortB pullup resistors

Is this correct?

#### Exo

##### Active Member
andy.davies said:
one other question, will this work with the 16F84A ?
Yes, the F84 also has pull-ups on portB; they are controlled in the same way.

#### Exo

##### Active Member
RonDumas said:
Just a newbie question but, How about the PicBasic code. I don't know assembly.
I think I've got this figured out.
Code would be:
Poke Option_Reg, 128 ' enable PortB pullup resistors

Is this correct?
well, i don't know PicBasic :? . But you just need to use the picbasic command to clear the RBPU bit in option_reg;
However, putting 128 in option_reg is not correct; this would SET the bit, you need to clear it. Secondly, you must find a command that only affects that single bit, writing 128 directly for example will set RBPU but will also clear all the other bits in option_reg wich is not good.

#### RonDumas

##### New Member
Thanks EXO. The plot thickens. Bowling night tonight so I'll ponder it over a few beers. This stuff is really challenging. Fun though.

#### ivancho

##### New Member
To enable the pull up resistors you should do the following:

Code:
OPTION_REG = $7f ' Enable PORTB pullups :arrow: As you can see the OPTION_REG will have a 01111111, according to the OPTION_REG chart (attached) you can see that you enable the pull-ups and whatever else. If you want to change those parameters you can too. Good Luck, Ivancho #### Attachments • 56.1 KB Views: 1,373 #### RonDumas ##### New Member I see. The same way all registers are accessed(TrisA,TrisB,etc...). It makes sense now. Does the compiler,PicBasic, recognize the following as the same? Poke Option_reg,127 OR Poke Option_reg,%01111111 OR Poke Option_reg,$7f
If so I assume the first, decimal number, is the preffered way.

Thanks Exo, Andy and Ivancho for your help and patience.

#### ivancho

##### New Member
Yes you can use:
• $for HEX % for binary :arrow: when indicating HEX there are some tricks to it I can't remember. It is something like you have to have 2 positions always, so to put hex A you will have to do$0A.

:!: You do not need to use the POKE comand, as long as you have the PBP. That is an old command that is still around.
But to answer you question, yes that is the same, but You are better off assgining the value to the register name like this

TRISA = %10000001
OPTION_REG = \$7F
PORTB = 5

Ivan

Status
Not open for further replies.