Learn I/O first. I/O operation is the most basic, and these registers must be firmly mastered. The difficulty of MSP430 is that it has a large number of registers that need to be set. Although not every register must be mastered, I/O control registers must be remembered. This is too basic-_' Everyone should always have a schematic diagram (PCB diagram) on hand to facilitate line checking and pin configuration 1. Simple operation (setting) of general I/O 1.1 Introduction to I/O Features: ① Multiple multiplexing and settings (that is, whether to control input, output, whether to connect pull-up resistor, whether to connect pull-down resistor, whether to accept interrupt); ② In general, P1 and P2 both have interrupt capabilities. The interrupts introduced from each I/O pin of the P1 and P2 interfaces can be independently enabled and set to be triggered by the rising edge or falling edge. The corresponding interrupt vector tables are P1IV and P2IV, which can only perform word operations, and the PAIV register does not exist at all. ③P1 and P2 can be combined into PA, P3 and P4 can be combined into PB, ... PC, PD. So P1 is 8-bit BCD 0x00, and PA is 16-bit BCD 0x0000. When writing to the PA port using word operations, all 16 bits are written to this port; when writing to the low byte of the PA port using byte operations, the high byte remains unchanged; ④Since 430 has many I/O and peripheral circuit wiring, bit operations are often used here. If we define BIT0=0X01, BIT1=0X02, BIT3=0X04…BIT7=0X80 in advance (which will be used later, so we declare it here first), then when we set the output of P1.1 and P1.3 to 1, we can do this: P1OUT|=(BIT1+BIT3). This is very clear. ⑤ For unused I/O, it is better to pull it down uniformly. In addition, when the length of the read data is less than the maximum length of the port, those unused bits will be regarded as zero. 1.2 Simple configuration of I/O The configuration of 430 I/O is implemented by software, which is implemented through the corresponding configuration registers. (When using a certain I/O, be sure to configure the I/O first, otherwise it is easy to make mistakes) 1.2.1 I/O direction setting register PXDIR If P1.1 and P1.2 are set to output state, the operation is: P1DIR |= (BIT1+BIT2) is equivalent to PADIR |= (BIT1+BIT2) and is also equivalent to PADIR_L|= (BIT1+BIT2. Pull high to set it to output, pull low to set it to input (default). 1.2.2 I/O input setting register PXIN If the input of P1.1 and P1.2 is set to a low level, the operation is: P1IN &=~ (BIT1+BIT2). 1.2.3 I/O output setting register PXOUT ① When used only as a simple output: If P1.1 and P1.2 are set to output a high level, the operation is: P1OUT |= (BIT1+BIT2). ② If the pin is a normal I/O function, and is currently set to the input direction, and the pull-up/pull-down resistor register is valid. Then PXOUT can be used to configure the pull-up and pull-down resistors: Low level is a pull-down resistor; High level is a pull-up resistor; 1.2.4 Pull-up/pull-down resistor enable register PXREN Low level means the register is invalid; High level means the register is valid 1.2.5 Output drive capability setting register PXDS Weakened drive can reduce electromagnetic interference EMI, full drive will increase electromagnetic interference. The default is to weaken drive. Low level indicates weakened drive (default); High level indicates full drive; 1.2.6 Function selection register PXSEL Used to declare that the port is to be applied to the special function of the peripheral circuit (does not determine the input and output direction), the default is low level. Low level indicates ordinary I/O (default); High level indicates that the pin will have a special purpose of connecting to the peripheral circuit; For example: the development board initialization function HAL_Board.There is a program like this in c: P5SEL |= (BIT2+BIT3) (=00001100); This sentence means that P5.2 and P5.3 will have special uses. In fact, these two I/Os are connected to external high-frequency clock crystals (which must be set to input status later). In addition, it should be noted that once the PXSEL of an I/O is set high, the pin can no longer be used as an interrupt pin. In summary, a simple program application: /*Realize the flashing of the LED*/The LED is located under each touch button. For specific interfaces, please refer to the schematic diagram #include This header file contains the configuration of each register of 430 void main(void) { WDTCTL=WDTPW+WDTHOLD; //Turn off the watchdog P1DIR|=(BIT0+BIT1+BIT2+BIT3+BIT4+BIT5); //P1.0-P1.5 is output, BITX is defined in msp430.h P1OUT&=~(BIT0+BIT1+BIT2+BIT3+BIT4+BIT5); //Clear /*P1SEL=0X00; PXDS=0X00;default*/ int i=0,j=0; while(1) { ] if(i>5) i=0; else { switch(i) { case 0:P1OUT=0x01;break; case 1:P1OUT=0x02;break; case 2:P1OUT=0x04;break; case 3:P1OUT=0x08;break; case 4:P1OUT=0x10;break; case 5:P1OUT=0x20;break; } } i++; for(j=20000;j>0;j--); //Delay } }