1导入库
2编写调用库
主函数C代码
#include "hal_defs.h" //硬件抽象宏定义
#include "hal_cc8051.h" //8051硬件抽象层
#include "hal_int.h" //抽象层中断控制文件
#include "hal_mcu.h" //mcu库
#include "hal_board.h" //板库
#include "hal_led.h" //led
#include "hal_rf.h" //rf
#include "basic_rf.h" //基本rf库
#include "hal_uart.h" //uart
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
uint8 uRxdata [128];//Rx缓冲
uint8 uTxdata [128];//Tx缓冲
int uRxlen;
int r_UartLen;
void MyByteCopy(uint8 *dst, int dststart, uint8 *src, int srcstart, int len)//取出数据
{
int i;
for(i=0; i<len; i++)
{
*(dst+dststart+i)=*(src+srcstart+i);//实现数组上的数据交换
}
}
uint16 RecvUartData(void)
{
uint16 r_UartLen = 0;
uint8 r_UartBuf[128];
uRxlen=0;
r_UartLen = halUartRxLen();//获取Rx的长度
while(r_UartLen > 0)
{
r_UartLen = halUartRead(r_UartBuf, sizeof(r_UartBuf));//取出串口的数据
MyByteCopy(uRxdata, uRxlen, r_UartBuf, 0, r_UartLen);//将数据给Tx
uRxlen += r_UartLen;//获取rx的长度给Tx 且Rx+1
halMcuWaitMs(5); //这里的延迟非常重要,因为这是串口连续读取数据时候需要有一定的时间间隔
r_UartLen = halUartRxLen();
}
return uRxlen;
}
int main(void){
halBoardInit();//板初始化
halLedSet(1);//led灯1
halLedSet(2);//led灯2
while(1){
int len=0;
len=RecvUartData();//看Rx是否有数据
if(len>0){
halUartWrite(uRxdata,len);//串口输出
//len=0;
}
}
}
小白的一天的成果感谢支持