forked from ccsens_hardware/stc_ttss_weight
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.
192 lines
5.1 KiB
192 lines
5.1 KiB
4 years ago
|
|
||
|
/*****************************************************************************
|
||
|
update by cc @201501101001
|
||
|
���Զമ�� �� ��һ���� ������ ÿ�������Ƕ����Ļ��Ƿֿ����н��� �����Ǹ��ӵĻ�������Ӧ�ü�����
|
||
|
����Ҫƽ��������.
|
||
|
|
||
|
uartcom/uartlib.c:
|
||
|
���õĺ��� ��Ӳ����
|
||
|
���ô���ģʽ(���ڵ�����ͨѶ������������)�����ĺ���,
|
||
|
һЩ����ģʽ������(lcd�ȹ���������)��Ҳ��ʹ��
|
||
|
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...)
|
||
|
-----------------------------------------------------------------------------------------
|
||
|
uartcom/uartcom0
|
||
|
��uart���ص�ͨѶЭ�� com + n
|
||
|
Ϊ����Ӧ��ͬ��ͨѶЭ����Ҫ��ͬ��uart������Ӧ ��Ӧ������
|
||
|
|
||
|
typedef struct _ts_lcm_pro_; Ӧ��Э�����Ķ���? LCM��Э��------------
|
||
|
L3_UARTcom0_exp_protocol ����Ӧ��Э��
|
||
|
-----------------------------------------------------------------------------------------
|
||
|
uartcom/uprotocol: ��Ҫ��Ϊ uartcom + n������ �����㵽Ӧ�ò㻺���Ĺ���
|
||
|
���õĴ���ͨѶ����
|
||
|
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----------s_at0
|
||
|
-----------------------------------------------------------------------------------------
|
||
|
********************************************************************************/
|
||
|
|
||
|
#include "tpc_uart.h"
|
||
|
|
||
|
|
||
|
//NUM: 0 1 2 3 4
|
||
|
// Fx R1 R2 R3 ocr
|
||
|
// F+�ӻ� R1 R2 R3 У��
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/// ʵ���з��� �����յ�������0d0a�����Ķ�Э��ʱ,����
|
||
|
/// Э��֮������ʱ��̫��,ok��������ʱ �����ֶ�ʧЭ����
|
||
|
/// ������,���� ���ڶ��ݵĶ���Э�� Ӧ����һ�������Ļ���
|
||
|
/// ���� ,ͬʱ ������Э����,Ӧ���������ջ���,����
|
||
|
/// �����������˺��Զ�����
|
||
|
//_s_HRTU_P_rf_
|
||
|
/// _s_HRTU_Pfx_
|
||
|
/// fx 11 22 33 oc -- oc = 11+ 22+33
|
||
|
//buf 0 1 2 3 [4]
|
||
|
//
|
||
|
//// protocol hex 1 serial to buff
|
||
|
#ifdef D_use_uart_rx
|
||
|
void L1_s2b_PH1 (TS_Handle_PH1 *p)// reentrant
|
||
|
{
|
||
|
if (0 == p->head)
|
||
|
{
|
||
|
if (D_HETU_FX_fi == (p->reg&D_HETU_FX_H4))
|
||
|
{//p->ok = 1;p->head = 0;
|
||
|
p->head = 1;
|
||
|
p->num = 0;
|
||
|
//p->ocx = 0;
|
||
|
p->buf[p->num]=p->reg;
|
||
|
}
|
||
|
}else
|
||
|
{
|
||
|
p->num ++;
|
||
|
p->buf[p->num] = p->reg;
|
||
|
|
||
|
if(p->num >= D_HETU_FX_buf_max) // [4]
|
||
|
{
|
||
|
///p->ocr = p->buf[1]; p->ocr += p->buf[2];p->ocr += p->buf[3];
|
||
|
///if(p->ocr == p->buf[D_HETU_FX_buf_max])
|
||
|
{
|
||
|
// if (p->ok != 1)
|
||
|
{
|
||
|
// D_led_D2_ON();
|
||
|
p->ok = 1;//�յ� ��������,�����и��ط���0���������ٴν��ܱ���
|
||
|
// D_led_D2_OFF();
|
||
|
}
|
||
|
}
|
||
|
p->num = 0; //����if (p->ok != 1) ��
|
||
|
p->head = 0; //����if (p->ok != 1) ��
|
||
|
//p->max = 0;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
////485
|
||
|
//// ����ַ�ж���
|
||
|
void L1_s2b_PH1A (TS_Handle_PH1A *p)// reentrant
|
||
|
{
|
||
|
if (0 == p->head)
|
||
|
{
|
||
|
if (D_HETU_FXA == p->reg)
|
||
|
{//p->ok = 1;p->head = 0;
|
||
|
p->head = 1;
|
||
|
p->num = 0;
|
||
|
//p->ocx = 0;
|
||
|
p->buf[p->num]=p->reg;
|
||
|
}
|
||
|
}else
|
||
|
{
|
||
|
p->num ++;
|
||
|
p->buf[p->num] = p->reg;
|
||
|
if(p->num >= D_HETU_FXA_buf_max - 1) // [4]
|
||
|
{
|
||
|
///p->ocr = p->buf[1]; p->ocr += p->buf[2];p->ocr += p->buf[3];
|
||
|
///if(p->ocr == p->buf[D_HETU_FX_buf_max])
|
||
|
{
|
||
|
//if (p->add == p->buf[1])///��ַ��ƥ��
|
||
|
{
|
||
|
// D_led_D2_ON();
|
||
|
p->ok = 1;//�յ� ��������,�����и��ط���0���������ٴν��ܱ���
|
||
|
// D_led_D2_OFF();
|
||
|
}
|
||
|
// p->ok = 1;
|
||
|
}
|
||
|
p->num = 0; //����if (p->ok != 1) ��
|
||
|
p->head = 0; //����if (p->ok != 1) ��
|
||
|
//p->max = 0;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
///FF FE 08 52 16 11 22 33 44 F5 9F ������һ��modbusЭ����(8������52 16 11 22 33 44 F5 9F )
|
||
|
/// 1 2 3 4 5 6 7 8
|
||
|
/// 0 1 2 3 4 5 6 7 8 9 10
|
||
|
/// Э����������˼Ϊ��ַΪ0x52�Ĵӻ�, ������16 ����Ϊ11 22 33 44,У���� F5 9F
|
||
|
|
||
|
void L1_s2b_PH3_init(TS_Handle_PH3 *p)
|
||
|
{
|
||
|
p->max = 0;
|
||
|
p->ok = 0;
|
||
|
p->num = 0;
|
||
|
p->head = 0;
|
||
|
p->head_0 = TS_PH3_FILTER0;
|
||
|
p->head_1 = TS_PH3_FILTER1;
|
||
|
}
|
||
|
|
||
|
void L1_s2b_PH3(TS_Handle_PH3 *p)// reentrant
|
||
|
{
|
||
|
p->cashe[1] = p->cashe[0];
|
||
|
p->cashe[0] = p->reg;//
|
||
|
|
||
|
if (0 == p->head)
|
||
|
{
|
||
|
if ((p->cashe[1] == p->head_0)&&(p->cashe[0] == p->head_1))
|
||
|
{
|
||
|
p->head = 1;
|
||
|
p->max = D_s_PH3_ccmodbus_max - 1;
|
||
|
p->sp = p->buf;
|
||
|
p->sp[0] = p->head_0;
|
||
|
p->sp[1] = p->head_1;
|
||
|
p->num = 1;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
p->num ++;
|
||
|
p->sp[p->num] = p->cashe[0];
|
||
|
if(p->num == 2)//���� ��3������
|
||
|
{
|
||
|
p->max = p->reg + 2;//
|
||
|
if(p->max >= D_s_PH3_ccmodbus_max)
|
||
|
{
|
||
|
p->max = D_s_PH3_ccmodbus_max - 1;
|
||
|
}
|
||
|
}
|
||
|
if(p->num >= p->max)
|
||
|
{
|
||
|
//p->ts_ccmodbus.crc = (p->sp[p->num-1] | p->sp[p->num]) & 0xFFFF;
|
||
|
if(/*crc()==p->ts_ccmodbus.crc*/ 1)
|
||
|
{
|
||
|
if (p->ok != 1)
|
||
|
{
|
||
|
p->ok = 1;//�յ� ��������,�����и��ط���0���������ٴν��ܱ���
|
||
|
}
|
||
|
}
|
||
|
p->num = 0;
|
||
|
p->head = 0;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/******************************************************************************
|
||
|
** End Of File
|
||
|
******************************************************************************/
|