Page 1 of 1

Seting Arduino pull up / down resisters

Posted: Thu Feb 11, 2016 2:27 pm
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

Re: Seting Arduino pull up / down resisters

Posted: Thu Feb 11, 2016 3:16 pm
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