2-msp430 Key Input Detection

Source: Internet
Author: User

In order to write an article to pave the mat-remind yourself,,,,,,

P1.0 level, varies with the level change of the P1.1 pin input

#include"io430.h"voidDelayvoid) {unsignedCharA,b,c;  for(c=167;c>0; c--)         for(b=171;b>0; b--)             for(a=1;a>0; a--);}voidMainvoid) {Wdtctl= Wdtpw + wdthold;//The watchdog is turned on by default and is turned off without using it.P1dir =0x01;//P1.0 for Output mode   while(1) {P1out=0x01;//P1.0 output High leveldelay (); P1out=0x00;//P1.0 output Low leveldelay (); }}

There is such a definition in msp430 's header file

/*-------------------------------------------------------------------------* Standard Bits *------------------- ------------------------------------------------------*/#defineBIT0 (0x0001)#defineBIT1 (0x0002)#defineBIT2 (0x0004)#defineBIT3 (0x0008)#defineBIT4 (0x0010)#defineBIT5 (0x0020)#defineBIT6 (0x0040)#defineBIT7 (0x0080)#defineBIT8 (0x0100)#defineBIT9 (0x0200)#defineBita (0x0400)#defineBITB (0x0800)#defineBITC (0x1000)#defineBITD (0x2000)#defineBITE (0x4000)#defineBITF (0x8000)

So when setting P1.0 to output mode, you can

P1dir = BIT0;

Let's say we re-configure P1.1 as input mode.

If direct p1dir = 0x0001;

If you configure P1.2 for output mode later

P1dir = 0x0005;

This can be very cumbersome because the previous PIN configuration is considered

So when you configure a PIN as the output pin,

P1dir = P1dir |    0x0001 P1.0 for output

P1dir = P1dir |    0x0004 P1.2 for output

That

P1dir = P1dir |      BIT0; P1.0 for output

P1dir = P1dir |     BIT2; P1.2 for output

That

P1dir |= BIT0; P1.0 for output

P1dir |= BIT2; P1.2 for output

P1.1 when configured as input

P1dir &= 0xFFFD; P1.1 for input

That

P1dir &= ~bit1; P1.1 for input p1dir = P1dir & (~BIT1);

See if it doesn't affect each other.

P1dir |= BIT0; P1.0 for output p1dir = 0000 0000 0000 0000 0000 0000 0000 0001

P1dir |= BIT2; P1.2 for output p1dir = 0000 0000 0000 0000 0000 0000 0000 0101

P1dir &= ~bit1; P1.1 for input p1dir = 0000 0000 0000 0000 0000 0000 0000 0101

Now it seems that the orientation is not configured as input mode

#include"io430.h"voidMainvoid ){  //Stop watchdog timer to prevent time out resetWdtctl = Wdtpw +Wdthold; P1dir|= BIT0;//P1.0 for Output//p1dir &= BIT1;//P1.1 for input------shielding//p1dir |= bit6;//-----Shielding//p1out &= ~bit6;//------ShieldingP1dir|= BIT7;//P1.7 for output-------test not affectedP1out |= BIT7;//P1.7 output High level-------test not affected     while(1)  {    if(P1IN&BIT1)//#define BIT1 (0x0002) If the P1 input register p1in 1th bit is 1 o'clock{p1out|= BIT0;//P1.0 output high, without affecting other pins    }    if(! (P1IN&BIT1))//#define BIT1 (0x0002) If the P1 input register p1in 1th bit is 0 o'clock{p1out&= ~bit0;//P1.0 output low, without affecting other pins    }  }}

2-msp430 Key Input Detection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.