MSP430: What does P1OUT=4, P1OUT |=4, P1OUT &-=~8 mean?

Publisher:书香墨意Latest update time:2015-11-10 Source: eefocusKeywords:MSP430 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
First of all, msp430 does not have a P0 port, so let's use the P1 port to explain P1OUT = 4; P1.2 pin outputs a high level, and the rest of the P1 pins output a low level; P1OUT |= 4; P1.2 is set to a high level, and the rest of the P1 pins remain unchanged; P1OUT &= ~8; that is, P1OUT &= 0xf7, P1.3 is set to a low level, and the rest of the P1 pins remain unchanged; | is the OR operator, & is the AND operator, please refer to the C language application operator section for details!
  
If there is no P0 port, just treat P0 as P1 and explain P1OUT=4=0100; so P1.0, P1.1, P1.3 input P1.2 output P1OUT |=4=0100; so P1.2 output P1OUT &-=~8=-(1000)=0111; P1.3 input may not be correct. This is my own understanding. I have just read the book, so I hope experts can give me some advice. The following is a detailed explanation of AND or OR. Please take a closer look. This is what I organized when I was studying. (1) The & is often used to test whether a certain bit is 1 or 0. The following program tests whether the fourth bit of the variable flag is 1 or 0. #define TEST 8 main() { int flag; ...; if ((flag&TEST)!=0) { printf("fourth bit is set"); } } Note that the logical operator has a lower priority than the relational operator and must be enclosed in parentheses. Bitwise AND is also often used to clear certain bits of the operand or to keep certain bits: a=a&0xffff clears the upper 16 bits and keeps the lower 16 bits. (2) Bitwise OR is often used to set a bit in an identifier to 1 #define SET 8 main() { int flag; ...; flag=flag | SET; //Same as flag |=SET if((flag & TEST)!=0) { printf("flag is set") } } (3) The negation operator is often used with the bitwise AND operation to turn off a bit. x=8; flag=flag &~x; //flag &=~x will turn off the fourth bit of flag. (4) Shift operators << , >> Shift operations are often used to multiply or divide by powers of 2. x=y<<1; This statement shifts y left by one bit and then assigns it to x. The decimal value of x is equal to the value of y multiplied by 2. Similarly, shifting right by one bit is equal to the value of y divided by 2.
Keywords:MSP430 Reference address:MSP430: What does P1OUT=4, P1OUT |=4, P1OUT &-=~8 mean?

Previous article:How to turn on and off interrupts in MSP430, code and command for turning on and off interrupts
Next article:MSP430X5XX clock system and low power mode

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号