CC2530 串口接收发送数据(查询法)
#include "ioCC2530.h"
void initUART(void)
{
PERCFG&=~0x01;
P0SEL |= 0x0C;
U0CSR |= 0xC0;//串口接收使能
U0UCR |= 0x00;//无奇偶校验,1位停止位
U0GCR |= 0x08;
U0BAUD = 0x3b;//波特率:9600bps
//IEN0 |=0X04;//开串口接收中断 URX0IE = 1,
}
void setSysClk(void)
{
CLKCONCMD&=0xbf;
asm("NOP");
asm("NOP");
asm("NOP");
CLKCONCMD&=0xc0;
asm("NOP");
asm("NOP");
asm("NOP");
}
void delay(void)
{
unsigned int i;
unsigned char j;
for(i=0;i<500;i++)
{
for(j=0;j<200;j++)
{
asm("NOP");
asm("NOP");
asm("NOP");
}
}
}
char receive (void)
{
char dat;
while (!URX0IF );
dat = U0DBUF;
URX0IF = 0;
return dat;
}
void send(int c)
{
U0DBUF=c;
while (!UTX0IF);
UTX0IF = 0;
}
void main()
{
setSysClk();
initUART();
while(1)
{
unsignedchar uartdat;
uartdat=receive();
uartdat=~uartdat;
send(uartdat);
}
}
-----------------------------------------------------
CC2530 串口接收发送(中断法)
#include "ioCC2530.h"
void initUART(void)
{
PERCFG&=~0x01;
P0SEL |= 0x0C;
U0CSR |= 0xC0;//串口接收使能
U0UCR |= 0x00;//无奇偶校验,1位停止位
U0GCR |= 0x08;
U0BAUD = 0x3b;//波特率:9600bps
IEN0 |=0X04;//开串口接收中断 URX0IE = 1,
EA=1;
}
void setSysClk(void)
{
CLKCONCMD&=0xbf;
asm("NOP");
asm("NOP");
asm("NOP");
CLKCONCMD&=0xc0;
asm("NOP");
asm("NOP");
asm("NOP");
}
void delay(void)
{
unsigned int i;
unsigned char j;
for(i=0;i<500;i++)
{
for(j=0;j<200;j++)
{
asm("NOP");
asm("NOP");
asm("NOP");
}
}
}
void send(int c)
{
U0DBUF=c;
while (!UTX0IF);
UTX0IF = 0;
}
void main()
{
setSysClk();
initUART();
while(1)
{
delay();
delay();
}
}
#pragma vector=URX0_VECTOR
__interrupt void URX0_IRQ(void)
{
charuartdat;
//while(!URX0IF);
//URX0IF=0;
uartdat=U0DBUF;
uartdat=~uartdat;
send(uartdat);
}