This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

cc2540f/cc2541f串口测试



   #include "ioCC2540.h"  

#pragma vector   =URX0_VECTOR

__interrupt void URX0_ISR(void) {

  URX0IF=0;    U0DBUF='B';      

     while(  !(U0CSR&0x2));    

  U0CSR=0xc0;

  U0DBUF='L';         

  while(  !(U0CSR&0x2));    

  U0CSR=0xc0;

 U0DBUF='E';       

   while(  !(U0CSR&0x2));      U0CSR=0xc0;

 

 

}

 

       void delay()    

     {unsigned long i;           for(i=0;i<10000;i++)           asm(" nop ");         }    

       void  main()         

    {    CLKCONCMD = 0x80;       // Wait until system clock source has changed to HS XOSC (CLKCONSTA.OSC = 0).  

    while(CLKCONSTA & 0x40);//外部晶振32MHz    

          P0SEL =0x0c;///发送数据的tx引脚是p03, rx p0.2      

                 P0DIR=0xff;     

       U0CSR=0xc0;       

     U0UCR=0x02;     

       U0GCR=0x08;    

        U0BAUD=59;//波特率9600   

          PERCFG=0;      

      IEN0|=0x84;//中断使能    

       EA = 1;///总中断

            while(1)               {                 U0DBUF=0xaa;         

      while(  !(U0CSR&0x2));            

              delay();               delay();               delay();           

                delay();               delay();               delay();    

               U0DBUF=0x55;               while(  !(U0CSR&0x2));             

              delay();               delay();               delay();    

                       delay();               delay();               delay();               }       

      }