CC2530串口收发

#include "iocc2530.h"
#define uint unsigned int
#define uchar unsigned char
#define led P1_0
void delay(uint t)
{
  uint i,j;
  while(t--)
  for(i=100;i>0;i--)
  for(j=587;j>0;j--);
}

void send(uchar ch)
{
  U0DBUF=ch;
  while(UTX0IF==0);
  UTX0IF=0;  
}

void sendStr(uchar *p)
{
  while(*p!='\0')
  {
    send(*p);
    p++;
  }
}


void init()
{
  P1SEL &=~(1<<0);
  P1DIR |=(1<<0);
  P0SEL|=0x0c;
  
  U0CSR |=(1<<6);
//  CLKCONCMD &=~(1<<6);
//  CLKCONCMD &=~(1<<0);
//  CLKCONCMD &=~(1<<1);
//  CLKCONCMD &=~(1<<2);
  CLKCONCMD &=~0x47;  //设置使用晶振和分频
  while(CLKCONSTA &(1<<6));//等待寄存器稳定
  
  U0CSR|=(1<<7);
  U0GCR=9;
  U0BAUD=59;
  UTX0IF=0;
  
  
  U0CSR|=(1<<6);
  URX0IF=0;
  URX0IE=1;  
  EA=1;
}
void main()
{
  init();
  while(1)
  {
    //send('k');
    //led=0;
    sendStr("Hello hahahahaha!!\r\n");
    //led=1;
    delay(20);
    
  }
}
#pragma vector= URX0_VECTOR
__interrupt void URX0ISR(void)
{
  uchar temp;
  temp=U0DBUF;
  if(temp=='o')
  {
    led=0;
  }
  if(temp=='c')
  {
    led=1;
  }
  URX0IF=0;
}

猜你喜欢

转载自blog.csdn.net/weixin_41967600/article/details/89525315