You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
228 lines
6.5 KiB
228 lines
6.5 KiB
//////////////////////////////////////////////////////////////////////////
|
|
/// COPYRIGHT NOTICE
|
|
/// Copyright (c) 2015, 传控科技
|
|
/// All rights reserved.
|
|
///
|
|
/// @file main.c
|
|
/// @brief main app
|
|
///
|
|
///(本文件实现的功能的详述)
|
|
///
|
|
/// @version 1.1 CCsens technology
|
|
/// @author CC
|
|
/// @date 20150102
|
|
///
|
|
///
|
|
/// 修订说明:最初版本
|
|
/// Modified by:
|
|
/// Modified date:
|
|
/// Version:
|
|
/// Descriptions:
|
|
// 20160413 CC-ACC-VH02
|
|
// 连接至 J22 RXD0 TXD0
|
|
//P5_DIR &= ~BIT1; //p5.1输出TXD
|
|
//P5_DIR |= BIT0; //p5.0输入RXD
|
|
//P5_SEL0 &= ~(BIT0 +BIT1); //设置P5.0 P5.1为UART0 RXD TXD
|
|
//P5_SEL1 |= BIT0 +BIT1;
|
|
|
|
/*****************************************************************************
|
|
update by cc @201700110
|
|
针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是
|
|
个需要平衡的事情.
|
|
|
|
clib/clib.c:
|
|
公用的函数 和硬件无关
|
|
放置串行模式(串口等其他通讯总线类的输出)输出的函数,
|
|
一些覆盖模式输出的(lcd等固屏输出的)的也可使用
|
|
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...)
|
|
-----------------------------------------------------------------------------------------
|
|
uartcom/Uprotocol2app
|
|
协议到应用
|
|
为了适应不同的通讯协议需要不同的uart口来对应 和应用相关
|
|
|
|
typedef struct _ts_lcm_pro_; 应用协议包的定义? LCM的协议------------
|
|
L3_UARTcom0_exp_protocol 解析应用协议
|
|
-----------------------------------------------------------------------------------------
|
|
uartcom/urec2protocol: 接收到的数据放入到指向特定协议的缓存中,和协议的格式有关 一般分为 标头式或者标尾式
|
|
公用的串口通讯定义
|
|
struct _s_protocol_ 的公共协议包(关键的结构体)的声明------struct _s_protocol_
|
|
void L1_uart_2buf(struct _s_protocol_ *p)串行数据保存到指向特定协议的缓冲中
|
|
--------------------------------------------------------------------------------------------
|
|
msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面
|
|
L0_UART0_Init
|
|
UART0_IRQHandler
|
|
L0_Usend_uc------UserDef
|
|
-----------------------------------------------------------------------------------------
|
|
********************************************************************************/
|
|
#include "uart0.h"
|
|
struct _s_protocol_ s_at0;
|
|
|
|
|
|
struct _s_send_buf_ s_send_pool;
|
|
struct _s_send_buf_ s_send_bath;
|
|
U8 L0_uart0_get(void){return SBUF;}
|
|
|
|
//#define D_uart_baudrate(X) PCON |= U0BRD; (256 - s_sys_para.sys_clock * (1 + 1) / (32 * X))
|
|
|
|
sbit led =P0^4;
|
|
void L0_uart0_init(void)
|
|
{
|
|
//UART初始化
|
|
PCON &= 0x7F; //波特率不倍速
|
|
SCON = 0x50; //8位数据,可变波特率
|
|
|
|
|
|
// AUXR |= 0x40; //定时器1时钟为Fosc,即1T 去掉为9600
|
|
AUXR &= 0xFE; //串口1选择定时器1为波特率发生器
|
|
|
|
// 0 1 0 1
|
|
// b7 b6 5 4 , 3 2 1 0
|
|
// 0
|
|
TMOD &= 0x0F; //清除定时器1模式位
|
|
TMOD |= 0x20; //设定定时器1为8位自动重装方式
|
|
TL1 = 0xFD; //设定定时初值
|
|
TH1 = 0xFD; //设定定时器重装值
|
|
ET1 = 0; //禁止定时器1中断
|
|
TR1 = 1; //启动定时器1
|
|
|
|
//L0_uart0_IntTIClear();
|
|
//L0_uart0_IntSendStart();
|
|
L0_uart0_IntSendOver();
|
|
TI = 0;
|
|
ES = 1; //打开串口中断
|
|
s_send_bath.p = s_send_bath.buf;
|
|
}
|
|
|
|
|
|
void L0_uart0_uc(U8 ww)
|
|
{
|
|
s_send_bath.max = 1;
|
|
s_send_bath.buf[0] = ww;
|
|
s_send_bath.p = s_send_bath.buf;
|
|
L0_uart0_sendbuf();
|
|
}
|
|
|
|
|
|
void L0_uart0_0d0a(void)
|
|
{
|
|
s_send_bath.max = 2;
|
|
s_send_bath.buf[0] = 0x0d;
|
|
s_send_bath.buf[1] = 0x0a;
|
|
s_send_bath.p = s_send_bath.buf;
|
|
L0_uart0_sendbuf();
|
|
}
|
|
// L0_uart0_uc(cguHex2Char[D_uc_low(s->sec)][0]);
|
|
void L0_uart0_uchex(U8 ww)
|
|
{
|
|
s_send_bath.max = 2;
|
|
s_send_bath.buf[0] = cguHex2Char[D_uc_low(ww)][1];
|
|
s_send_bath.buf[1] = cguHex2Char[D_uc_high(ww)][1];
|
|
s_send_bath.p = s_send_bath.buf;
|
|
L0_uart0_sendbuf();
|
|
}
|
|
void L0_uart0_ulhex(vU32 ww)
|
|
{
|
|
U_U32 ultemp;
|
|
ultemp.dWord = ww;
|
|
L0_uart0_uchex(ultemp.BYTE4.byte0);
|
|
L0_uart0_uchex(ultemp.BYTE4.byte1);
|
|
L0_uart0_uchex(ultemp.BYTE4.byte2);
|
|
L0_uart0_uchex(ultemp.BYTE4.byte3);
|
|
}
|
|
#define D_SERVE_UART interrupt 4
|
|
|
|
|
|
|
|
/*************************************************
|
|
UART 中断
|
|
*************************************************/
|
|
|
|
void INTERRUPT_UART(void) D_SERVE_UART// using 2
|
|
{
|
|
D_51_REG_ES(0);
|
|
//------------------------------------------------
|
|
if(L0_uart0_IntRI()) //如果是U0接收中断
|
|
{L0_uart0_IntRIClear(); //清除接收中断标志
|
|
//L1_uart_2buf(&s_at0);
|
|
L1_uart_2strbuf(&s_at0);
|
|
//D_led_D2_REV();
|
|
}
|
|
//------------------------------------------------
|
|
else
|
|
{
|
|
if(L0_uart0_IntTI()) //如果是U0发送中断
|
|
{L0_uart0_IntTIClear(); //清除发送中断标志
|
|
if(s_send_pool.max != s_send_pool.now)
|
|
{
|
|
L0_uart0_set(s_send_pool.buf[s_send_pool.now]);
|
|
s_send_pool.now ++;
|
|
}else
|
|
{
|
|
s_send_pool.max = 0;s_send_pool.now = 0;
|
|
L0_uart0_IntSendOver(); //可以发送下一个数据
|
|
}
|
|
}
|
|
}
|
|
D_51_REG_ES(1);
|
|
}
|
|
|
|
#define D_task_uart0_0 0x10
|
|
#define D_task_uart0_buf_send 0x11
|
|
#define D_task_uart0_buf_pre 0x12
|
|
#define D_task_uart0_buf_over 0x13
|
|
|
|
|
|
//U8 packagea[] = "AT+CIPSEND=251\r\n";
|
|
|
|
void L0_uart0_sendstr(U8 *str)
|
|
{
|
|
//L0_uart0_sendbuf(str,strlen(str));
|
|
s_send_bath.max = strlen(str);
|
|
s_send_bath.p = str;
|
|
L0_uart0_sendbuf();
|
|
}
|
|
|
|
|
|
// 发送buf数组 中的0----(num-1)
|
|
void L0_uart0_sendbuf(void)
|
|
{
|
|
unsigned char n = 0;
|
|
//s_send_bath.max = 1;
|
|
//s_send_bath.0 = 1;
|
|
//s_send_bath.buf[0] = ww;
|
|
/// s_send_bath.buf s_send_bath.max 已经在调用前写入
|
|
if(s_send_bath.max>= D_send_buf_max)
|
|
{
|
|
s_send_bath.max = 3;
|
|
}
|
|
ES = 0;
|
|
if(L0_uart0_SendIntFree())
|
|
{/// 上次的已经发送完毕了,或者第一次开始
|
|
/// (s_send_pool.now == s_send_pool.max = 0 buf中为空)
|
|
for(n = 0;n < s_send_bath.max; n++)
|
|
{
|
|
s_send_pool.buf[n] = s_send_bath.p[n];
|
|
}
|
|
//s_send_pool.now = 0;
|
|
s_send_pool.max = s_send_bath.max;
|
|
L0_uart0_IntTIClear();
|
|
L0_uart0_IntSendStart();
|
|
s_send_pool.now = 1;
|
|
L0_uart0_set(s_send_pool.buf[0]);
|
|
}else
|
|
{// 需要插入
|
|
/// [0]--?--[pool.now]--?--[pool.max-1].......................................
|
|
/// [0]--?--[pool.now]--?--[pool.max]+[bath.0]--?---[bath.max-1].............
|
|
for(n = 0;n < s_send_bath.max; n++)
|
|
{
|
|
s_send_pool.buf[s_send_pool.max] = s_send_bath.p[n];
|
|
s_send_pool.max ++;
|
|
if(s_send_pool.max >= D_send_buf_max)
|
|
{
|
|
s_send_pool.max = D_send_buf_max;
|
|
}
|
|
}
|
|
}
|
|
ES = 1;
|
|
}
|
|
|
|
|