diff --git a/keilp/cc_as_stc02_ps5ws.uvprojx b/keilp/cc_as_stc02_ps5ws.uvprojx index 2c8a7a6..1554cb9 100644 --- a/keilp/cc_as_stc02_ps5ws.uvprojx +++ b/keilp/cc_as_stc02_ps5ws.uvprojx @@ -10,7 +10,6 @@ STC8F2K16S2 0x0 MCS-51 - 0 stc8a8k64s4a12 @@ -177,14 +176,12 @@ 0 0 0 - 0 0 0 0 0 0 0 - 0 0 0 0 @@ -254,16 +251,6 @@ 0x0 0x0 - - 0 - 0x0 - 0x0 - - - 0 - 0x0 - 0x0 - @@ -283,7 +270,7 @@ - + ..\source\msp @@ -405,6 +392,11 @@ 1 ..\source\msp\uart_x.c + + UART2.C + 1 + ..\source\msp\UART2.C + @@ -430,6 +422,11 @@ 1 ..\source\bsp\rs485.c + + 868.c + 1 + ..\source\bsp\868.c + @@ -455,6 +452,11 @@ 1 ..\source\tpc\modbus.c + + ccmodbus.c + 1 + ..\source\tpc\ccmodbus.c + diff --git a/source/app/main.c b/source/app/main.c index daf14a2..2c9b6de 100644 --- a/source/app/main.c +++ b/source/app/main.c @@ -81,24 +81,27 @@ stc5ac32s void L0_main_init(void) { - //Lc_delay_ms(200); - L0_board_config(); + Lc_delay_ms(200); + L0_board_config(); L0_uart0_buf_init();//串口初始化 + L0_uart2_buf_init();//串口初始化 EA = 1; //Lc_delay_ms(100); L1_tick_init(); L0_timer0_Init(); - + L3_reg_init(); + L3_param_init(); L2_485_init(); - L0_ADS1213_INIT(); - L3_task_adc_init(0); + L0_ADS1213_INIT(); + + L3_task_adc_init(0); L3_task_adc_init(1); L3_task_adc_init(2); L3_task_adc_init(3); - //L3_task_debug_init(); + L3_task_debug_init(); L3_task_show_init(); L3_task_reglisten_init(); L0_uart0_sendArray("v2.7",4); @@ -114,30 +117,45 @@ void main(void) //验证加密信息 //L3_encrypt_handler(); //主循环 + M2=0; + M1=0; + M0=1; while(1) { if(1 == s_nos_tick.t1s_heatbeart) { s_nos_tick.t1s_heatbeart = 0; - LED1 ^= 1; + LED0 ^= 1; + LED0 ^= 1; + } + if(s_uart0_rec.ok) + { + LED0 ^= 1; + s_uart0_rec.ok=0; + L0_uart2_sendArray(s_uart0_rec.buf, s_uart0_rec.num); + } + if(s_uart2_rec.ok) + { + LED0 ^= 1; + s_uart2_rec.ok=0; + L0_uart0_sendArray(s_uart2_rec.buf, s_uart2_rec.num); } - //L1_ADS1213_main(); //单路采集滤波 - L3_task_adc_handler(0); - L3_task_adc_handler(1); - L3_task_adc_handler(2); - L3_task_adc_handler(3); + //L3_task_adc_handler(0); + //L3_task_adc_handler(1); + //L3_task_adc_handler(2); + //L3_task_adc_handler(3); //显示 - L3_task_adc_filter_show(&ts_adc_blur_show); + //L3_task_adc_filter_show(&ts_adc_blur_show); //寄存器值监控 - L3_task_reglisten_handle(&s_task_reglisten); - + //L3_task_reglisten_handle(&s_task_reglisten); //输出,响应485协议 - L3_task_modbus_handler(&s_uart0_rec); + //L3_task_modbus_handler(&s_uart0_rec); + //L3_task_uart_handler(&s_task_uart); //调试输出 //L3_task_debug(&_s_task_debug); diff --git a/source/app/main.h b/source/app/main.h index ba525f9..55e3564 100644 --- a/source/app/main.h +++ b/source/app/main.h @@ -38,6 +38,7 @@ #define _MAIN_H #include "../msp/uart0.h" +#include "../msp/uart2.h" #include "../msp/eeprom.h" #include "../bsp/bsp_config.h" @@ -53,6 +54,8 @@ #include "../app/task_encrypt.h" + + ////////////////////////////////////////////////////////////////// #endif //#ifndef _MAIN_H diff --git a/source/app/source.lnk b/source/app/source.lnk index 08bd271..1f3f23c 100644 Binary files a/source/app/source.lnk and b/source/app/source.lnk differ diff --git a/source/app/task_modbus.c b/source/app/task_modbus.c index 6c9be30..e8ead34 100644 --- a/source/app/task_modbus.c +++ b/source/app/task_modbus.c @@ -1,5 +1,6 @@ #include "task_modbus.h" #include "../msp/uart0.h" +#include "../msp/uart2.h" #include "../tpc/modbus.h" #include "../app/app_config.h" @@ -183,7 +184,7 @@ void L3_task_modbus_handler(TP_Handler_X *ph4) { TS_PH4_modbus *ts_modbus = (TS_PH4_modbus *)ph4->buf; //L0_uart0_sendArray(ph4->buf, 8); - //L0_uart0_sendArray("abcdefgh", 8); + //L0_uart3_sendArray("abcdefgh", 8); ph4->ok = 0; if(ts_modbus->slaver == R.p.slaver_id || ts_modbus->slaver == D_UART0_485_SLAVER_ID_BROADCAST) //从机 { diff --git a/source/app/task_uart.c b/source/app/task_uart.c new file mode 100644 index 0000000..be16f9d --- /dev/null +++ b/source/app/task_uart.c @@ -0,0 +1,27 @@ +#include "task_uart.h" +#include "../bsp/bsp_config.h" +#include "../app/app_config.h" +#include "../msp/uart0.h" +#include "../msp/uart2.h" +S_TASK_UART_TRA s_task_uart; +void L3_task_uart_init(void) +{ + L1_task_init(&s_task_uart.task); + L3_task_s_go(s_task_uart,D_task_init); +} +#define D_task_uart2_send 0x50 +void L3_task_uart_handler(S_TASK_UART_TRA *s) +{ + TTSS_Task_init() + L2_task_go(D_task_uart2_send); + + TTSS_Task_step(D_task_uart2_send) + if(ts_uart[uNum2].t->reg!=0) + { + LED0 ^= 1; + L0_uart2_sendArray("i",8); + } + L2_task_go_Tdelay(D_task_uart2_send,D_Tdelay_Msec(100)); //??100ms + TTSS_Task_end(); + +} \ No newline at end of file diff --git a/source/app/task_uart.h b/source/app/task_uart.h new file mode 100644 index 0000000..65d0e98 --- /dev/null +++ b/source/app/task_uart.h @@ -0,0 +1,19 @@ +#ifndef _APP_TASK_UART_H +#define _APP_TASK_UART_H + +#include "../ctask/task.h" +#include "../clib/clib.h" + +typedef struct _s_task_uart +{ + TS_task task; +}S_TASK_UART_TRA; + +extern S_TASK_UART_TRA s_task_uart; + +extern void L3_task_uart_init(void); +extern void L3_task_uart_handler(S_TASK_UART_TRA *s); + + +#endif // #ifndef _APP_TASK_UART_H + diff --git a/source/bsp/868.c b/source/bsp/868.c new file mode 100644 index 0000000..b44309f --- /dev/null +++ b/source/bsp/868.c @@ -0,0 +1,2 @@ +#include "868.h" + diff --git a/source/bsp/868.h b/source/bsp/868.h new file mode 100644 index 0000000..a3e30e9 --- /dev/null +++ b/source/bsp/868.h @@ -0,0 +1,8 @@ +#ifndef BSP_868_H +#define BSP_868_H + +#include "../bsp/bsp_config.h" +#include "../msp/uart0.h" + + +#endif \ No newline at end of file diff --git a/source/bsp/bsp_config.c b/source/bsp/bsp_config.c index 33f0363..9fb9404 100644 --- a/source/bsp/bsp_config.c +++ b/source/bsp/bsp_config.c @@ -1,5 +1,6 @@ #include "bsp_config.h" #include "../msp/UART0.h" +#include "../msp/UART3.h" #include "../msp/eeprom.h" //////////////////////////////////////////////////////////////////////////// @@ -53,11 +54,11 @@ void L0_board_config(void) //BITN_0(P_SW2 ,BITN2);// rxd4 p0.2 txd4 p0.3 //485 RE/DE 配置推完输出 P55 - BITN_0(P5M1,BITN5);BITN_1(P5M0,BITN5); + //BITN_0(P5M1,BITN5);BITN_1(P5M0,BITN5); //LED - D_stdIO_P1(BITN7); - D_stdIO_P5(BITN4); + //D_stdIO_P1(BITN7); + //D_stdIO_P5(BITN5); //IO D_stdIO_P1(BITN0); diff --git a/source/bsp/bsp_config.h b/source/bsp/bsp_config.h index 126bc70..88b17f1 100644 --- a/source/bsp/bsp_config.h +++ b/source/bsp/bsp_config.h @@ -61,11 +61,11 @@ //STEP 2 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>TYPE_UASER_BOARD CONFIG #if(TYPE_UASER_BOARD == TYPE_BOARD_WEIGH_0B) #include - #include "../cpu/stc_stc8hxx.h" + #include "../cpu/stc_stc8f.h" #include "../cpu/stc_macro.h" //基本配置(工作频率、时钟、看门狗、字节序) - #define TYPE_MCU TYPE_MCU_STC_8H + #define TYPE_MCU TYPE_MCU_STC_8F #define TYPE_IDE TYPE_IDE_KEIL #define D_CPUfamily_type D_CPUfamily_8bits #define D_sys_MainFre MainFre_22M @@ -75,7 +75,7 @@ #define D_CODE_ENCRYPTION_TYPE TYPE_ENCRYPTION_ENABLE //是否代码加密 - #define D_MCU_NAME "STC8H3K48S4" + #define D_MCU_NAME "STC8F2K16S2" //存储器特殊参数地址配置 #define D_MCU_SPEC_PARAM_CHIPID 0xBFF9 //...其他参数 @@ -85,15 +85,17 @@ #define D_uart0_SBIT SBIT_1 #define D_PIN_UART0 PIN_UART0_Rxd_30_Txd_31 #define D_uart2_BRT BRT_115200 + #define D_uart2_SBIT SBIT_1 + #define D_PIN_UART2 PIN_UART2_Rxd_10_Txd_11 #define D_uart3_BRT BRT_115200 #define D_uart4_BRT BRT_115200 //485配置 - #define D_UART0_485_TYPE TYPE_485_SLAVER //UART0启用485 + #define D_UART0_485_TYPE TYPE_485_NONE //UART0启用485 #define D_UART0_485_SLAVER_ID_BROADCAST 0xFF //485从机总是响应0xFF消息 #define D_UART0_485_SLAVER_ID 0x01 //板卡作为485从机 slaverId - #define D_UART0_485_TX() P55 = 1; - #define D_UART0_485_RX() P55 = 0; + #define D_UART0_485_TX() P32 = 1; + #define D_UART0_485_RX() P32 = 0; #define D_UART2_485_TYPE TYPE_485_NONE //UART2不启用485 #define D_UART3_485_TYPE TYPE_485_NONE //UART2不启用485 #define D_UART4_485_TYPE TYPE_485_NONE //UART2不启用485 @@ -104,9 +106,12 @@ #define D_MODBUS_REG_MAX_NUM 32 //每次最多读取/写入的寄存器数量,此处的数量要注意和 D_tp_handle_x_len 对应 //外设定义 - #define LED0 P17 //D4 - #define LED1 P54 //D4 + #define LED0 P55 //D1 + //868配置 + #define M0 P13 + #define M1 P14 + #define M2 P12 //EEP存储地址定义 #define D_EEP_SECTOR_SIZE 0x200 //每个扇区0x200==512bytes #define D_EEP_SECTOR_BLOCK_SIZE 0x40 //扇区中每个数据块0x40==64bytes,可选值[32,64,128]等 @@ -152,7 +157,6 @@ #define D_SERVE_INT4 interrupt 16 #define D_SERVE_UART3 interrupt 17 #define D_SERVE_UART4 interrupt 18 - #define D_SERVE_TIMER3 interrupt 19 #define D_SERVE_TIMER4 interrupt 20 #define D_SERVE_CMP interrupt 21 @@ -198,7 +202,7 @@ //STEP 5 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>UART2 PIN +#define PIN_UART2_Rxd_10_Txd_11 5 + +//<<<<<<<<<<<<<<<<<<<<<<<<<<<.UART2 PIN //>>>>>>>>>>>>>>>>>>>>>>485 Type #define TYPE_485_NONE 0 diff --git a/source/bsp/rs485.c b/source/bsp/rs485.c index 5c00a48..b58709f 100644 --- a/source/bsp/rs485.c +++ b/source/bsp/rs485.c @@ -4,5 +4,5 @@ void L2_485_init(void) { //485配置强推挽输出 P33 P32 //BITN_0(P3M1,BITN3);BITN_1(P3M0,BITN3); - BITN_0(P5M1,BITN5);BITN_1(P5M0,BITN5); + BITN_0(P3M1,BITN2);BITN_1(P3M0,BITN2); } \ No newline at end of file diff --git a/source/bsp/rs485.h b/source/bsp/rs485.h index 0bdba72..e3629e4 100644 --- a/source/bsp/rs485.h +++ b/source/bsp/rs485.h @@ -6,8 +6,8 @@ //485_RE P33 //485_DE P32 -#define D_485_TX() P55 = 1;// >750us -#define D_485_RX() P55 = 0; +#define D_485_TX() P32 = 1;// >750us +#define D_485_RX() P32 = 0; extern void L2_485_init(void); #endif \ No newline at end of file diff --git a/source/ctask/tick.c b/source/ctask/tick.c index 3644450..fa4ee64 100644 --- a/source/ctask/tick.c +++ b/source/ctask/tick.c @@ -24,6 +24,7 @@ void L1_tick_init(void) s_nos_tick.jiffies = 0; s_nos_tick.t_1s = 0; s_nos_tick.t1s_heatbeart= 0; + //s_nos_tick.t_10ms = 0; } @@ -35,11 +36,13 @@ void L1_tick_tick (void) // 4,294,836,225 = 65535*65535 ;3600*24*60*60 = 31,536,000秒/年 //s_nos_tick.t_50ms ++;//D_led_D1_REV(); 20160522验证 s_nos_tick.jiffies++; + //s_nos_tick.t_10ms = 1; if(s_nos_tick.jiffies % HZ == 0) { // 65535*65535/24/60/60/356/10 =12.7年 s_nos_tick.t_1s ++; s_nos_tick.t1s_heatbeart = 1; + } } diff --git a/source/ctask/tick.h b/source/ctask/tick.h index bc47af5..35a26d8 100644 --- a/source/ctask/tick.h +++ b/source/ctask/tick.h @@ -18,6 +18,7 @@ struct _s_nos_tick_ vU32 jiffies; // noos系统定时器最小计时单元 vU32 t_1s; vU8 t1s_heatbeart; //noos 系统定时器整秒时刻标志,需要软件清除 +// vU8 t_10ms; }; extern struct _s_nos_tick_ s_nos_tick; diff --git a/source/msp/UART0.C b/source/msp/UART0.C index 999ac97..2549198 100644 --- a/source/msp/UART0.C +++ b/source/msp/UART0.C @@ -69,8 +69,6 @@ void L0_uart0_init(void) SCON = 0x50; //8位数据,可变波特率 AUXR |= 0x01; //串口1选择定时器2为波特率发生器 AUXR &= 0xFB; //定时器2时钟为Fosc/12,即12T - //T2L = 0xFE; //设定定时初值 - //T2H = 0xFF; //设定定时初值 T2L = val; T2H = val >> 8; AUXR |= 0x10; //启动定时器2 @@ -119,6 +117,7 @@ void INTERRUPT_UART(void) D_SERVE_UART } if(L0_uart0_IntTI()) //如果是U0发送中断 { + L0_uart0_IntTIClear(); //清除发送中断标志 if(ts_uart[uNum0].p->max != ts_uart[uNum0].p->now) { @@ -140,17 +139,24 @@ void INTERRUPT_UART(void) D_SERVE_UART void timer1_isrHanddle(void) D_SERVE_TIMER1 { - struct _tp_handler_x *p = &s_uart0_rec; - - if((p->head == 1) && (p->num >= D_s_modbus_min)) + struct _tp_handler_x *p1 = &s_uart0_rec; + struct _tp_handler_x *p2 = &s_uart2_rec; + if((p1->head == 1) && (p1->num >= D_s_modbus_min)) { - //LED1 ^= 1; - p->head = 0; - crc16(p->crc,p->buf,p->num - 2); //校验CRC - if(p->crc[0] == p->buf[p->num-2] && p->crc[1] == p->buf[p->num-1]) + p1->head = 0; + crc16(p1->crc,p1->buf,p1->num - 2); //校验CRC + if(p1->crc[0] == p1->buf[p1->num-2] && p1->crc[1] == p1->buf[p1->num-1]) { - p->ok = 1; - LED0 ^= 1; + p1->ok = 1; + } + } + if((p2->head == 1) && (p2->num >= D_s_modbus_min)) + { + p2->head = 0; + crc16(p2->crc,p2->buf,p2->num - 2); //校验CRC + if(p2->crc[0] == p2->buf[p2->num-2] && p2->crc[1] == p2->buf[p2->num-1]) + { + p2->ok = 1; } } L0_timer1_stop(); diff --git a/source/msp/UART0.h b/source/msp/UART0.h index 37bd779..038b0ca 100644 --- a/source/msp/UART0.h +++ b/source/msp/UART0.h @@ -55,7 +55,7 @@ msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 #include "../bsp/bsp_config.h" #include "../tpc/modbus.h" #include "uart_x.h" - +#include "../msp/uart2.h" //#include "../tpc/tpc_x.h" #define uNum0 0 diff --git a/source/msp/UART2.c b/source/msp/UART2.c index 3884af7..0e0d81c 100644 --- a/source/msp/UART2.c +++ b/source/msp/UART2.c @@ -54,14 +54,15 @@ msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 L0_Usend_uc------UserDef ----------------------------------------------------------------------------------------- ********************************************************************************/ -#include "uart2.h" -#include "../app/common.h" +#include "uart2.h" +#include "../app/app_config.h" +#include "../msp/time.h" //#define _USE_485 static volatile Ts_uart_send_buf idata ts_uart_send_shop; -TP_Handler_X s_uart2_rec; -TS_PH3_ccmodbus s_uart2_ack; +TP_Handler_X s_uart2_rec; +TS_PH4_modbus s_uart2_ack; void L0_uart2_init(void) { @@ -87,11 +88,9 @@ void L0_uart2_buf_init(void) ts_uart[uNum2].p->now = 0; ts_uart[uNum2].p->ok = D_ready; ts_uart[uNum2].t = &s_uart2_rec; - ts_uart[uNum2].t->head_0 = D_CMD_Filter1_ff; - ts_uart[uNum2].t->head_1 = D_CMD_Filter2_fe; ts_uart[uNum2].t->head = 0; ts_uart[uNum2].t->ok = 0; - ts_uart[uNum2].tp_handler = L1_s2b_PH3; + ts_uart[uNum2].tp_handler = NULL; ts_uart[uNum2].ack = (U8*)&s_uart2_ack; L0_uart2_init(); D_uart2_ES_INT(1); //打开串口中断 @@ -120,7 +119,9 @@ void INTERRUPT_uart2(void) D_SERVE_uart2// using 2 { L0_uart2_IntRIClear(); //清除接收中断标志 ts_uart[uNum2].t->reg = L0_uartN_get(uNum2); - ts_uart[uNum2].tp_handler(ts_uart[uNum2].t); + //ts_uart[uNum2].tp_handler(ts_uart[uNum2].t); + L1_s2b_PH4(ts_uart[uNum2].t); + L0_timer1_restart(); } if(L0_uart2_IntTI()) //如果是U0发送中断 { @@ -153,4 +154,3 @@ void INTERRUPT_uart2(void) D_SERVE_uart2// using 2 - diff --git a/source/msp/UART2.h b/source/msp/UART2.h index 8d2835b..97cc20b 100644 --- a/source/msp/UART2.h +++ b/source/msp/UART2.h @@ -54,8 +54,8 @@ msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 #define _uart2_H #include "../bsp/bsp_config.h" -#include "../tpc/tpc_ccmodbus.h" -#include "uartN.h" +#include "../tpc/ccmodbus.h" +#include "uart_x.h" #define uNum2 1 @@ -69,7 +69,7 @@ msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 void L0_uart2_buf_init(void); void L0_uart2_sendArray(U8 * buf, U16 len); - +void uart2_Handdle(void) ; #define L0_uart2_uc(X) L0_uartN_uc(uNum2,X) #define L0_uart2_us(X) L0_uartN_us(uNum2,X) #define L0_uart2_ul(X) L0_uartN_ul(uNum2,X) @@ -77,10 +77,9 @@ void L0_uart2_sendArray(U8 * buf, U16 len); #define L0_uart2_uchex(X) L0_uartN_uchex(uNum2,X) #define L0_uart2_ushex(X) L0_uartN_ushex(uNum2,X) #define L0_uart2_ulhex(X) L0_uartN_ulhex(uNum2,X) -#define L0_uart2_sendstr(buf) L0_uartN_sendstr(uNum2,buf) - -extern TP_Handler_X s_uart2_rec; -extern TS_PH3_ccmodbus s_uart2_ack; +#define L0_uart2_sendstr(buf) L0_uartN_sendstr(uNum2,buf) +extern TP_Handler_X s_uart2_rec; +extern TS_PH4_modbus s_uart2_ack; #endif //#ifndef _uart2_H diff --git a/source/msp/UART3.c b/source/msp/UART3.c index 5c59ccb..98439ee 100644 --- a/source/msp/UART3.c +++ b/source/msp/UART3.c @@ -55,7 +55,7 @@ msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 ----------------------------------------------------------------------------------------- ********************************************************************************/ #include "uart3.h" -#include "time.h" +#include "../msp/time.h" #include static volatile Ts_uart_send_buf idata ts_uart_send_shop; @@ -104,9 +104,9 @@ void L0_uart3_buf_init(void) void L0_uart3_sendArray(U8 * buf, U16 len) { -#if (D_UART3_485_TYPE != TYPE_485_NONE) - D_UART3_485_TX() //切换到输出状态 -#endif +//#if (D_UART3_485_TYPE != TYPE_485_NONE) +// D_UART3_485_TX() //切换到输出状态 +//#endif L0_uartN_sendArray(uNum3,buf,len); } @@ -154,7 +154,7 @@ void timer4_isrHanddle(void) D_SERVE_TIMER4 if((p->head == 1) && (p->num >= D_s_modbus_min)) { p->head = 0; - crc16_irq(p->crc,p->buf,p->num - 2); //校验CRC + crc16(p->crc,p->buf,p->num - 2); //校验CRC if(p->crc[0] == p->buf[p->num-2] && p->crc[1] == p->buf[p->num-1]) { if(p->ok == 0) @@ -162,7 +162,7 @@ void timer4_isrHanddle(void) D_SERVE_TIMER4 p->ok = 1; } } - LED0 ^= 1; + //LED0 ^= 1; } L0_timer4_stop(); } diff --git a/source/msp/UART3.h b/source/msp/UART3.h index a4e2ea8..eb4bb28 100644 --- a/source/msp/UART3.h +++ b/source/msp/UART3.h @@ -54,8 +54,8 @@ msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 #define _uart3_H #include "../bsp/bsp_config.h" -#include "../tpc/tpc_modbus.h" -#include "uartN.h" +#include "../tpc/modbus.h" +#include "uart_x.h" #define uNum3 2 diff --git a/source/msp/time.c b/source/msp/time.c index 8007b26..fa74792 100644 --- a/source/msp/time.c +++ b/source/msp/time.c @@ -81,8 +81,8 @@ void L0_timer1_restart() //600微秒@11.0592MHz TL1 = val; //设置定时初值 TH1 = val >>8; //设置定时初值 TF1 = 0; //清除TF1标志 - TR1 = 1; //定时器1开始计时 - ET1 = 1; //add by cc + TR1 = 1; //定时器1开始计时,每隔1ms加1 + ET1 = 1; //add by cc 打开定时器中断 #else AUXR |= 0x40; //定时器时钟1T模式 @@ -102,6 +102,9 @@ void L0_timer1_stop(void) } + + + /******************************END*********************************/ diff --git a/source/msp/time.h b/source/msp/time.h index 6d78f09..7c1b7c9 100644 --- a/source/msp/time.h +++ b/source/msp/time.h @@ -5,7 +5,9 @@ #include "../bsp/bsp_config.h" #include "../ctask/tick.h" - +extern void L0_timer3_stop(void); +extern void L0_timer3_restart(void); //600微秒@11.0592MHz +extern void L0_timer3_Init(void); extern void L0_timer1_stop(void); extern void L0_timer1_start(); extern void L0_timer1_restart(void); //600微秒@11.0592MHz diff --git a/source/msp/uart_x.c b/source/msp/uart_x.c index 3be3670..bdda560 100644 --- a/source/msp/uart_x.c +++ b/source/msp/uart_x.c @@ -58,7 +58,7 @@ msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 TS_uart_reg idata ts_uart[SERIAL_MAX_NUM] = {0}; -void L0_uartN_set(U8 uartx,U8 x) /*reentrant*/ +void L0_uartN_set(U8 uartx,U8 x) { switch(uartx) { diff --git a/source/tpc/ccmodbus.c b/source/tpc/ccmodbus.c index b847efa..e3408a9 100644 --- a/source/tpc/ccmodbus.c +++ b/source/tpc/ccmodbus.c @@ -1,4 +1,4 @@ - + /***************************************************************************** update by cc @201501101001 针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是 @@ -31,7 +31,8 @@ msp/uartx.c 底层代码 和cpu相关 #include "ccmodbus.h" #include "../clib/clib.h" - +vU8 D_CMD_Filter1_ff; +vU8 D_CMD_Filter2_fe; #if 0 U8 L3_pack_ccmodbus_03(TS_PH3_ccmodbus *pmodbus ,U8 slaverId, U16 reg, U16 num) { @@ -90,7 +91,6 @@ U8 L3_pack_ccmodbus_10(TS_PH3_ccmodbus *pmodbus ,U8 slaverId, U16 reg, U16 num, U8 L3_pack_ccmodbus(TS_PH3_ccmodbus *pccmodbus, MD_SLAVER_INFO *slaver_info) { - U8 pkglen = 0; pccmodbus->filter1 = D_CMD_Filter1_ff; pccmodbus->filter2 = D_CMD_Filter2_fe; pccmodbus->num = L3_pack_modbus((TS_PH4_modbus*)&pccmodbus->slaver, slaver_info); @@ -141,7 +141,7 @@ void L1_s2b_PH3(struct _tp_handler_x *p)// reentrant if ((p->cashe[1] == p->head_0)&&(p->cashe[0] == p->head_1)) { p->head = 1; - p->max = D_tp_handle_x_len; + p->max = D_TPC_HANDLER_X_LEN ; p->sp = p->buf; p->num = 0; p->sp[p->num++] = p->head_0; @@ -154,7 +154,7 @@ void L1_s2b_PH3(struct _tp_handler_x *p)// reentrant if(p->num == 3)//数量 第3个数据 { p->max = p->cashe[0] + 3; - if((p->max > D_tp_handle_x_len) || (p->max < D_s_ccmodbus_min)) + if((p->max > D_TPC_HANDLER_X_LEN ) || (p->max < D_s_ccmodbus_min)) { p->head = 0; return; //error 超过最大长度 diff --git a/source/tpc/ccmodbus.h b/source/tpc/ccmodbus.h index 80f9eff..234355f 100644 --- a/source/tpc/ccmodbus.h +++ b/source/tpc/ccmodbus.h @@ -54,7 +54,7 @@ msp/uartx.c 底层代码 和cpu相关 #define __TPC_CCMODBUS_H_ #include "tpc_x.h" -#include "tpc_modbus.h" +#include "modbus.h" //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ///协议类型: 十六进制协议3->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> /// 发送的数据为有ff fe开头的十六进制的长协议,内包含标准的modbus协议 @@ -62,9 +62,10 @@ msp/uartx.c 底层代码 和cpu相关 /// 协议表达的意思为地址为0x52的从机, 功能码16 数据为11 22 33 44,校验码 F5 9F /// 校验码的范围为 -//#define D_s_PH3_ccmodbus_max 128 +#define D_s_PH3_ccmodbus_max 128 #define D_s_ccmodbus_min (D_s_modbus_min + 3) - +extern vU8 D_CMD_Filter1_ff; +extern vU8 D_CMD_Filter2_fe; typedef struct {//8byte vU8 filter1; @@ -72,7 +73,7 @@ typedef struct vU8 num; //接收到的数据的计数, 随着数据接收而变化注意数据长度的范围 vU8 slaver; //发送方的地址或命令 vU8 oper; //命令 - vU8 buf[D_tp_handle_x_len + 8];//D_s_PH3_ccmodbus_max - 3,长一点防止越界 + vU8 buf[D_s_PH3_ccmodbus_max - 3];//D_s_PH3_ccmodbus_max - 3,长一点防止越界 vU8 crc[2]; //crc16 }TS_PH3_ccmodbus; @@ -94,5 +95,4 @@ extern U16 L3_ccmodbus_slaver_ack(TS_PH3_ccmodbus *pccmodbus,TS_PH3_ccmodbus *pM extern void L3_ccmodbus_master_handler(TS_PH3_ccmodbus *pmodbus,MD_SLAVER_INFO *p_slaver_info); extern void L1_s2b_PH3(struct _tp_handler_x *p);// reentrant; -#endif /* end __TPC_CCMODBUS_H_ */ - +#endif /* end __TPC_CCMODBUS_H_ */ \ No newline at end of file diff --git a/source/tpc/tpc_x.h b/source/tpc/tpc_x.h index 8956284..35d5f4e 100644 --- a/source/tpc/tpc_x.h +++ b/source/tpc/tpc_x.h @@ -11,7 +11,7 @@ typedef struct _tp_handler_x vU8 cashe[2]; vU8 head_0; vU8 head_1; - vU8 num; //接收到的数据的计数, 随着数据接收而变化注意数据长度的范围 + vU8 num; //接收到的数据的计数, 随着数据接收而变化注意数据长度的范围 vU8 ok; //接收协议ok标志 vU8 max; //接收到的数目的最大值 vU8 buf[D_TPC_HANDLER_X_LEN+16];////协议缓冲