欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: MSP430F5529LP P3.3,P3.4串口測試程序 [打印本頁]

作者: flechazo12    時間: 2021-8-6 10:38
標題: MSP430F5529LP P3.3,P3.4串口測試程序
MSP430F5529LP關于P3.3,P3.4串口測試
  1. #include <msp430.h>
  2. //#include <io430.h>
  3. void delay(int ms)        //延時函數
  4. {
  5.     int i,j;
  6.     for( i=0;i<ms;i++)
  7.     for( j=0;j<240;j++);
  8. }

  9. void send_buf(unsigned char *ptr)    //發送字符串
  10. {
  11.     while(*ptr != '\0')
  12.     {
  13.         while(!(UCA0IFG & UCTXIFG));
  14.         UCA0TXBUF = *ptr;
  15.         ptr++;
  16.         delay(50);
  17.     }
  18. }

  19. void main(void)
  20. {
  21.     WDTCTL = WDTPW + WDTHOLD;      //關閉看門狗

  22.     P4DIR |= BIT7;                               //初始化LED

  23.     //串口初始化
  24.      P3SEL    |=  BIT3+BIT4;                       // P5.6,7 = USCI_A1 TXD/RXD
  25.      UCA0CTL1 |=  UCSWRST;                      // **Put state machine in reset**
  26.      UCA0CTL1 |=  UCSSEL_1;                     // ACLK
  27.      UCA0BR0   =  0x03;                         // 32768Hz 9600 波特率為9600
  28.      UCA0BR1   =  0x00;                             // 32768Hz 9600
  29.      UCA0MCTL |=  UCBRS_3 + UCBRF_0;           // Modulation UCBRSx=1, UCBRFx=0  ok
  30.      //UCA0MCTL = UCBRS_0 + UCBRF_13 + UCOS16;
  31.      UCA0CTL1 &= ~UCSWRST;                   // **Initialize USCI state machine**
  32.      UCA0IE |=  UCRXIE;                       // Enable USCI_A1 RX interrupt 使能中斷

  33.      //S2  ok
  34.     P2IE |= BIT1;
  35.     P2IES |= BIT1;
  36.     P2IFG &= ~ BIT1;
  37.     P2REN |= BIT1;
  38.     P2OUT |= BIT1;
  39.     _EINT();                                               //中斷使能
  40.    // send_buf("串口通信\r\n");
  41.     //send_buf("jecaa\r\n");
  42.     while(1)
  43.     {
  44.         //send_buf("jecaa\r\n");
  45.         delay(500);


  46.     }
  47. }
  48. int A=0;
  49. #pragma vector = USCI_A0_VECTOR
  50. __interrupt void USCI_A0()
  51. {
  52.     A++;
  53.     switch(_even_in_range(UCA0IV,4))
  54.     {
  55.     case 0:break;                             // Vector 0 - No interrupt
  56.         case 2:                                   // Vector 2 - RXIFG
  57.            // UCA0TXBUF = UCA0RXBUF;                // 發送接收到的數據
  58.                                      // 如需對發送信息進行處理修改此處
  59.             break;
  60.      case 4:break;                             // Vector 4 - TXIFG
  61.      default: break;
  62.     }
  63. }
  64. int b=0;
  65. #pragma vector = PORT2_VECTOR
  66. __interrupt void P2_ISR()
  67. {
  68.     b++;
  69.     if(P2IFG & BIT1)
  70.     {
  71.         while((P2IN & BIT1)==0);
  72.         P4OUT ^= BIT7;
  73.         send_buf("Pressed\r\n");
  74.     }
  75.     P2IFG &=~ BIT1;
  76. }

復制代碼

代碼下載: 串口測試.zip (59.87 KB, 下載次數: 16)

作者: hanyiwei    時間: 2022-7-29 12:17
你好,請問你這個串口通信時發送字符串,是從電腦往單片機發送嗎




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1