CC2530 串口接收發(fā)送數(shù)據(jù)(查詢法)#include "ioCC2530.h"
本文引用地址:http://m.butianyuan.cn/article/201611/318047.htm
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 串口接收發(fā)送(中斷法)
#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);
}
評論