Seting Arduino pull up / down resisters

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Chris_MIRA
Posts: 186
Joined: Wed Jan 23, 2013 3:43 pm
Has thanked: 2 times
Been thanked: 21 times
Contact:

Seting Arduino pull up / down resisters

Post by Chris_MIRA »

Hi,
I understand that the internal arduino pull up (down) resisters can be set by adding a few lines of C code, but cant find the relevant C code, could someone please give an explanation or examples of how to set them please? :D
Regards,
Chris

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Seting Arduino pull up / down resisters

Post by Benj »

Hi Chris,

There's just internal pull up resistors on the Mega328P no pull down.

Here is some code you can use to add pull ups to port pin B0, other port pins work in the same way. Basically the pin has to be configured as an input and then you set the bits in the port register, the order doesn't seem to matter according to the datasheet.

Code: Select all

MCUCR &= 0xEF;  //Global Enable Pull Ups - Clear PUD bit
DDRB |= 0x01; //Port pin B0 configured as input
PORTB |= 0x01;  //Pull up enable

Post Reply