/****************************************************************************
* 文 件 名: main.c
* 描 述: 设置串口调试助手波特率:115200bps 8N1
* 会收到CC2530发过来的:Hello Zigbee
****************************************************************************/
#include <ioCC2530.h>
#include <string.h>
typedef unsigned char uchar;
typedef unsigned int uint;
#define TX_SIZE 20
#define TX_STRING "Hello Zigbee "
char TxData[TX_SIZE]; //存储发送字符串
/****************************************************************************
* 名 称: DelayMS()
* 功 能: 以毫秒为单位延时 16M时约为535,32M时要调整,系统时钟不修改默认为16M
* 入口参数: msec 延时参数,值越大延时越久
* 出口参数: 无
****************************************************************************/
void DelayMS(uint msec)
{
uint i,j;
for (i=0; i<msec; i++)
for (j=0; j<1070; j++);
}
/****************************************************************************
* 名 称: InitUart()
* 功 能: 串口初始化函数
* 入口参数: 无
* 出口参数: 无
****************************************************************************/
void InitUart(void)
{
PERCFG = 0x00; //外设控制寄存器 USART 0的IO位置:0为P0口位置1
P0SEL = 0x0c; //P0_2,P0_3用作串口(外设功能)
P2DIR &= ~0XC0; //P0优先作为UART0
U0CSR |= 0x80; //设置为UART方式
U0GCR |= 11;
U0BAUD |= 216; //波特率设为115200
UTX0IF = 0; //UART0 TX中断标志初始置位0
}
/****************************************************************************
* 名 称: UartSendString()
* 功 能: 串口发送函数
* 入口参数: Data:发送缓冲区 len:发送长度
* 出口参数: 无
****************************************************************************/
void UartSendString(char *Data, int len)
{
uint i;
for(i=0; i<len; i++)
{
U0DBUF = *Data++;
while(UTX0IF == 0);
UTX0IF = 0;
}
}
/****************************************************************************
* 程序入口函数
****************************************************************************/
void main(void)
{
CLKCONCMD &= ~0x40; //设置系统时钟源为32MHZ晶振
while(CLKCONSTA & 0x40); //等待晶振稳定为32M
CLKCONCMD &= ~0x47; //设置系统主时钟频率为32MHZ
InitUart(); //调置串口相关寄存器
memset(TxData, 0, TX_SIZE); //数据清0
memcpy(TxData, TX_STRING, sizeof(TX_STRING)); //复制发送字符串到TxData
while(1)
{
UartSendString(TxData, sizeof(TX_STRING)); //串口发送数据
DelayMS(1000); //延时
}
}
* 文 件 名: main.c
* 描 述: 设置串口调试助手波特率:115200bps 8N1
* 会收到CC2530发过来的:Hello Zigbee
****************************************************************************/
#include <ioCC2530.h>
#include <string.h>
typedef unsigned char uchar;
typedef unsigned int uint;
#define TX_SIZE 20
#define TX_STRING "Hello Zigbee "
char TxData[TX_SIZE]; //存储发送字符串
/****************************************************************************
* 名 称: DelayMS()
* 功 能: 以毫秒为单位延时 16M时约为535,32M时要调整,系统时钟不修改默认为16M
* 入口参数: msec 延时参数,值越大延时越久
* 出口参数: 无
****************************************************************************/
void DelayMS(uint msec)
{
uint i,j;
for (i=0; i<msec; i++)
for (j=0; j<1070; j++);
}
/****************************************************************************
* 名 称: InitUart()
* 功 能: 串口初始化函数
* 入口参数: 无
* 出口参数: 无
****************************************************************************/
void InitUart(void)
{
PERCFG = 0x00; //外设控制寄存器 USART 0的IO位置:0为P0口位置1
P0SEL = 0x0c; //P0_2,P0_3用作串口(外设功能)
P2DIR &= ~0XC0; //P0优先作为UART0
U0CSR |= 0x80; //设置为UART方式
U0GCR |= 11;
U0BAUD |= 216; //波特率设为115200
UTX0IF = 0; //UART0 TX中断标志初始置位0
}
/****************************************************************************
* 名 称: UartSendString()
* 功 能: 串口发送函数
* 入口参数: Data:发送缓冲区 len:发送长度
* 出口参数: 无
****************************************************************************/
void UartSendString(char *Data, int len)
{
uint i;
for(i=0; i<len; i++)
{
U0DBUF = *Data++;
while(UTX0IF == 0);
UTX0IF = 0;
}
}
/****************************************************************************
* 程序入口函数
****************************************************************************/
void main(void)
{
CLKCONCMD &= ~0x40; //设置系统时钟源为32MHZ晶振
while(CLKCONSTA & 0x40); //等待晶振稳定为32M
CLKCONCMD &= ~0x47; //设置系统主时钟频率为32MHZ
InitUart(); //调置串口相关寄存器
memset(TxData, 0, TX_SIZE); //数据清0
memcpy(TxData, TX_STRING, sizeof(TX_STRING)); //复制发送字符串到TxData
while(1)
{
UartSendString(TxData, sizeof(TX_STRING)); //串口发送数据
DelayMS(1000); //延时
}
}