您的位置 首页 芯闻

CC2530串口接纳发送数据

CC2530串口接收发送数据(查询法)#includeioCC2530.hvoidinitUART(void){PERCFG=~0x01;P0SEL

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);

}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/news/xinwen/277409.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部