载入中...

公告
载入中...

我的分类(专题)

载入中...


最新日志
载入中...

最新回复
载入中...

留言板
载入中...

统计
载入中...

链接

站长个人入口

CC2430/CC2431源代码:串口0的应用-发数据
c51rf2 发表于 2008-5-30 10:20:00

//cd wxl      串口0发数据

//说明:本实验在成都无线龙提供的CC2430模块中调试通过。http://www.c51rf.com


#i nclude <ioCC2430.h>
#i nclude <string.h>

#define uint unsigned int
#define uchar unsigned char

//定义控制灯的端口
#define led1 P1_0
#define led2 P1_1

//函数声明
void Delay(uint);
void initUARTtest(void);
void UartTX_Send_String(char *Data,int len);


char Txdata[30]=" ChenDu WuXianLong TongXun ";

/****************************************************************
*函数功能 :延时      
*入口参数 :定性延时         
*返 回 值 :无            
*说    明 :             
****************************************************************/
void Delay(uint n)
{
uint i;
for(i=0;i<n;i++);
for(i=0;i<n;i++);
for(i=0;i<n;i++);
for(i=0;i<n;i++);
for(i=0;i<n;i++);
}

/****************************************************************
*函数功能 :初始化串口1          
*入口参数 :无            
*返 回 值 :无       
*说    明 :57600-8-n-1      
****************************************************************/
void initUARTtest(void)
{

    CLKCON &= ~0x40;              //晶振
    while(!(SLEEP & 0x40));      //等待晶振稳定
    CLKCON &= ~0x47;             //TICHSPD128分频,CLKSPD不分频
    SLEEP |= 0x04;    //关闭不用的RC振荡器

    PERCFG = 0x00;     //位置1 P0口
    P0SEL = 0x3c;     //P0用作串口
    P2DIR &= ~0XC0;                             //P0优先作为串口0

    U0CSR |= 0x80;     //UART方式
    U0GCR |= 10;     //baud_e
    U0BAUD |= 216;     //波特率设为57600
    UTX0IF = 0;
}

/****************************************************************
*函数功能 :串口发送字符串函数     
*入口参数 : data:数据         
*    len :数据长度       
*返 回 值 :无           
*说    明 :    
****************************************************************/
void UartTX_Send_String(char *Data,int len)
{
int j;
for(j=0;j<len;j++)
{
    U0DBUF = *Data++;
    while(UTX0IF == 0);
    UTX0IF = 0;
}
}


/****************************************************************
*函数功能 :主函数        
*入口参数 :无       
*返 回 值 :无      
*说    明 :无       
****************************************************************/
void main(void)
{
uchar i;
        //P1 out
P1DIR = 0x03;      //P1控制LED
led1 = 0;
led2 = 1;     //关LED

initUARTtest();
UartTX_Send_String(Txdata,29);         //wu xian long tong xun

        for(i=0;i<30;i++)Txdata[i]=' ';

        strcpy(Txdata,"UART0 TX test ");       //将UART0 TX test赋给Txdata;

while(1)
{
           UartTX_Send_String(Txdata,sizeof("UART0 TX Test")); //串口发送数据
            Delay(50000);                     //延时
            Delay(50000);
            Delay(50000);
}
}


阅读全文 | 回复(0) | 引用通告 | 编辑

  • 标签:CC2430 Zigbee 
  • 发表评论:
    载入中...