|
@@ -1,6 +1,48 @@
|
|
|
#define __UART_DEF
|
|
#define __UART_DEF
|
|
|
#include "ABIS_User.h"
|
|
#include "ABIS_User.h"
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+#include <stdarg.h>
|
|
|
|
|
+#include <stdio.h>
|
|
|
|
|
+#include <string.h>
|
|
|
|
|
+
|
|
|
|
|
+unsigned int gloublePrintLevel = 4;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+/****************************************************************
|
|
|
|
|
+* 函数名: Van_Device_Printf
|
|
|
|
|
+* 创建时间: 2021/04/22
|
|
|
|
|
+* 创建人: 范义东
|
|
|
|
|
+* 函数说明:调试打印接口函数
|
|
|
|
|
+* 输入参数: dev 传 NULL 采用本地定义
|
|
|
|
|
+ devNum 数码
|
|
|
|
|
+* 输出参数: *name
|
|
|
|
|
+* 返回值 : void
|
|
|
|
|
+****************************************************************/
|
|
|
|
|
+void Van_Device_Printf(unsigned int printLevel, const char *cmd, ...)
|
|
|
|
|
+{
|
|
|
|
|
+ char buf[128] = {};
|
|
|
|
|
+ int buflen = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if (gloublePrintLevel >= printLevel)
|
|
|
|
|
+ {
|
|
|
|
|
+ va_list args; //定义一个va_list类型的变量,用来储存单个参数
|
|
|
|
|
+ va_start(args, cmd); //使args指向可变参数的第一个参数
|
|
|
|
|
+ vsprintf(buf, cmd, args); //必须用vprintf等带V的
|
|
|
|
|
+ va_end(args); //结束可变参数的获取
|
|
|
|
|
+ buflen = strlen((const char *)buf);
|
|
|
|
|
+ for(unsigned int i=0; i<buflen; i++){
|
|
|
|
|
+ g_ucU3TX_Data[i] = buf[i];
|
|
|
|
|
+ }
|
|
|
|
|
+ if(buflen==0)return;
|
|
|
|
|
+ while(DMA2CONbits.CHEN);
|
|
|
|
|
+ DMA2CNT=(buflen-1);
|
|
|
|
|
+ DMA2CONbits.CHEN = 1;
|
|
|
|
|
+ DMA2REQbits.FORCE = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ return;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/*******************************************************************************
|
|
/*******************************************************************************
|
|
|
* 函数名称:InitUart1
|
|
* 函数名称:InitUart1
|
|
|
*******************************************************************************/
|
|
*******************************************************************************/
|
|
@@ -1657,274 +1699,274 @@ void my_send_char(char ch){
|
|
|
|
|
|
|
|
// 返回值为打印字符的个数
|
|
// 返回值为打印字符的个数
|
|
|
// 支持%d,%o, %x,%s,%c,%f(只打印6位数字)
|
|
// 支持%d,%o, %x,%s,%c,%f(只打印6位数字)
|
|
|
-int my_printf(const char* str, ...)
|
|
|
|
|
-{
|
|
|
|
|
- if (str == NULL) return -1;
|
|
|
|
|
-
|
|
|
|
|
- uint32_t ret_num = 0;// 返回打印字符的个数
|
|
|
|
|
- char* pStr = (char*)str;// 指向str
|
|
|
|
|
- int ArgIntVal = 0; // 接收整型
|
|
|
|
|
- uint32_t ArgHexVal = 0;// 接十六进制
|
|
|
|
|
- char* ArgStrVal = NULL; // 接收字符型
|
|
|
|
|
- double ArgFloVal = 0.0; // 接受浮点型
|
|
|
|
|
- uint32_t val_seg = 0; // 数据切分
|
|
|
|
|
- uint32_t val_temp = 0; // 临时保存数据
|
|
|
|
|
- int cnt = 0; // 数据长度计数
|
|
|
|
|
- int cnt_float = 0; // 数据长度计数
|
|
|
|
|
- int i = 0;
|
|
|
|
|
-
|
|
|
|
|
- va_list pArgs; // 定义va_list类型指针,用于存储参数的地址
|
|
|
|
|
- va_start(pArgs, str); // 初始化pArgs
|
|
|
|
|
- if(g_ucU3TX_Last > 0){
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
- while (*pStr != '\0')
|
|
|
|
|
- {
|
|
|
|
|
- switch (*pStr)
|
|
|
|
|
- {
|
|
|
|
|
- case ' ':
|
|
|
|
|
- case '\r':
|
|
|
|
|
- case '\n':
|
|
|
|
|
- my_send_char(*pStr); ret_num++; break;
|
|
|
|
|
- case '\t':
|
|
|
|
|
- my_send_char(*pStr); ret_num += 4; break;
|
|
|
|
|
- case '%':
|
|
|
|
|
- pStr++;
|
|
|
|
|
- // % 格式解析
|
|
|
|
|
-
|
|
|
|
|
- if('.' == *pStr)
|
|
|
|
|
- {
|
|
|
|
|
- pStr++;
|
|
|
|
|
- cnt_float = *pStr - '0';// %.Nf,输出指定位数小数
|
|
|
|
|
- pStr++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- switch (*pStr)
|
|
|
|
|
- {
|
|
|
|
|
- case '%':
|
|
|
|
|
- my_send_char('%');// %%,输出%
|
|
|
|
|
- ret_num++;
|
|
|
|
|
- pStr++;
|
|
|
|
|
- continue;
|
|
|
|
|
- case 'c':
|
|
|
|
|
- ArgIntVal = va_arg(pArgs, int);// %c,输出char
|
|
|
|
|
- my_send_char((char)ArgIntVal);
|
|
|
|
|
- ret_num++;
|
|
|
|
|
- pStr++;
|
|
|
|
|
- continue;
|
|
|
|
|
- case 'd':
|
|
|
|
|
- // 接收整型
|
|
|
|
|
- ArgIntVal = va_arg(pArgs, int);
|
|
|
|
|
- if (ArgIntVal < 0)// 如果为负数打印,负号
|
|
|
|
|
- {
|
|
|
|
|
- ArgIntVal = -ArgIntVal;// 取相反数
|
|
|
|
|
-
|
|
|
|
|
- my_send_char('-');
|
|
|
|
|
- ret_num++;
|
|
|
|
|
- }
|
|
|
|
|
- val_seg = ArgIntVal;// 赋值给 val_seg处理数据
|
|
|
|
|
- // 计算ArgIntVal长度
|
|
|
|
|
- if (ArgIntVal)
|
|
|
|
|
- {
|
|
|
|
|
- while (val_seg) {
|
|
|
|
|
- cnt++;
|
|
|
|
|
- val_seg /= 10;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else cnt = 1;// 数字0的长度为1
|
|
|
|
|
-
|
|
|
|
|
- ret_num += cnt;// 字符个数加上整数的长度
|
|
|
|
|
-
|
|
|
|
|
- // 将整数转为单个字符打印
|
|
|
|
|
- while (cnt)
|
|
|
|
|
- {
|
|
|
|
|
- val_seg = ArgIntVal / m_pow_n(10, cnt - 1);
|
|
|
|
|
- ArgIntVal %= m_pow_n(10, cnt - 1);
|
|
|
|
|
- my_send_char((char)val_seg + '0');
|
|
|
|
|
- cnt--;
|
|
|
|
|
- }
|
|
|
|
|
- pStr++;
|
|
|
|
|
- continue;
|
|
|
|
|
- case 'o':
|
|
|
|
|
- // 接收整型
|
|
|
|
|
- ArgIntVal = va_arg(pArgs, int);
|
|
|
|
|
- if (ArgIntVal < 0)// 如果为负数打印,负号
|
|
|
|
|
- {
|
|
|
|
|
- ArgIntVal = -ArgIntVal;// 取相反数
|
|
|
|
|
-
|
|
|
|
|
- my_send_char('-');
|
|
|
|
|
- ret_num++;
|
|
|
|
|
- }
|
|
|
|
|
- val_seg = ArgIntVal;// 赋值给 val_seg处理数据
|
|
|
|
|
- // 计算ArgIntVal长度
|
|
|
|
|
- if (ArgIntVal)
|
|
|
|
|
- {
|
|
|
|
|
- while (val_seg) {
|
|
|
|
|
- cnt++;
|
|
|
|
|
- val_seg /= 8;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else cnt = 1;// 数字0的长度为1
|
|
|
|
|
-
|
|
|
|
|
- ret_num += cnt;// 字符个数加上整数的长度
|
|
|
|
|
-
|
|
|
|
|
- // 将整数转为单个字符打印
|
|
|
|
|
- while (cnt)
|
|
|
|
|
- {
|
|
|
|
|
- val_seg = ArgIntVal / m_pow_n(8, cnt - 1);
|
|
|
|
|
- ArgIntVal %= m_pow_n(8, cnt - 1);
|
|
|
|
|
- my_send_char((char)val_seg + '0');
|
|
|
|
|
- cnt--;
|
|
|
|
|
- }
|
|
|
|
|
- pStr++;
|
|
|
|
|
- continue;
|
|
|
|
|
- case 'x':
|
|
|
|
|
- // 接收16进制
|
|
|
|
|
- ArgHexVal = va_arg(pArgs, uint32_t);
|
|
|
|
|
- val_seg = ArgHexVal;
|
|
|
|
|
- // 计算ArgIntVal长度
|
|
|
|
|
- if (ArgHexVal)
|
|
|
|
|
- {
|
|
|
|
|
- while (val_seg) {
|
|
|
|
|
- cnt++;
|
|
|
|
|
- val_seg /= 16;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else cnt = 1;// 数字0的长度为1
|
|
|
|
|
-
|
|
|
|
|
- ret_num += cnt;// 字符个数加上整数的长度
|
|
|
|
|
- // 将整数转为单个字符打印
|
|
|
|
|
- while (cnt)
|
|
|
|
|
- {
|
|
|
|
|
- val_seg = ArgHexVal / m_pow_n(16, cnt - 1);
|
|
|
|
|
- ArgHexVal %= m_pow_n(16, cnt - 1);
|
|
|
|
|
- if (val_seg <= 9)
|
|
|
|
|
- my_send_char((char)val_seg + '0');
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- //my_send_char((char)val_seg - 10 + 'a'); //小写字母
|
|
|
|
|
- my_send_char((char)val_seg - 10 + 'A');
|
|
|
|
|
- }
|
|
|
|
|
- cnt--;
|
|
|
|
|
- }
|
|
|
|
|
- pStr++;
|
|
|
|
|
- continue;
|
|
|
|
|
- case 'b':
|
|
|
|
|
- // 接收整型
|
|
|
|
|
- ArgIntVal = va_arg(pArgs, int);
|
|
|
|
|
- val_seg = ArgIntVal;
|
|
|
|
|
- // 计算ArgIntVal长度
|
|
|
|
|
- if (ArgIntVal)
|
|
|
|
|
- {
|
|
|
|
|
- while (val_seg) {
|
|
|
|
|
- cnt++;
|
|
|
|
|
- val_seg /= 2;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else cnt = 1;// 数字0的长度为1
|
|
|
|
|
-
|
|
|
|
|
- ret_num += cnt;// 字符个数加上整数的长度
|
|
|
|
|
- // 将整数转为单个字符打印
|
|
|
|
|
- while (cnt)
|
|
|
|
|
- {
|
|
|
|
|
- val_seg = ArgIntVal / m_pow_n(2, cnt - 1);
|
|
|
|
|
- ArgIntVal %= m_pow_n(2, cnt - 1);
|
|
|
|
|
- my_send_char((char)val_seg + '0');
|
|
|
|
|
- cnt--;
|
|
|
|
|
- }
|
|
|
|
|
- pStr++;
|
|
|
|
|
- continue;
|
|
|
|
|
- case 's':
|
|
|
|
|
- // 接收字符
|
|
|
|
|
- ArgStrVal = va_arg(pArgs, char*);
|
|
|
|
|
- ret_num += (uint32_t)strlen(ArgStrVal);
|
|
|
|
|
- while (*ArgStrVal)
|
|
|
|
|
- {
|
|
|
|
|
- my_send_char(*ArgStrVal);
|
|
|
|
|
- ArgStrVal++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- pStr++;
|
|
|
|
|
- continue;
|
|
|
|
|
-
|
|
|
|
|
- case 'f':
|
|
|
|
|
- // 接收浮点型 保留6为小数,不采取四舍五入
|
|
|
|
|
- ArgFloVal = va_arg(pArgs, double);
|
|
|
|
|
-
|
|
|
|
|
- if (ArgFloVal < 0)// 如果为负数打印,负号
|
|
|
|
|
- {
|
|
|
|
|
- ArgFloVal = -ArgFloVal;// 取相反数
|
|
|
|
|
-
|
|
|
|
|
- my_send_char('-');
|
|
|
|
|
- ret_num++;
|
|
|
|
|
- }
|
|
|
|
|
- val_seg = (uint32_t)ArgFloVal;// 取整数部分
|
|
|
|
|
- val_temp = val_seg; // 临时保存整数部分数据
|
|
|
|
|
- ArgFloVal = ArgFloVal - val_seg;// 得出余下的小数部分
|
|
|
|
|
- // 计算整数部分长度
|
|
|
|
|
- if (val_seg)
|
|
|
|
|
- {
|
|
|
|
|
- while (val_seg) {
|
|
|
|
|
- cnt++;
|
|
|
|
|
- val_seg /= 10;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else cnt = 1;// 数字0的长度为1
|
|
|
|
|
- ret_num += cnt;// 字符个数加上整数的长度
|
|
|
|
|
- // 将整数转为单个字符打印
|
|
|
|
|
- while (cnt)
|
|
|
|
|
- {
|
|
|
|
|
- val_seg = val_temp / m_pow_n(10, cnt - 1);
|
|
|
|
|
- val_temp %= m_pow_n(10, cnt - 1);
|
|
|
|
|
- my_send_char((char)val_seg + '0');
|
|
|
|
|
- cnt--;
|
|
|
|
|
- }
|
|
|
|
|
- // 打印小数点
|
|
|
|
|
- my_send_char('.');
|
|
|
|
|
- ret_num++;
|
|
|
|
|
- // printf("\r\n %f\r\n", ArgFloVal);
|
|
|
|
|
- if(cnt_float == 0)
|
|
|
|
|
- cnt_float = 6;
|
|
|
|
|
-
|
|
|
|
|
- // 开始输出小数部分
|
|
|
|
|
- //ArgFloVal *= 1000000;
|
|
|
|
|
- ArgFloVal *= m_pow_n(10, cnt_float);
|
|
|
|
|
-
|
|
|
|
|
- val_temp = (int)ArgFloVal;// 取整数部分
|
|
|
|
|
- while (cnt_float)
|
|
|
|
|
- {
|
|
|
|
|
- val_seg = val_temp / m_pow_n(10, cnt_float - 1);
|
|
|
|
|
- val_temp %= m_pow_n(10, cnt_float - 1);
|
|
|
|
|
- my_send_char((char)val_seg + '0');
|
|
|
|
|
- cnt_float--;
|
|
|
|
|
- }
|
|
|
|
|
- ret_num += 6;
|
|
|
|
|
- pStr++;
|
|
|
|
|
- continue;
|
|
|
|
|
- default:// % 匹配错误,暂输出空格
|
|
|
|
|
- my_send_char(' '); ret_num++;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- break;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- default:
|
|
|
|
|
- my_send_char(*pStr); ret_num++;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- pStr++;
|
|
|
|
|
- }
|
|
|
|
|
- va_end(pArgs);// 结束取参数
|
|
|
|
|
-
|
|
|
|
|
- for(int i;i<ret_num;i++){
|
|
|
|
|
- g_ucU3TX_Data[i] = g_ucU3TX_buf[i];
|
|
|
|
|
- }
|
|
|
|
|
- g_ucU3TX_Last = 0;
|
|
|
|
|
- while(DMA2CONbits.CHEN);
|
|
|
|
|
- DMA2CNT=(ret_num-1);
|
|
|
|
|
- DMA2CONbits.CHEN = 1;
|
|
|
|
|
- DMA2REQbits.FORCE = 1;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- return ret_num;
|
|
|
|
|
-}
|
|
|
|
|
|
|
+//int my_printf(const char* str, ...)
|
|
|
|
|
+//{
|
|
|
|
|
+// if (str == NULL) return -1;
|
|
|
|
|
+//
|
|
|
|
|
+// uint32_t ret_num = 0;// 返回打印字符的个数
|
|
|
|
|
+// char* pStr = (char*)str;// 指向str
|
|
|
|
|
+// int ArgIntVal = 0; // 接收整型
|
|
|
|
|
+// uint32_t ArgHexVal = 0;// 接十六进制
|
|
|
|
|
+// char* ArgStrVal = NULL; // 接收字符型
|
|
|
|
|
+// double ArgFloVal = 0.0; // 接受浮点型
|
|
|
|
|
+// uint32_t val_seg = 0; // 数据切分
|
|
|
|
|
+// uint32_t val_temp = 0; // 临时保存数据
|
|
|
|
|
+// int cnt = 0; // 数据长度计数
|
|
|
|
|
+// int cnt_float = 0; // 数据长度计数
|
|
|
|
|
+// int i = 0;
|
|
|
|
|
+//
|
|
|
|
|
+// va_list pArgs; // 定义va_list类型指针,用于存储参数的地址
|
|
|
|
|
+// va_start(pArgs, str); // 初始化pArgs
|
|
|
|
|
+// if(g_ucU3TX_Last > 0){
|
|
|
|
|
+// return 0;
|
|
|
|
|
+// }
|
|
|
|
|
+// while (*pStr != '\0')
|
|
|
|
|
+// {
|
|
|
|
|
+// switch (*pStr)
|
|
|
|
|
+// {
|
|
|
|
|
+// case ' ':
|
|
|
|
|
+// case '\r':
|
|
|
|
|
+// case '\n':
|
|
|
|
|
+// my_send_char(*pStr); ret_num++; break;
|
|
|
|
|
+// case '\t':
|
|
|
|
|
+// my_send_char(*pStr); ret_num += 4; break;
|
|
|
|
|
+// case '%':
|
|
|
|
|
+// pStr++;
|
|
|
|
|
+// // % 格式解析
|
|
|
|
|
+//
|
|
|
|
|
+// if('.' == *pStr)
|
|
|
|
|
+// {
|
|
|
|
|
+// pStr++;
|
|
|
|
|
+// cnt_float = *pStr - '0';// %.Nf,输出指定位数小数
|
|
|
|
|
+// pStr++;
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// switch (*pStr)
|
|
|
|
|
+// {
|
|
|
|
|
+// case '%':
|
|
|
|
|
+// my_send_char('%');// %%,输出%
|
|
|
|
|
+// ret_num++;
|
|
|
|
|
+// pStr++;
|
|
|
|
|
+// continue;
|
|
|
|
|
+// case 'c':
|
|
|
|
|
+// ArgIntVal = va_arg(pArgs, int);// %c,输出char
|
|
|
|
|
+// my_send_char((char)ArgIntVal);
|
|
|
|
|
+// ret_num++;
|
|
|
|
|
+// pStr++;
|
|
|
|
|
+// continue;
|
|
|
|
|
+// case 'd':
|
|
|
|
|
+// // 接收整型
|
|
|
|
|
+// ArgIntVal = va_arg(pArgs, int);
|
|
|
|
|
+// if (ArgIntVal < 0)// 如果为负数打印,负号
|
|
|
|
|
+// {
|
|
|
|
|
+// ArgIntVal = -ArgIntVal;// 取相反数
|
|
|
|
|
+//
|
|
|
|
|
+// my_send_char('-');
|
|
|
|
|
+// ret_num++;
|
|
|
|
|
+// }
|
|
|
|
|
+// val_seg = ArgIntVal;// 赋值给 val_seg处理数据
|
|
|
|
|
+// // 计算ArgIntVal长度
|
|
|
|
|
+// if (ArgIntVal)
|
|
|
|
|
+// {
|
|
|
|
|
+// while (val_seg) {
|
|
|
|
|
+// cnt++;
|
|
|
|
|
+// val_seg /= 10;
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// else cnt = 1;// 数字0的长度为1
|
|
|
|
|
+//
|
|
|
|
|
+// ret_num += cnt;// 字符个数加上整数的长度
|
|
|
|
|
+//
|
|
|
|
|
+// // 将整数转为单个字符打印
|
|
|
|
|
+// while (cnt)
|
|
|
|
|
+// {
|
|
|
|
|
+// val_seg = ArgIntVal / m_pow_n(10, cnt - 1);
|
|
|
|
|
+// ArgIntVal %= m_pow_n(10, cnt - 1);
|
|
|
|
|
+// my_send_char((char)val_seg + '0');
|
|
|
|
|
+// cnt--;
|
|
|
|
|
+// }
|
|
|
|
|
+// pStr++;
|
|
|
|
|
+// continue;
|
|
|
|
|
+// case 'o':
|
|
|
|
|
+// // 接收整型
|
|
|
|
|
+// ArgIntVal = va_arg(pArgs, int);
|
|
|
|
|
+// if (ArgIntVal < 0)// 如果为负数打印,负号
|
|
|
|
|
+// {
|
|
|
|
|
+// ArgIntVal = -ArgIntVal;// 取相反数
|
|
|
|
|
+//
|
|
|
|
|
+// my_send_char('-');
|
|
|
|
|
+// ret_num++;
|
|
|
|
|
+// }
|
|
|
|
|
+// val_seg = ArgIntVal;// 赋值给 val_seg处理数据
|
|
|
|
|
+// // 计算ArgIntVal长度
|
|
|
|
|
+// if (ArgIntVal)
|
|
|
|
|
+// {
|
|
|
|
|
+// while (val_seg) {
|
|
|
|
|
+// cnt++;
|
|
|
|
|
+// val_seg /= 8;
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// else cnt = 1;// 数字0的长度为1
|
|
|
|
|
+//
|
|
|
|
|
+// ret_num += cnt;// 字符个数加上整数的长度
|
|
|
|
|
+//
|
|
|
|
|
+// // 将整数转为单个字符打印
|
|
|
|
|
+// while (cnt)
|
|
|
|
|
+// {
|
|
|
|
|
+// val_seg = ArgIntVal / m_pow_n(8, cnt - 1);
|
|
|
|
|
+// ArgIntVal %= m_pow_n(8, cnt - 1);
|
|
|
|
|
+// my_send_char((char)val_seg + '0');
|
|
|
|
|
+// cnt--;
|
|
|
|
|
+// }
|
|
|
|
|
+// pStr++;
|
|
|
|
|
+// continue;
|
|
|
|
|
+// case 'x':
|
|
|
|
|
+// // 接收16进制
|
|
|
|
|
+// ArgHexVal = va_arg(pArgs, uint32_t);
|
|
|
|
|
+// val_seg = ArgHexVal;
|
|
|
|
|
+// // 计算ArgIntVal长度
|
|
|
|
|
+// if (ArgHexVal)
|
|
|
|
|
+// {
|
|
|
|
|
+// while (val_seg) {
|
|
|
|
|
+// cnt++;
|
|
|
|
|
+// val_seg /= 16;
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// else cnt = 1;// 数字0的长度为1
|
|
|
|
|
+//
|
|
|
|
|
+// ret_num += cnt;// 字符个数加上整数的长度
|
|
|
|
|
+// // 将整数转为单个字符打印
|
|
|
|
|
+// while (cnt)
|
|
|
|
|
+// {
|
|
|
|
|
+// val_seg = ArgHexVal / m_pow_n(16, cnt - 1);
|
|
|
|
|
+// ArgHexVal %= m_pow_n(16, cnt - 1);
|
|
|
|
|
+// if (val_seg <= 9)
|
|
|
|
|
+// my_send_char((char)val_seg + '0');
|
|
|
|
|
+// else
|
|
|
|
|
+// {
|
|
|
|
|
+// //my_send_char((char)val_seg - 10 + 'a'); //小写字母
|
|
|
|
|
+// my_send_char((char)val_seg - 10 + 'A');
|
|
|
|
|
+// }
|
|
|
|
|
+// cnt--;
|
|
|
|
|
+// }
|
|
|
|
|
+// pStr++;
|
|
|
|
|
+// continue;
|
|
|
|
|
+// case 'b':
|
|
|
|
|
+// // 接收整型
|
|
|
|
|
+// ArgIntVal = va_arg(pArgs, int);
|
|
|
|
|
+// val_seg = ArgIntVal;
|
|
|
|
|
+// // 计算ArgIntVal长度
|
|
|
|
|
+// if (ArgIntVal)
|
|
|
|
|
+// {
|
|
|
|
|
+// while (val_seg) {
|
|
|
|
|
+// cnt++;
|
|
|
|
|
+// val_seg /= 2;
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// else cnt = 1;// 数字0的长度为1
|
|
|
|
|
+//
|
|
|
|
|
+// ret_num += cnt;// 字符个数加上整数的长度
|
|
|
|
|
+// // 将整数转为单个字符打印
|
|
|
|
|
+// while (cnt)
|
|
|
|
|
+// {
|
|
|
|
|
+// val_seg = ArgIntVal / m_pow_n(2, cnt - 1);
|
|
|
|
|
+// ArgIntVal %= m_pow_n(2, cnt - 1);
|
|
|
|
|
+// my_send_char((char)val_seg + '0');
|
|
|
|
|
+// cnt--;
|
|
|
|
|
+// }
|
|
|
|
|
+// pStr++;
|
|
|
|
|
+// continue;
|
|
|
|
|
+// case 's':
|
|
|
|
|
+// // 接收字符
|
|
|
|
|
+// ArgStrVal = va_arg(pArgs, char*);
|
|
|
|
|
+// ret_num += (uint32_t)strlen(ArgStrVal);
|
|
|
|
|
+// while (*ArgStrVal)
|
|
|
|
|
+// {
|
|
|
|
|
+// my_send_char(*ArgStrVal);
|
|
|
|
|
+// ArgStrVal++;
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// pStr++;
|
|
|
|
|
+// continue;
|
|
|
|
|
+//
|
|
|
|
|
+// case 'f':
|
|
|
|
|
+// // 接收浮点型 保留6为小数,不采取四舍五入
|
|
|
|
|
+// ArgFloVal = va_arg(pArgs, double);
|
|
|
|
|
+//
|
|
|
|
|
+// if (ArgFloVal < 0)// 如果为负数打印,负号
|
|
|
|
|
+// {
|
|
|
|
|
+// ArgFloVal = -ArgFloVal;// 取相反数
|
|
|
|
|
+//
|
|
|
|
|
+// my_send_char('-');
|
|
|
|
|
+// ret_num++;
|
|
|
|
|
+// }
|
|
|
|
|
+// val_seg = (uint32_t)ArgFloVal;// 取整数部分
|
|
|
|
|
+// val_temp = val_seg; // 临时保存整数部分数据
|
|
|
|
|
+// ArgFloVal = ArgFloVal - val_seg;// 得出余下的小数部分
|
|
|
|
|
+// // 计算整数部分长度
|
|
|
|
|
+// if (val_seg)
|
|
|
|
|
+// {
|
|
|
|
|
+// while (val_seg) {
|
|
|
|
|
+// cnt++;
|
|
|
|
|
+// val_seg /= 10;
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// else cnt = 1;// 数字0的长度为1
|
|
|
|
|
+// ret_num += cnt;// 字符个数加上整数的长度
|
|
|
|
|
+// // 将整数转为单个字符打印
|
|
|
|
|
+// while (cnt)
|
|
|
|
|
+// {
|
|
|
|
|
+// val_seg = val_temp / m_pow_n(10, cnt - 1);
|
|
|
|
|
+// val_temp %= m_pow_n(10, cnt - 1);
|
|
|
|
|
+// my_send_char((char)val_seg + '0');
|
|
|
|
|
+// cnt--;
|
|
|
|
|
+// }
|
|
|
|
|
+// // 打印小数点
|
|
|
|
|
+// my_send_char('.');
|
|
|
|
|
+// ret_num++;
|
|
|
|
|
+// // printf("\r\n %f\r\n", ArgFloVal);
|
|
|
|
|
+// if(cnt_float == 0)
|
|
|
|
|
+// cnt_float = 6;
|
|
|
|
|
+//
|
|
|
|
|
+// // 开始输出小数部分
|
|
|
|
|
+// //ArgFloVal *= 1000000;
|
|
|
|
|
+// ArgFloVal *= m_pow_n(10, cnt_float);
|
|
|
|
|
+//
|
|
|
|
|
+// val_temp = (int)ArgFloVal;// 取整数部分
|
|
|
|
|
+// while (cnt_float)
|
|
|
|
|
+// {
|
|
|
|
|
+// val_seg = val_temp / m_pow_n(10, cnt_float - 1);
|
|
|
|
|
+// val_temp %= m_pow_n(10, cnt_float - 1);
|
|
|
|
|
+// my_send_char((char)val_seg + '0');
|
|
|
|
|
+// cnt_float--;
|
|
|
|
|
+// }
|
|
|
|
|
+// ret_num += 6;
|
|
|
|
|
+// pStr++;
|
|
|
|
|
+// continue;
|
|
|
|
|
+// default:// % 匹配错误,暂输出空格
|
|
|
|
|
+// my_send_char(' '); ret_num++;
|
|
|
|
|
+// break;
|
|
|
|
|
+// }
|
|
|
|
|
+// break;
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// default:
|
|
|
|
|
+// my_send_char(*pStr); ret_num++;
|
|
|
|
|
+// break;
|
|
|
|
|
+// }
|
|
|
|
|
+// pStr++;
|
|
|
|
|
+// }
|
|
|
|
|
+// va_end(pArgs);// 结束取参数
|
|
|
|
|
+//
|
|
|
|
|
+// for(int i;i<ret_num;i++){
|
|
|
|
|
+// g_ucU3TX_Data[i] = g_ucU3TX_buf[i];
|
|
|
|
|
+// }
|
|
|
|
|
+// g_ucU3TX_Last = 0;
|
|
|
|
|
+// while(DMA2CONbits.CHEN);
|
|
|
|
|
+// DMA2CNT=(ret_num-1);
|
|
|
|
|
+// DMA2CONbits.CHEN = 1;
|
|
|
|
|
+// DMA2REQbits.FORCE = 1;
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// return ret_num;
|
|
|
|
|
+//}
|