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.
 
 
 
 

312 lines
5.7 KiB

//////////////////////////////////////////////////////////////////////////
/// COPYRIGHT NOTICE
/// Copyright (c) 2023, 传控科技
/// All rights reserved.
///
/// @file asp_gsensor.c
/// @brief asp_gsensor
///
///(本文件实现的功能的详述)
///
////20221217_213321 CCmodify new uart struct for road protocol
#include "msp_UART1.h"
#include "msp_UART2.h"
#include "debug_drv.h"
#include "bsp_config.h"
#include "asp_gsensor.h"
#include "bsp_moto.h"
#include "asp_move.h"
#include "asp_lowpower.h"
#define D_version_main "7.0"
void L0_uart_close(void)
{
L0_uart1_str("\r\nuart1 close");///
Lc_delay_ms(20);
EA = 0;
D_uart1_ES_INT(0);
//// D_UART2_ES_INT(0);
AUXR = 0; //定时器2开始计时
ET1 = 0; //禁止定时器%d中断
TR1 = 0; //定时器1开始计时
}
void L0_uart1_open(void)
{//
L0_uart1_buf_init();//串口初始化//
EA = 1;
L0_uart1_str("\r\nuart1 open");
}
void L0_uart2_open(void)
{//
L0_uart2_buf_init();
EA = 1;
L0_uart1_str("\r\nuart2 open");
}
void L0_SetWakeUpTime(u16 SetTime)
{
SetTime = (U16)((32768UL * (U32)SetTime) / 16000); //重装值 = Fwkt/16 * SetTime/1000 = Fwkt * SetTime / 16000
if(SetTime > 0) SetTime--;
WKTCL = (u8)SetTime;
WKTCH = (u8)(SetTime >> 8) | 0x80;
}
void L0_main_lowp_set(void)
{//
L0_uart_close();
L0_SetWakeUpTime(10000);///
BITN_1(P_SW2 ,BITN7);///P_SW2|=0x80;
////PCON = 0;
///0:禁止端口内部的 4.1K 上拉电阻
///1:使能端口内部的 4.1K 上拉电阻
P0PU = 0;
P1PU = 0;
P2PU = 0;
P3PU = 0;
P4PU = 0;
P5PU = 0;
///0:使能端口的施密特触发功能。(上电复位后默认使能施密特触发)
P0NCS = 0xff;
P1NCS = 0xff;
P2NCS = 0xff;
P3NCS = 0xff;
P4NCS = 0xff;
P5NCS = 0xff;
////1:电平转换速度慢,相应的上下冲比较小
P0SR =0xff;
P1SR =0xff;
P2SR =0xff;
P3SR =0xff;
P4SR =0xff;
P5SR =0xff;
///1:一般驱动能力
P0DR =0xff;
P1DR =0xff;
P2DR =0xff;
P3DR =0xff;
P4DR =0xff;
P5DR =0xff;
///0:禁止数字信号输入。若 I/O 被当作比较器输入口、ADC 输入口、触摸按键输入口或者为外部晶 振接入脚等模拟口时,
///进入时钟停振模式前,必须设置为 0,否则会有额外的耗电。
///1:使能数字信号输入。若 I/O 被当作数字口时,必须设置为 1,否 MCU 无法读取外部端口的电平。
P0IE =0;
P1IE =0;
P2IE =0;
P3IE =0;
P4IE =0;
P5IE =0;
BITN_1(P_SW2 ,BITN7);USBCON = 0;
////USBCON = 0;
///USBCON = 0x80;
ADC_CONTR = 0; ////建议进入空闲模式和掉电模式前将 ADC 电源关闭,以降低功耗
RSTCFG = 0;//没有变化43ua 41ua 低压复位控制位
D_HighR_P0_ALL();
D_HighR_P1_ALL();
D_HighR_P2_ALL();
D_HighR_P3_ALL();
D_HighR_P4_ALL();
D_HighR_P5_ALL();/***********
P3 = 0;
P0 = 0;
P1 = 0;
P2 = 0;
P4 = 0;
P5 = 0;
*********/
P0 = 0xff;
P1 = 0xff;
P2 = 0xff;
P4 = 0xff;
P5 = 0xff;
D_stdIO_P4(BITN1);
///D_OpenD_P4(BITN1);
D_P41_ON();
/*****
// XOSCCR =0;
///HIRCCR = 0;
IRC32KCR = 0x80; //启动内部32K IRC
while (!(IRC32KCR & 1)); //等待时钟稳定
CLKDIV = 0x00; //时钟不分频
CLKSEL = 0x03; //选择内部32K
P_SW2 = 0x00;
P45
P27
P26
P44
P43
p13
P23 switch2 限位开关
P40 SWITCH1 限位开关
P41 SW_CAL 电源分压电阻 =1 关闭
*******/
}
/*
void L2_main_version(u8 d)
{
printfs(D_version_main);
L1_uartD_uc(d);
printfs(D_BOARD_NAME);
printfs(__DATE__);
printfs(__TIME__);
}
*/
void L1_main_lowp_test(void)
{//
while(9)
{
/// L2_gsensor_init(0);
L0_main_lowp_set();
_nop_();
_nop_();
//// L0_uart_close();
PCON = 0x02; ////2222 //MCU进入掉电模式
///D_LPCD_INT_CLOSE(); 对掉电唤醒后有一个中断进来没有效果
_nop_();
_nop_(); _nop_();
_nop_(); _nop_();
_nop_();
L0_uart1_open();
L0_uart2_open();
/// L2_main_version(0);
/// L2_gsensor_init(1);
}
}
void L3_test_lp(u8 filter)//// ON listen function
{
if(filter == pd->filter)
{///filter num d1 d2 d3 ....dn
//// FD 08 11 22 33 44 55 66 77 88
///printf("\r\nDdebug:F1 R1 R2 R3 R4 ocr FD->");
switch (pd->ocr)
{
case 0x22: ///'s'
///FX R1 R2 R3 R4 ocr
///F1 m R2 R3 R4 22
// L0_moto_run(pd->R1);
printf1("22: moto=(%X)",(int)pd->R1);
break;
default:
printfs(" pp error\r\n ");
break;
};
printfs("333");
}
}
/***
case 0x23: ///'s'
///FX R1 R2 R3 R4 ocr
///F1 m R2 R3 R4 22
if(pd->R1)
{
D_BUZ_OPEN();
}else
{
D_BUZ_OFF();
}
printf("22: moto=(%X)",(int)pd->R1);
break;
case 0x24: ///'s'
///F1 m 23 56 64 22
ts_task_move.loc_angle[0] = pd->R1;
ts_task_move.loc_angle[1] = pd->R2;
ts_task_move.loc_angle[2] = pd->R3;
ts_task_move.loc_angle[3] = pd->R4;
L3_task_s_go(ts_task_move,D_task_move_init);
printf("move: %d %d %d %d )",(int)pd->R1,(int)pd->R2,(int)pd->R3,(int)pd->R4);
break;
case 0x25: ///'s'
///F1 m 23 56 64 22
ts_task_move.loc_angle[0] = pd->R1;
ts_task_move.loc_angle[1] = pd->R2;
ts_task_move.loc_angle[2] = pd->R3;
ts_task_move.loc_angle[3] = pd->R4;
L3_task_s_go(ts_task_move,D_task_move_init);
ts_task_move.loc_now =D_2uc_u16(pd->R1, pd->R2);
printf("move: loc_now %XH %d )",(int)ts_task_move.loc_now,(int)ts_task_move.loc_now);
break;
case 0x26: ///'s'
///F1 m 23 56 64 22
ts_task_move.loc_angle[0] = pd->R1;
if(pd->R1)
{
ts_task_move.loc_now ++;
}
else
{
ts_task_move.loc_now --;
}
printf("move: loc_now %XH %d ->%d )",(int)ts_task_move.loc_now,(int)ts_task_move.loc_now,(int)ts_task_move.loc_want);
break;
****/