Now lets look at how to use the pins for output.
There are many ports on the MSP430 (varies on version) , for example PORT-1 ( P1.0 to p1.7 ) &
PORT-2 ( P2.0 to P2.7 ).
#include <msp430.h>
/**
* main.c
*/
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
P3DIR=0xFF; // P3DIR=0x00;
P6DIR=0xFF;
P4DIR |=0x00;
P4REN |=0xFF;
P4OUT |=0xFF;
}
P3DIR |=0x00 tells us that the whole of PORT-3 is initialized to take inputs.
P3DIR |=0xFF tells us that the whole of PORT-3 is initialized to give outputs.
P3DIR |=0x01 only the pin P3.0 is initialized to output in PORT-3.
This follows a Hexadecimal Port mapping.
The Major advantage with the higher versions of MSP430 are , they have inbuilt Pull -Up or Down resistors, so no need to connect externally.
P4REN |=0xFF , this indicates that the pins of PORT-4 have their pull up/down resistors enabled.
TO select them between Pull UP or Pull DOWN, the instruction P$OUT |=0xFF is used.
If 0xFF is used they configure as Pull UP resistors and if 0x00 they configure as Pull DOWN.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.