1175 views|0 replies

2015

Posts

0

Resources
The OP
 

MSP430G2553 study notes DAY1 Knowledge reserve and device initialization [Copy link]

Register
Direction register PxDIR
specifies the IO port output/input, 0: input 1: output

PxDIR = BIT0;
PxDIR = 0x01; //The two forms are equivalent, define Px.0 as output;

the output register PxOUT
specifies the IO port to output high or low level 0: low 1: high

P1OUT = BIT0; //P1 is 0xFF;
P1OUT |= BIT0; //P1.0 is 1, P1 is 0x01;
P1OUT &= ~BIT0; //P1.0 is 0;

Input register PxIN
specifies the IO port input status 0: low 1: high

The internal resistor pull-up/pull-down control register PxREN
controls the internal resistor pull-up or pull-down of the MCU IO port and fixes the initial state of the IO port

P1REN = BIT0; //P1.0 internal resistor weak pull-up, used to read keyboard status, P1.0 is pulled low when the keyboard is pressed

Pin multiplexing function selection register PxSEL/PxSEL2
selects the function of the multiplexed pin

Operator
Logical operator
&& Logical AND
The result is true when all are true, and false when any are false;

|| Logical OR
The result is true when any of them are true, and false when all of them are false;

! Logical NOT
If the condition is true, the result is false; if the condition is false, the result is true;

Bitwise operator
& Bitwise AND
a:11001100
b:11110000
=:11000000

| Bitwise OR
a:11001100
b:11110000
=:11111100

~ Bitwise inversion
a:11001100
=:00110011

~ Bitwise XOR Different
is true, identical is false;

a:11001100
b:11110000
=:00111100

Initialization
Light up the LED for testing

#include <msp430g2553.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Turn off the watchdog
P1OUT = 0; // The initial value of P1 is 0x00;
P1DIR = BIT0 | BIT6 ; // Initialize P1.0 and P1.6 as outputs
while(1)
{
P1OUT |= BIT0; // P1.0 outputs high level
P1OUT |= BIT6; // P1.6 outputs high level
}
}

Button control LED test

#include<msp430g2553.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD;
P1OUT = 0;
P1DIR |= BIT0 + BIT6;
P1REN |= BIT3; //P1.3 internal resistor pulls up, initial state is weak high level
P1OUT |= BIT3;
while(1)
{
if((P1IN & BIT3) == BIT3)
P1OUT |= BIT0 + BIT6;
else
P1OUT &= ~BIT0;
}
}

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list