/****************************************************************************************************************
*************************
*Author:JYW
*Time:2019_04_09
*Describe:LetAllLinesOfCodeSpeak
*****************************************************/
/***********************
*Describe:该程序收发字符受益良多
所以多加练习
************************/
#include<ioCC2530.h>
#include<string.h>
typedef unsigned char uchar;
typedef unsigned int uint;
#define TX_SIZE 20
#define TX_STRING "Hello"
/******************************/
while(1)
{
/*UartState默认接收状态*/
if(UartState == UART0_RX)
{
if(RxBuf != 0)
{
/*以‘#’为结束符,一次最多接收50个字符*/
if(RxBuf != '#')&&(count < 50)
{
RxData[count++] = RxBuf;
}
else
{
if(count >= 50)
{
count = 0;
memset(RxData, 0, SIZE);//清空缓冲区
}
else
UartState = UART0_TX;//进入发送状态
}
RxBuf = 0;
}
}
if(UartState == UART0TX)//发送状态
{
U0CSR 7= ~0x40;
UartSendString(RxData, count);
U0CSR |= 0x40;//允许接收
UartState = UART_RX;
count = 0;
memset(RxData, 0, SIZE);
}
}
/*******************************/
while(1)
{
if(UartState == UART0_RX)
{
if(RxBuf != 0)
{
if((RxBuf != '#')&&(count < 50))
RxData[count++] = RxBuf;
else
{
if(count >= 50)
{
count = 0;
memset(RxData,0,SIZE);
}
else
{
UartState == UART0_TX;
}
}
RxBuf = 0;
}
}
if(UartState == UART0_TX)
{
U0CSR &=0xBF; //1011 1111
UartSendString(RxData,count);//fasongshuju
U0CSR |= 0x40;
UartState = UART0_RX;
count = 0;
memset(RxData,0,SIZE);
}
}
/********************************************************/
/***********************************
/*协议栈中消息的创建*/
keyChange_t *msgptr;
msgptr = (keyChange_t *)osal_msg_allocate(sizeof(keyChange_t));
if(msgptr)
{
msgptr->hdr.event = KEY_CHANGE;//给这个消息填值
msgptr->keys = 3;
osal_msg_send(JywApp_TaskID, (uint8 *)msgptr);
}
*********************/