commit 543b4f2ff5460dafdfc20e83ddcd7151b507ddaf Author: zhangsan Date: Thu Sep 17 13:21:25 2020 +0800 v1.0 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd151ae --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +### vim +*.swp +*.swo +*~ + +### Keil5 +/keil/* +/keilp/* +!*.sct +!*.uvprojx + +### Source Insight +*.IAB +*.IAD +*.IMB +*.IMD +*.PFI +*.PO +*.PR +*.PRI +*.PS +*.WK3 +*.SearchResults +*.bookmarks.xml +*.snippets.xml +si/**/cache/ +si/**/Backup/ +si4/**/cache/ +si4/**/Backup/ + +### Source file +source/bak/ +/out/ diff --git a/docs/加密流程图-v0.1-20200917.eddx b/docs/加密流程图-v0.1-20200917.eddx new file mode 100644 index 0000000..935cd92 Binary files /dev/null and b/docs/加密流程图-v0.1-20200917.eddx differ diff --git a/docs/加密流程图-v0.2-20200917.eddx b/docs/加密流程图-v0.2-20200917.eddx new file mode 100644 index 0000000..857f55c Binary files /dev/null and b/docs/加密流程图-v0.2-20200917.eddx differ diff --git a/keilp/cc_as_stc02_ps5ws.uvprojx b/keilp/cc_as_stc02_ps5ws.uvprojx new file mode 100644 index 0000000..2dc42ef --- /dev/null +++ b/keilp/cc_as_stc02_ps5ws.uvprojx @@ -0,0 +1,427 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + STC8F2K16S2 + 0x0 + MCS-51 + 0 + + + STC8F2K64S4 + STC + IRAM(0-0xFF) XRAM(0-0x07FF) IROM(0-0xFFF8) CLOCK(35000000) MODP2 + + "LIB\STARTUP.A51" ("Standard 8051 Startup Code") + + 63032 + STC8.H + + + + + + + + + + + 0 + 0 + d:\Keil\C51\BIN\ + + + STC\ + STC\ + + 0 + 0 + 0 + 0 + 1 + + ..\out\ + cc_stc02_ps5ws + 1 + 0 + 1 + 1 + 1 + ..\out\ + 0 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + 65535 + + + S8051.DLL + + DP51.DLL + -pDP8051 + S8051.DLL + + TP51.DLL + -p51 + + + + 0 + 0 + 0 + 0 + 16 + + + + + 0 + 0 + 0 + 0 + 0 + -1 + + 0 + + "" () + + + + + 0 + + + + 2 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + 0 + 0x0 + 0xffff + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0xfff9 + + + 0 + 0x0 + 0x100 + + + 0 + 0x0 + 0x800 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + + + 0 + 0 + 0 + 0 + 1 + 3 + 2 + 2 + 0 + 1 + 0 + 0 + + + + + + + + + 0 + 1 + 0 + 0 + + + + + + + + + 0 + 0 + 1 + 0 + 2 + 1 + + REMOVEUNUSED + + + + + + + + + + + + + + + + + + + + + + + + + + + app + + + main.c + 1 + ..\source\app\main.c + + + common.c + 1 + ..\source\app\common.c + + + + + cpu + + + STARTUP.A51 + 2 + ..\source\cpu\STARTUP.A51 + + + + + msp + + + time.c + 1 + ..\source\msp\time.c + + + UART0.C + 1 + ..\source\msp\UART0.C + + + msp_eeprom.c + 1 + ..\source\msp\msp_eeprom.c + + + msp_id.c + 1 + ..\source\msp\msp_id.c + + + + + bsp + + + ctask + + + task.c + 1 + ..\source\ctask\task.c + + + tick.c + 1 + ..\source\ctask\tick.c + + + + + tpc + + + tpc_modbus.c + 1 + ..\source\tpc\tpc_modbus.c + + + + + clib + + + clib.c + 1 + ..\source\clib\clib.c + + + + + + + +
diff --git a/si4/keywords.txt b/si4/keywords.txt new file mode 100644 index 0000000..d39a8c6 --- /dev/null +++ b/si4/keywords.txt @@ -0,0 +1,152 @@ +#define, Keyword +#elif, Directive +#else, Directive +#endif, Directive +#if, Directive +#ifdef, Directive +#ifndef, Directive +#include, Keyword +#pragma, Keyword +#undef, Keyword +(, Delimiter +), Delimiter +",", Delimiter +;, Delimiter +abstract, Keyword +__abstract, Keyword +alignas, Keyword +alignof, Keyword +asm, Keyword +__asm, Keyword +assert, Debug +Assert, Debug +async, Keyword +auto, Keyword +bool, Keyword +break, Control +case, Control +catch, Control +cdecl, Keyword +__cdecl, Keyword +char, Keyword +class, Control +coclass, Control +const, Keyword +constexpr, Keyword +const_cast, Keyword +continue, Control +cout, Keyword +decltype, Keyword +default, Control +__delegate, Keyword +delete, Control +do, Control +double, Keyword +DWORD, Keyword +dynamic_cast, Keyword +each, Control +else, Control +enum, Control +__event, Keyword +except, Control +__except, Control +exception, Keyword +explicit, Keyword +export, Keyword +extern, Keyword +FALSE, Boolean +false, Boolean +FAR, Keyword +far, Keyword +final, Keyword +__finally, Control +float, Keyword +for, Control +fortran, Keyword +for_each, Control +friend, Keyword +__gc, Keyword +goto, Control +HUGE, Keyword +huge, Keyword +if, Control +inline, Keyword +INT, Keyword +int, Keyword +int16_t, Keyword +int32_t, Keyword +int64_t, Keyword +int8_t, Keyword +interface, Control +LONG, Keyword +long, Keyword +mutable, Keyword +namespace, Control +near, Keyword +NEAR, Keyword +new, Control +noexcept, Keyword +NULL, Null Value +nullptr, Null Value +__nullptr, Null Value +operator, Keyword +override, Keyword +pascal, Keyword +PASCAL, Keyword +private, Keyword +__property, Keyword +protected, Keyword +public, Keyword +ref, Keyword +REGISTER, Keyword +register, Keyword +reinterpret_cast, Keyword +return, Control +sealed, Keyword +short, Keyword +SHORT, Keyword +signed, Keyword +sizeof, Keyword +static, Keyword +static_cast, Keyword +struct, Control +__super, Keyword +switch, Control +template, Control +this, Keyword +thread_local, Keyword +throw, Control +TRUE, Boolean +true, Boolean +try, Control +__try, Control +TTSS_step01, Highlight +TTSS_Task_end, Highlight +TTSS_Task_init, Highlight +TTSS_Task_step, Highlight +TTSS_step01, Highlight +TTSS_step02,Highlight +TTSS_step03,Highlight +TTSS_step04,Highlight +TTSS_step05,Highlight +TTSS_step06,Highlight +TTSS_step07,Highlight +TTSS_Task_step, Highlight +typedef, Control +typeid, Keyword +typename, Keyword +UINT, Keyword +union, Control +unsigned, Keyword +using, Keyword +virtual, Keyword +VOID, Keyword +void, Keyword +volatile, Keyword +wchar_t, Keyword +while, Control +WORD, Keyword +{, Delimiter +[, Delimiter +], Delimiter +}, Delimiter diff --git a/si4/ps5ws.si4project/soft_ps5ws.sip_sym b/si4/ps5ws.si4project/soft_ps5ws.sip_sym new file mode 100644 index 0000000..1b9f150 Binary files /dev/null and b/si4/ps5ws.si4project/soft_ps5ws.sip_sym differ diff --git a/si4/ps5ws.si4project/soft_ps5ws.sip_xab b/si4/ps5ws.si4project/soft_ps5ws.sip_xab new file mode 100644 index 0000000..ca441ee Binary files /dev/null and b/si4/ps5ws.si4project/soft_ps5ws.sip_xab differ diff --git a/si4/ps5ws.si4project/soft_ps5ws.sip_xad b/si4/ps5ws.si4project/soft_ps5ws.sip_xad new file mode 100644 index 0000000..4f3302b Binary files /dev/null and b/si4/ps5ws.si4project/soft_ps5ws.sip_xad differ diff --git a/si4/ps5ws.si4project/soft_ps5ws.sip_xc b/si4/ps5ws.si4project/soft_ps5ws.sip_xc new file mode 100644 index 0000000..c10b9f5 Binary files /dev/null and b/si4/ps5ws.si4project/soft_ps5ws.sip_xc differ diff --git a/si4/ps5ws.si4project/soft_ps5ws.sip_xf b/si4/ps5ws.si4project/soft_ps5ws.sip_xf new file mode 100644 index 0000000..7681842 Binary files /dev/null and b/si4/ps5ws.si4project/soft_ps5ws.sip_xf differ diff --git a/si4/ps5ws.si4project/soft_ps5ws.sip_xm b/si4/ps5ws.si4project/soft_ps5ws.sip_xm new file mode 100644 index 0000000..3a6d71d Binary files /dev/null and b/si4/ps5ws.si4project/soft_ps5ws.sip_xm differ diff --git a/si4/ps5ws.si4project/soft_ps5ws.sip_xr b/si4/ps5ws.si4project/soft_ps5ws.sip_xr new file mode 100644 index 0000000..46b54ef Binary files /dev/null and b/si4/ps5ws.si4project/soft_ps5ws.sip_xr differ diff --git a/si4/ps5ws.si4project/soft_ps5ws.sip_xsb b/si4/ps5ws.si4project/soft_ps5ws.sip_xsb new file mode 100644 index 0000000..bbee17a Binary files /dev/null and b/si4/ps5ws.si4project/soft_ps5ws.sip_xsb differ diff --git a/si4/ps5ws.si4project/soft_ps5ws.sip_xsd b/si4/ps5ws.si4project/soft_ps5ws.sip_xsd new file mode 100644 index 0000000..3bcc962 Binary files /dev/null and b/si4/ps5ws.si4project/soft_ps5ws.sip_xsd differ diff --git a/si4/ps5ws.si4project/soft_ps5ws.siproj b/si4/ps5ws.si4project/soft_ps5ws.siproj new file mode 100644 index 0000000..1254b64 Binary files /dev/null and b/si4/ps5ws.si4project/soft_ps5ws.siproj differ diff --git a/si4/ps5ws.si4project/soft_ps5ws.siproj_settings.xml b/si4/ps5ws.si4project/soft_ps5ws.siproj_settings.xml new file mode 100644 index 0000000..837f22c --- /dev/null +++ b/si4/ps5ws.si4project/soft_ps5ws.siproj_settings.xml @@ -0,0 +1,22 @@ + + + + + + + + + diff --git a/si4/ps5ws.si4project/soft_ps5ws.siwork b/si4/ps5ws.si4project/soft_ps5ws.siwork new file mode 100644 index 0000000..c3b9118 Binary files /dev/null and b/si4/ps5ws.si4project/soft_ps5ws.siwork differ diff --git a/source/33.txt b/source/33.txt new file mode 100644 index 0000000..ad7917e --- /dev/null +++ b/source/33.txt @@ -0,0 +1,141 @@ +#define, Keyword +#elif, Directive +#else, Directive +#endif, Directive +#if, Directive +#ifdef, Directive +#ifndef, Directive +#include, Keyword +#pragma, Keyword +#undef, Keyword +(, Delimiter +), Delimiter +",", Delimiter +;, Delimiter +abstract, Keyword +__abstract, Keyword +alignas, Keyword +alignof, Keyword +asm, Keyword +__asm, Keyword +assert, Debug +Assert, Debug +async, Keyword +auto, Keyword +bool, Keyword +break, Control +case, Control +catch, Control +cdecl, Keyword +__cdecl, Keyword +char, Keyword +class, Control +coclass, Control +const, Keyword +constexpr, Keyword +const_cast, Keyword +continue, Control +cout, Keyword +decltype, Keyword +default, Control +__delegate, Keyword +delete, Control +do, Control +double, Keyword +DWORD, Keyword +dynamic_cast, Keyword +each, Control +else, Control +enum, Control +__event, Keyword +except, Control +__except, Control +exception, Keyword +explicit, Keyword +export, Keyword +extern, Keyword +FALSE, Boolean +false, Boolean +FAR, Keyword +far, Keyword +final, Keyword +__finally, Control +float, Keyword +for, Control +fortran, Keyword +for_each, Control +friend, Keyword +__gc, Keyword +goto, Control +huge, Keyword +HUGE, Keyword +if, Control +inline, Keyword +INT, Keyword +int, Keyword +int16_t, Keyword +int32_t, Keyword +int64_t, Keyword +int8_t, Keyword +interface, Control +long, Keyword +LONG, Keyword +mutable, Keyword +namespace, Control +near, Keyword +NEAR, Keyword +new, Control +NULL, Null Value +nullptr, Null Value +__nullptr, Null Value +operator, Keyword +override, Keyword +PASCAL, Keyword +pascal, Keyword +private, Keyword +__property, Keyword +protected, Keyword +public, Keyword +ref, Keyword +register, Keyword +REGISTER, Keyword +reinterpret_cast, Keyword +return, Control +sealed, Keyword +short, Keyword +SHORT, Keyword +signed, Keyword +sizeof, Keyword +static, Keyword +static_cast, Keyword +struct, Control +__super, Keyword +switch, Control +template, Control +this, Keyword +thread_local, Keyword +throw, Control +TRUE, Boolean +true, Boolean +try, Control +__try, Control +ttss_task_init, Highlight +typedef, Control +typeid, Keyword +typename, Keyword +UINT, Keyword +union, Control +unsigned, Keyword +using, Keyword +value, Keyword +virtual, Keyword +VOID, Keyword +void, Keyword +volatile, Keyword +wchar_t, Keyword +while, Control +WORD, Keyword +[, Delimiter +{, Delimiter +], Delimiter +}, Delimiter diff --git a/source/app/common.c b/source/app/common.c new file mode 100644 index 0000000..762b98e --- /dev/null +++ b/source/app/common.c @@ -0,0 +1,75 @@ +#include "common.h" +//#include "../tpc/tpc_uart.h" +#include "../msp/msp_eeprom.h" +#include "../msp/msp_id.h" + +struct global_param G; +struct ts_eeprom_param eep_param; + +#define EEP_SECTOR_SIZE 0x200 +#define EEP_PARAM_ADDR (EEP_SECTOR_SIZE * 0) +#define ENC_KEY 0x01010101 + +#if 0 +void L3_eeprom_read(void) +{ + U8 dlen = 0; + L0_Iap_Read_array(EEP_PARAM_ADDR, (U8*)&eep_param, 2 + EEPROM_PARAM_DATA_MAX + 2); + if(eep_param.filter == EEPROM_PARAM_FILTER) + { + dlen = eep_param.len - 2; + crc16(eep_param.crc,(U8*)&eep_param,2+dlen); + if(eep_param.crc[0] == eep_param.buf[dlen] && eep_param.crc[1] == eep_param.buf[dlen+1]) + { + L0_uart0_uc('#'); + Lc_buf_copy_uc((U8*)&G.p,(U8*)eep_param.buf,dlen); + } + } +} +#endif + +void L3_eeprom_persist(void) +{ + U8 dlen = MCU_ID_KEY_LEN + MCU_ID_LEN; + eep_param.filter = EEPROM_PARAM_FILTER; + eep_param.len = dlen + 2; + Lc_buf_copy_uc((U8*)eep_param.enc_key,(U8*)&G.enc_key,MCU_ID_KEY_LEN); + Lc_buf_copy_uc((U8*)eep_param.enc_val,(U8*)&G.mcu_enc_id,MCU_ID_LEN); + crc16(eep_param.crc, &eep_param, 2+dlen); + + L0_Iap_Erase(EEP_PARAM_ADDR); + L0_Iap_Program_array(EEP_PARAM_ADDR, (U8*)&eep_param, 2 + dlen + 2); +} + + +void L3_chip_encrypt_main(void) +{ + U8 i = 0; + + //1.获取MCU_ID + L0_id_get_rom(G.mcu_id); + + for(i=0;i> 24 & 0xFF; + G.enc_key[1] = ENC_KEY >> 16 & 0xFF; + G.enc_key[2] = ENC_KEY >> 8 & 0xFF; + G.enc_key[3] = ENC_KEY >> 0 & 0xFF; + //eeprom中读取持久化的值 + //L3_eeprom_read(); +} + diff --git a/source/app/common.h b/source/app/common.h new file mode 100644 index 0000000..ff89038 --- /dev/null +++ b/source/app/common.h @@ -0,0 +1,78 @@ +#ifndef APP_COMMON_H +#define APP_COMMON_H + +#include "../clib/type.h" + +#define APP_VERSION 0x10 +#define P485_SLAVER_ID 0x01 +#define D_ADC_CHANNEL_MAX 4 + +#define D_MCU_BIGENDIAN 1 +// #define D_MCU_LITTLEENDIAN 1 + +#define D_COUNT_WEIGHT(adc,zadc) ((S32)((1.0 * G.p.ratio * G.p.weight_max * (adc - zadc)) / (2 * 0x7FFFFF / 1000 * D_ADS1213_GAIN_VAL * G.p.lmd))) +//#define D_COUNT_WEIGHT(adc,zWeight) ((S32)((1.0 * G.p.ratio * G.p.weight_max * (adc)) / (2 * 0x7FFFFF / 1000 * D_ADS1213_GAIN_VAL * G.p.lmd)) - zWeight) + +#define MCU_ID_LEN 7 +#define MCU_ID_KEY_LEN 4 + +enum tp_handle +{ + TP_HANDLED, + TP_UNHANDLE +}; + +/** + * EEPROM 存储结构 + */ +#define EEPROM_PARAM_DATA_MAX 64 +#define EEPROM_PARAM_FILTER 0xAA +typedef struct ts_eeprom_param +{ + U8 filter; + U8 len; + U8 enc_key[MCU_ID_KEY_LEN]; + U8 enc_val[MCU_ID_LEN]; + U8 crc[2]; +}EEPROM_PARAM; + +/** + * 用户协议 + */ + + +//协议类型: MODBUS RTU模式 +#define D_s_PH4_modbus_max (12) +typedef struct ts_ph4_modbus +{ + U8 salver; //从机地址 + U8 oper; //功能码 + U8 buf[D_s_PH4_modbus_max]; + U8 crc[2]; + U8 num; +}TS_PH4_modbus; + +/** + * Register Map + */ +typedef struct global_param +{ + U16 reserved; + U8 enc_key[MCU_ID_KEY_LEN]; + U8 mcu_id[MCU_ID_LEN]; + U8 mcu_enc_id[MCU_ID_LEN]; +}GlobalParam; + +extern struct global_param G; +extern void L3_reg_init(void); +extern void L3_chip_encrypt_main(void); + +//寄存器内存基地址 +#define REG_MEM_BASE ((U16*)(&G)) //寄存器基础地址(本文件外部不应该使用该宏定义) +//变量地址转寄存器 +#define MEM_2_REG(mem) (((U16*)(mem) - REG_MEM_BASE) + 1) +//寄存器转变量地址 +#define REG_2_MEM(reg) (REG_MEM_BASE + (U16)((reg) - 1)) + +#endif + diff --git a/source/app/main.c b/source/app/main.c new file mode 100644 index 0000000..88de581 --- /dev/null +++ b/source/app/main.c @@ -0,0 +1,153 @@ +////////////////////////////////////////////////////////////////////////// +/// COPYRIGHT NOTICE +/// Copyright (c) 2015, 传控科技 +/// All rights reserved. +/// +/// @file main.c +/// @brief main app +/// +///(本文件实现的功能的详述) +/// +/// @version 1.1 CCsens technology +/// @author CC +/// @date 20150102 +/// @note +/// +/// @version 1.2 CCsens technology +/// @author CC +/// @date 20180903 +/// @note cc_gsm_PD03SM_vh03_m10_debug01 +//20160413 CC-ACC-VH02 +//20170111 CC-ls_02 +// +//20170608 cc_as_stc01_main +// +//20180903 cc_gsm_PD03SM_vh03_m10_debug01 +// +// +/// @version 1.3 CCsens technology +/// @author CC +/// @date 20180903 +/// @note add calibrationg function +/// @version 1.4 CCsens technology +/// @author CC +/// @date 20190101 +/// @note add calibrationg function + +////////////////////////////////////////////////////////////////////////// + + +/// 下面是一个含有两个参数的函数的注释说明(简述) +/// +/// 这里写该函数的详述信息 +/// @param a 被测试的变量(param描述参数) +/// @param s 指向描述测试信息的字符串 +/// @return 测试结果(return描述返回值) +/// @see Test() (本函数参考其它的相关的函数,这里作一个链接) +/// @note (note描述需要注意的问题) +/************************************************ +stc5ac32s +程序结构 + + +有动静 + 并且采集的值小于c200 设置采集间隔缩短 + 采集值 在 c200 + + +#include "bsp_config0.h" + +#define D_version_v 'L' + + +#if 0 + +#define D_leda_OFF(); D_P35_OFF(); +#define D_leda_ON(); D_P35_ON(); +#define D_leda_REV(); D_P35_REV(); +#define D_ledb_OFF(); D_P34_OFF(); +#define D_ledb_ON(); D_P34_ON(); +#define D_ledb_REV(); D_P34_REV(); + +#else +#define D_leda_OFF(); ///D_P35_OFF(); +#define D_leda_ON(); ///D_P35_ON(); +#define D_leda_REV(); ///D_P35_REV(); +#define D_ledb_OFF(); ///D_P34_OFF(); +#define D_ledb_ON(); ///D_P34_ON(); +#define D_ledb_REV(); ///D_P34_REV(); + +#endif + + +#if 0 +#define D_debug_sim +#endif +//#define D_iic_inspect +#define D_open_save_f + +#define TYPE_UASER_BOARD ccSensor_WS_ps5ws //CC_SE_paper_main_m10_smt01.sch + +//STEP 2 TYPE_UASER_BOARD CONFIG >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +#if(TYPE_UASER_BOARD == ccSensor_WS_ps5ws)///-------TYPE_UASER_BOARD----------------TYPE_UASER_BOARD---------- +//2.0-5.5 8K 2kram 4k eeprom spi iic 2uart tssop20 stc8f2k08s2 1.2yuan +//2.0-5.5 16K 2kram 4k eeprom spi iic 2uart tssop20 stc8f2k16s2 1.4yuan + + +//1.7-5.5 8K 1kram 3k eeprom spi iic 2uart tssop20 stc8f2k16s2 1.1yuan + + + +#define D_version_h 0x37 +#define D_version_L 0x38 + + + #define TYPE_MCU TYPE_MCU_STC + #define TYPE_IDE TYPE_IDE_KEIL + + #include + #include + #include + + #include "../cpu/STC_stc8a8k.h" + +#if 0//// д + . ڲIRCƵ: 22.128MHz + . 绽ѶʱƵ: 35.575KHz + . Ŵʹ + . P3.2P3.3´޹ + . ϵ縴λʱӶĸλʱ + . λͨI/O + . ⵽ѹʱλ,ѹж + . ѹżѹ : 2.20 V + . ϵ縴λʱ,ӲڲŹ + . ϵԶڲŹʱԤƵΪ : 256 + . ״̬ʱŹʱֹͣ + . Ź,޸ķƵ,ܹرտŹ + . ´ûʱ,ûEEPROMһ + . ´ûʱ,ûصĶ˿ڿ485 + . ´ʱҪУؿ + . TXDֱͨRXDŵĵƽ + . оƬλ,TXDΪǿ + . оƬλ,P2.0ߵƽ + . ڲοѹ: 1341 mV (οΧ: 1270~1410mV) + . ڲŲʱ: 2018113 + + . оƬк : F64181C6219784 + Ƭͺ: STC8F2K08S2 + ̼汾: 7.3.10U + + . û趨Ƶ: 22.118MHz + . ںƵ: 22.128MHz + . Ƶʵ: 0.043% + + + ɹ !(2019-02-24 18:16:24) + +õƬĹ: 2.0-5v 8kflash 2kram DPTR EEPROM 4K + SPI IIC T0-T4 5ʱ 绽רöʱ Ƚ ڲѹж Ź tssop20 1.2Ԫ +#endif + + #include "../cpu/c51_macro.h" +#define D_MCLKO_DIV2 2 +#define D_MCLKO_DIV4 4 +#define D_MCLKO_DIV8 6 +#define D_MCLKO_DIV16 8 +#define D_MCLKO_DIV32 10 +#define D_MCLKO_DIV64 12 + +#define D_CPUfamily_type D_CPUfamily_8bits + + #define D_uart0_BRT BRT_115200 + #define D_uart0_SBIT SBIT_1 +#ifdef D_debug115200 + #if 0 + #define L2_task_L0_uart0_uc(X) L0_uart0_uc(X)/// + #define GC032a_L0_uart0_uc(x) L0_uart0_uc(x)// + #else + + #define L2_task_L0_uart0_uc(X) L0_uart0_uc(X)// + #define GC032a_L0_uart0_uc(x) L0_uart0_uc(x)// + #endif + +#else + #define L2_task_L0_uart0_uc(x) //L0_uart0_uc_debug(x)/////// + #define L2_task_L0_uart0_uchex(x) // L0_uart0_uchex(x)///// + + + #define GC032a_L0_uart0_uc(x) //L0_uart0_uc_debug(x)///// + #define GC032a_L0_uart0_uchex(x) //L0_uart0_uchex(x)//// + + + #define GC032a_L0_uart0_sendArray(x,Y) //L0_uart0_uchex(Y)// + #define GC032a_L0_uart0_us(x) //L0_uart0_us(x)*/ + +#endif +///#define D_sys_MainFre MainFre_16M2 +#define D_sys_MainFre MainFre_11M +///#define D_sys_MainFre MainFre_22M + +#if(MainFre_5M == D_sys_MainFre) + +#define D_Cdelay_200us 20 +#define D_Cdelay_1us 1 ////while p21תʱⶨ 500k 2us һָ +#elif(MainFre_22M == D_sys_MainFre) + +#define D_Cdelay_200us 10 +#define D_Cdelay_1us 10 ////while p21תʱⶨ 500k 2us һָ +#define D_Cdelay_1ms 36// 500 14ms 360--10ms +#define D_Cdelay_5ms 180// 500 14ms 360--10ms +#define D_Cdelay_15ms 900 +#define D_Cdelay_30ms 2400 + +#define L0_delay_1us() Lc_delay_nop(2) // 5nop() 100ns 50nop() 1us (20)=10us (2)1.5us +#define L0_delay_10us() Lc_delay_nop(20) // 5nop() 100ns 50nop() 1us (20)=10us (2)1.5us + + + +// 0x01/#define D_MCLKO_set D_MCLKO_DIV16 //1.389MHz/800ns@MCU.22MHz- +#define D_MCLKO_set D_MCLKO_DIV8 ////2.778MHz/400ns@MCU.22MHz- +///#define D_MCLKO_set D_MCLKO_DIV4 ////5.556MHz/ @MCU.22MHz- +///#define D_MCLKO_set D_MCLKO_DIV2 ////5.556MHz/ @MCU.22MHz- +#define D_0xfa 0x33 +//#define D_0xfa 0x11 + +/******************* +#define D_0xf7 0x01 +#define D_0xf8 0x02 + +#define D_P00x46 0x26////pclk /////cccc201805 hs low polarity +#define D_P00x4c 0x00 +#define D_P00x4d 0x04 +#define D_P00x43 0x10 ///EABLE CrCb fixed en 02 +#define D_P00x4a 0x83 ///div_gate+clk_en 82 + +#define D_P00xda 0xff /// Cr fixed +#define D_P00xdb 0xff /// Cb fixed + +#define D_0xfa 0x22 //00000000000000 + + +P0:0x4d Debug_mode3 8 0x04 RW +[7:4] test_image_fix_value + +[3] fix_value_mode +[2] remove_ff_mode +[1] subsample extend opclk disable when SPI +[0] clk2x_bypass +*******************/ + +#elif(MainFre_27M == D_sys_MainFre) + +#define D_Cdelay_200us 20 +#define D_Cdelay_1us 1 ////while p21תʱⶨ 500k 2us һָ + +#else ///MainFre_11M + +#define D_Cdelay_200us 20 +#define D_Cdelay_1us 1 + +#define D_Cdelay_1ms 36// +#define D_Cdelay_5ms 180// +#define D_Cdelay_15ms 900 +#define D_Cdelay_30ms 2400 +#if 0 +#define L0_delay_1us() Lc_delay_nop(5) // 5nop() 100ns 50nop() 1us (20)=10us (2)1.5us +#define L0_delay_10us() Lc_delay_nop(40) // 5nop() 100ns 50nop() 1us (20)=10us (2)1.5us +#define L0_delay_40us() Lc_delay_nop(150) // 5nop() 100ns 50nop() 1us (20)=10us (2)1.5us +#else +#define L0_delay_1us() Lc_delay_nop(0) // 5nop() 100ns 50nop() 1us (20)=10us (2)1.5us +#define L0_delay_10us() Lc_delay_nop(4) // 5nop() 100ns 50nop() 1us (20)=10us (2)1.5us //示波器测试结果 +#define L0_delay_40us() Lc_delay_nop(18) // 5nop() 100ns 50nop() 1us (20)=10us (2)1.5us +#endif + +#endif//D_sys_MainFre) +/*******>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +1 +1ѡʱ2Ϊʷ + AUXR &= 0xFB; //ʱ2ʱΪFosc/12,12T, +2 timer0 Ϊtaskʹ +L1_tick_tick +3 + +///<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<****/ + +#define D_IO_LED1_OFF() D_P35_OFF() +#define D_IO_LED2_OFF() D_P34_OFF() +#define D_IO_485_RE_OFF() D_P33_OFF() +#define D_IO_485_DE_OFF() D_P32_OFF() +#define D_IO_LED1_INIT() ///D_P35_INIT() +#define D_IO_LED2_INIT() ///D_P34_INIT() +#define D_IO_485_RE_INIT() ///D_P33_INIT() +#define D_IO_485_DE_INIT() ///D_P32_INIT() +#define D_IO_LED1_ON() D_P35_ON() +#define D_IO_LED2_ON() D_P34_ON() +#define D_IO_485_RE_ON() D_P33_ON() +#define D_IO_485_DE_ON() D_P32_ON() + + +////////////////////////////////sim iic config +//schĶ +#define L0_IIC_SIM_INIT() BITN_0(P3M1,5);BITN_0(P3M0,5);\ + BITN_0(P3M1,4);BITN_0(P3M0,4); +///stc10 +#define L0_IIC_SIM_close() BITN_1(P3M1,5);BITN_0(P3M0,5);\ + BITN_1(P3M1,4);BITN_0(P3M0,4); + +#if 10 +#define L0_SDA_ON() D_P34_ON() +#define L0_SDA_OFF() D_P34_OFF() +#define L0_SDA_AT() D_P34_AT() +#define L0_SCL_ON() D_P35_ON() +#define L0_SCL_OFF() D_P35_OFF() +#else + +#define L0_SDA_ON() //D_P34_ON() +#define L0_SDA_OFF() //D_P34_OFF() +#define L0_SDA_AT() //D_P34_AT() +#define L0_SCL_ON() //D_P35_ON() +#define L0_SCL_OFF() //D_P35_OFF() + +#endif + + +#if(BRT_4800 == D_uart0_BRT) +#define D_txd4_wakeup() P31 = 1 // >750us +#define D_txd4_low() P31 = 0 +////ΪӦ433 ģĹ +////debugʱм ˴ԴӰ lowЧķͲʹ,wakeup + + +#else +#define D_txd4_wakeup() //P31 = 1 // >750us +#define D_txd4_low() //P31 = 0 + + +#endif + + +#define DR_who_wakeup22 i2ctxd + + +///// DR: Define Register DRB:bit of Define Register +#define DR_isr_times SADDR + +#define DR_who_wakeup SADEN +#define DRB_who_wakeup_timer0 BITN0 +#define DRB_who_wakeup_action BITN1 +#define DRB_who_wakeup_voice BITN2 +#ifdef doc342343 +BITN_1(DR_who_wakeup, DRB_who_wakeup_timer0); +BITN_0(DR_who_wakeup, DRB_who_wakeup_timer0); + +if(BITN_G(DR_who_wakeup, DRB_who_wakeup_timer0)) +{ + +} +#endif + + + + +#elif(TYPE_UASER_BOARD == TYPE_BOARD_TI26_MT01_M178)///-------TYPE_UASER_BOARD----------------TYPE_UASER_BOARD---------- + #define TYPE_MCU TYPE_MCU_STC + #define TYPE_IDE TYPE_IDE_KEIL + + #include + #include + #include + + #include "../cpu/STC_stc8a8k.h" + + #define D_CPUfamily_type D_CPUfamily_8bits + +#elif(TYPE_UASER_BOARD == TYPE_BOARD_SMMM_MB_VH032_0E) + +#endif + +#endif//_BSP_CONFIG_H +/*********************************end file*********************************************/ + + diff --git a/source/bsp/bsp_config0.h b/source/bsp/bsp_config0.h new file mode 100644 index 0000000..dd08e90 --- /dev/null +++ b/source/bsp/bsp_config0.h @@ -0,0 +1,202 @@ +//////////////////////////////////////////////////////////////////////////// +///@copyright Copyright (c) 2017, ؿƼ All rights reserved. +///------------------------------------------------------------------------- +/// @file hard_config.h +/// @brief hard config include +/// @info FILE FOR HARDWARE SETUP AND SOFTWARE SETUP///FOR EXAMPLE: BAORD ,MCU,IDE +/// @info YOU CAN CHANGE OR ADD THE DEFINE IF YOU NEED +/// @info ǶʽĿ ȷϵ· Ȼȷcpu оƬͺ Ȼȷϱ ֮ Ӧó +/// @info bsp_CONFIG Ϊͷļʼ TYPE_BOARD_xx +///------------------------------------------------------------------------- +/// @version 1.1 +/// @author CC +/// @date 20180308 +/// @note +/// @version 1.6 +/// @author CC +/// @date 20190714 +/// @note add TTSS_tick TYPE +/// @version 1.7 +/// @author CC +/// @date 20191226 +/// @note gsensor + 485 + + +////////////////////////////////////////////////////////////////////////////// + + +////////////////////////////////////////////////////////////////////////// +#ifndef _BSP_CONFIG0_H +#define _BSP_CONFIG0_H +#include + +#include "../clib/Type.h" +#include "../clib/bit.h" +#include "../ctask/task.h" + +#include "../clib/clib.h" +////#define D_debug115200/// + + +//#define D_cameralIndex 0 +//#define D_cameralIndex 1 +//#define D_cameralIndex 2 +#define D_cameralIndex 3 +//#define D_cameralIndex 4 +//#define D_cameralIndex 5 + + +#define SBIT_1 1 //1 stop bit +#define SBIT_2 2 //2 stop bit + + +#define BRT_115200 115200 +#define BRT_19200 19200 +#define BRT_9600 9600 +#define BRT_4800 4800 +#define BRT_SIM 900 +#define MainFre_5M 0 +#define MainFre_11M 1 +#define MainFre_22M 2 +#define MainFre_27M 3 +#define MainFre_24M 4 +#define MainFre_33M 5 +#if 0 + +#define D_leda_OFF(); D_P35_OFF(); +#define D_leda_ON(); D_P35_ON(); +#define D_leda_REV(); D_P35_REV(); +#define D_ledb_OFF(); D_P34_OFF(); +#define D_ledb_ON(); D_P34_ON(); +#define D_ledb_REV(); D_P34_REV(); + +#else +#define D_leda_OFF(); ///D_P35_OFF(); +#define D_leda_ON(); ///D_P35_ON(); +#define D_leda_REV(); ///D_P35_REV(); +#define D_ledb_OFF(); ///D_P34_OFF(); +#define D_ledb_ON(); ///D_P34_ON(); +#define D_ledb_REV(); ///D_P34_REV(); + +#endif + + + +#if 0 +#define D_debug_sim +#endif +//#define D_iic_inspect +#define D_open_save_f + +//>>>>>>>>>>>>>>>>>>>>>>.BORAD TYPE +#define TYPE_BOARD_hhnew 16 +#define TYPE_BOARD_st_sleep04_01 4 +#define TYPE_BOARD_st_sleep03 5 +#define TYPE_BOARD_SMMM_MB_VH032_0E 6 +#define TYPE_BOARD_LPC17xx_ 8 +#define TYPE_BOARD_STM32F_103ZET6_READBULL 1036 +#define TYPE_BOARD_hh_CC_MD_VH05_anyriny_simple_m51 0x0551 +#define TYPE_BOARD_hh_CC_MD_VH06_asMain_m6a7 0x6a7 +#define TYPE_BOARD_TI26_MT01_M178 0x178 //ʱv TI26_MT01-M178 +#define TYPE_BOARD_stc5as32_WIFIBV01 532 +#define TYPE_BOARD_SHC16LAXXQN32 1632 //SHC16LAXXQN32 + +#define TYPE_BOARD_paper6133_m0a6 0xa6 //ֽŴ +#define TYPE_BOARD_paper_main_m10 0x10 //ֽŴ2 CC_SE_paper_main_m10_smt01.sch +#define ccSensor_CG_V02_m08_debug 0x0208 //CG2 +#define TYPE_BOARD_cc_Light_Speed0B 0x11b //LR2 + +#define TYPE_BOARD_cc_G0A03 0x123 //Ǹ2 +#define ccSensor_WS_ps5ws 0x0258 ///ش + + +/************************************* +оƬͺ : IRC15W207S +HSY037.XA +ڴоƬҪ˵: + жʱ0Ͷʱ2 (ע:޶ʱ1) + бȽ (ɵһ·ADCʹ) +************************/ +///cc_gsm_paper6133_m0a6_debug01 +//STEP 1 <<<<<<<<<<<<<<<<<<<<<<<<<<<.BORAD TYPE + + +// BORAD, +// MCU:SHC6601 +// IDE :KEIL +//>>>>>>>>>>>>>>>>>>>>>>mcu TYPE +#define TYPE_MCU_SHC6601 66 +#define TYPE_MCU_STC 51 +#define TYPE_MCU_LPC17xx 3217 +#define TYPE_MCU_STM32 3232 + +#define D_CPUfamily_8bits 8 +#define D_CPUfamily_16bits 16 +#define D_CPUfamily_32bits 32 +//<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>IDE TYPE + +#define TYPE_IDE_KEIL 1 +#define TYPE_IDE_MDK 2 +#define TYPE_IDE_IAR 3 + +//<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>G-SENSOR TYPE + +#define TYPE_ASENSOR_ADXL362 362 +#define TYPE_ASENSOR_MSA300 362 +#define TYPE_ASENSOR TYPE_ASENSOR_MSA300 +//<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>TTSS_tick TYPE + +#define D_TTSS_tick_5ms 5 +#define D_TTSS_tick_10ms 10 +#define D_TTSS_tick_25ms 25 + + +//<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + +//#define TYPE_UASER_BOARD TYPE_BOARD_SMMM_MB_VH032_0E +//#define TYPE_UASER_BOARD TYPE_BOARD_stc90c516rd +//#define TYPE_UASER_BOARD TYPE_BOARD_hh_CC_MD_VH06_asMain_m6a7 +//#define TYPE_UASER_BOARD TYPE_BOARD_stc5as32_WIFIBV01 +//#define TYPE_UASER_BOARD TYPE_BOARD_hhnew +//STEP 1 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +//>>>>>>>>>>>>>>>>>>>>>>TTSS_tick TYPE + +#define D_TTSS_tick_5ms 5 +#define D_TTSS_tick_10ms 10 +#define D_TTSS_tick_25ms 25 + + +//<<<<<<<<<<<<<<<<<<<<<= ul2fun2[m]) u32i = ul2fun2[m] - 1; + for(m = 0;m > 4;m ++) + {// 43210 + d = (u32i /ul2fun2[m])%10; + if (d > 0) + str[n] = d; + n ++; + } + + if (n == point_num) + { + str[n] ='.'; + n ++; + } + + + str[n] = i%10 + +} + +void L0_Delay_ms(unsigned int time) +{ + unsigned int j; + for(;time > 0;time --) + { + j = D_l0_delay_ms; + while(j--) + ; + } +} + + +//22m 50ms --delay ms 100 j=150 +void L1_delay_test(void) +{ + while(9) + { + L0_Delay_ms(100); + P2 = !P2; + } + +}void Lc_delay_us(unsigned int n) +{ +// unsigned char j; + for(;n > 0;n --) + { + //j = 2; + // while(j--) + // ; + }65 300 +} +#endif + +void Lc_delay_us(vU16 i) +{ + vU16 m; + i=i/10; + for(m=i;m>0;m--) + { + Lc_delay_1us(); + } +} + +void Lc_delay_nop(U8 i) +{ + U8 m; + for(m=i;m>0;m--) + { + NOP(); + } +} + + + + +// D_1ms_delay_para +///22m 300 +/// 22M 100ns 5个100ns 20ns +void Lc_delay_ms(vU16 i) +{ + vU16 m,n; + for(m=i;m>0;m--) + { + #ifdef D_debug_time + ; + #else + //D_debug_time_using + for(n= 85;n > 0;n--) + { + L0_delay_10us();//10us + } + #endif + } +} + +void Lc_buf_copy_uc(U8 *d,const U8 *s,U16 num) +{ + U16 i; + for(i = 0; i < num; i ++) + { + *(d+i) = *(s+i); + } + +} + +vU8 Lc_U8_media3(vU8 a,vU8 b,vU8 c) +{ + if(a > b) + { + if(b > c) + { + return b; + }else + {// b a) + {/// a a) + {// a b) + { + if(b > c) + { + return b; + } + else + {// b a) + {/// a a) + {// a arr[j+1]) + { + ok = 0; + tmp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = tmp; + } + } + if(ok) + { + break; + } + } +} + +vS32 Lc_S32_media(vS32 val[],S16 num) +{ + if(num <= 1) + { + return val[0]; + } + else + { + Lc_array_sort(val,num); + return val[num/2]; + } +} + + +///// 0 1 (1-0)+1 +//// 把buf中的数据从[usStart]到[usEnd] 共 usEnd-usStart+1 的数据转换成ascii +/// 0x11 0x22 ---> 0x31 0x31 0x32 0x32 '1' '1' '2' '2' +void Lc_hex2ascii(U8 *buf,U16 len,U8 *ascii) +{ + vU16 t = 0,m = 0; + for(t = 0;t < len;t ++) + { + + #if 1 + ascii[m] = cguHex2Char[D_uc_high(buf[t])][1]; + m ++; + ascii[m] = cguHex2Char[D_uc_low (buf[t])][1]; + m ++; + ascii[m] =0x20; + m ++; + #else + + ascii[m] = 0x30+m; + m++; + ascii[m] = 0x30+m; + m++; + ascii[m] = 0x30+m; + m++; + + + #endif + } +} + +/// cguHex2Char[0][0] = 0x00 cguHex2Char[0][1] = 0x30 +unsigned char code cguHex2Char[16][2] +={ + 0x00,'0', + 0x01,'1', + 0x02,'2', + 0x03,'3', + 0x04,'4', + 0x05,'5', + 0x06,'6', + 0x07,'7', + 0x08,'8', + 0x09,'9', + 0x0A,'A', + 0x0B,'B', + 0x0C,'C', + 0x0D,'D', + 0x0E,'E', + 0x0F,'F' +}; + + +void crc16(unsigned char *CRC,void *dat,unsigned int len) +{ + unsigned char *ptr = (unsigned char *)dat; + unsigned long wcrc=0XFFFF;//预置16位crc寄存器,初值全部为1 + unsigned char temp;//定义中间变量 + int i=0,j=0;//定义计数 + for(i=0;i>=1;//先将数据右移一位 + wcrc^=0XA001;//与上面的多项式进行异或 + } + else//如果不是1,则直接移出 + { + wcrc>>=1;//直接移出 + } + } + } + temp=wcrc;//crc的值 + CRC[0]=wcrc;//crc的低八位 + CRC[1]=wcrc>>8;//crc的高八位 +} + + +U32 Lc_abs(vS32 a,vS32 b) +{ + if(a >= b) + { + return a - b; + } + return b - a; +} + +void Lc_encrypt_id(U8 *enc_dst, U8 *enc_src, U32 enc_key, U8 src_len) +{ + U8 i = 0,key0,key1,key2,key3; + key0 = enc_key >> 24 & 0xFF; + key1 = enc_key >> 16 & 0xFF; + key2 = enc_key >> 8 & 0xFF; + key3 = enc_key >> 0 & 0xFF; + + for(i=0;i> 0) & 0xFF) << 24) | (((dat >> 8) & 0xFF) << 16) | (((dat >> 16) & 0xFF) << 8) | (((dat >> 24) & 0xFF) << 0); + } + return res; +} + +U32 htonl(U32 dat) +{ + U32 res = 0; + if(dat == 0 || isBigEndianOrder()){ + res = dat; + }else{ + res = (((dat >> 0) & 0xFF) << 24) | (((dat >> 8) & 0xFF) << 16) | (((dat >> 16) & 0xFF) << 8) | (((dat >> 24) & 0xFF) << 0); + } + return res; +} + +U16 ntohs(U16 dat) +{ + U16 res = 0; + if(dat == 0 || isBigEndianOrder()){ + res = dat; + }else{ + res = (((dat >> 0) & 0xFF) << 8) | (((dat >> 8) & 0xFF) << 0) ; + } + return res; +} + +U16 htons(U16 dat) +{ + U16 res = 0; + if(dat == 0 || isBigEndianOrder()){ + res = dat; + }else{ + res = (((dat >> 0) & 0xFF) << 8) | (((dat >> 8) & 0xFF) << 0) ; + } + return res; +} +#endif + +#if 0///#ifdef D_flash_max + + +// 0--9 '0' +// ABCEDF------0X41-- 87-6= 81 +U8 Lc_Hex2Char(U8 CharStr) +{ + U8 rd; + if (CharStr >9)//A 10-9+ + { + rd = (CharStr - 10 + 'A') ; + } + else + { + rd = (CharStr + '0') ; + } + return rd; +} +// 0x30'0'----'9'--> 0x0----0x09 +//0x61--'a'---'f'--> 0x0a---0x0f +//0x41 'A'--'F'--> 0x0a---0x0f +U8 Lc_Char2Hex(U8 CharStr) +{ + U8 rd; + if (CharStr >= 'a')//0x61--'a'---'f'--> 0x0a---0x0f + { + rd = (CharStr - 'a' + 0x0a) ; + } + else if (CharStr >= 'A')//0x61--'a'---'f'--> 0x0a---0x0f + { + rd = (CharStr - 'A' + 0x0a) ; + } + else + { + rd = (CharStr - '0') ; + } + return rd; +} +//catch_protocol(s,d); +// 从 d中提取出协议,一般用于协议打包后的调试和透传, +// *s="iicsend:12 34 56 78 9a \r\n"; +// i: 012345678 +// 返回协议字节数量 +// extern int strpos (const char *s, char c); +unsigned char catch_protocol (const char *d_src,char d_protocol[]) +{ + unsigned char n = 0,len = 0;//,i = 0; + int i = 0; + i = strpos(d_src, (char)':'); + i ++; + len = strlen (d_src) - 2; + while(i < len) + { + d_protocol[n] = Lc_Char2Hex(*(d_src+i))*16; + i ++; + d_protocol[n] += Lc_Char2Hex(*(d_src+i)); + i ++;i ++; + n ++; + } + return n; +} + +/* + * 函数名:itoa 不同类型的cpu不一样 并且支持的最大数据取决于i = 1000000;D_value_max + * 描述 :将整形数据转换成字符串 + * 输入 :-radix =10 表示10进制,其他结果为0 + * -value 要转换的整形数 + * -buf 转换后的字符串 + * -radix = 10 + * 输出 :无 + * 返回 :无 + * 调用 :被USART1_printf()调用 + + Lc_int2a + + + */ + #define D_value_max 100000 +char *Lc_int2a(vS32 value, char *string, UN_TYPE radix) +{ + vS32 i, d; + UN_TYPE flag = 0; + vU16 U16temp = 0; + char *ptr = string; + + /* This implementation only works for decimal numbers. */ + //value + if (!value) + { + *ptr++ = 0x30; + *ptr = 0; + return string; + } + U16temp = value; + switch(radix) + {//%X2 %X4 %X6 + case '2': + *ptr++ = Lc_Hex2Char((U16temp>>4)&0x0f); + *ptr++ = Lc_Hex2Char((U16temp)&0x0f); + *ptr = 0; + return string; + break; + case '4': + *ptr++ = Lc_Hex2Char((U16temp>>12)&0x0f); + *ptr++ = Lc_Hex2Char((U16temp>>8)&0x0f); + *ptr++ = Lc_Hex2Char((U16temp>>12)&0x0f); + *ptr++ = Lc_Hex2Char((U16temp>>8)&0x0f); + *ptr++ = Lc_Hex2Char((U16temp>>4)&0x0f); + *ptr++ = Lc_Hex2Char((U16temp)&0x0f); + *ptr = 0; + return string; + break; + #if 0 + case '8': + *ptr++ = Lc_HexToChar((value>>24)&0x0f); + *ptr++ = Lc_HexToChar((value>>20)&0x0f); + *ptr++ = Lc_HexToChar((value>>16)&0x0f); + *ptr++ = Lc_HexToChar((value>>12)&0x0f); + *ptr++ = Lc_HexToChar((value>>8 )&0x0f); + *ptr++ = Lc_HexToChar((value>>4 )&0x0f); + *ptr++ = Lc_HexToChar((value)&0x0f); + *ptr = 0; + return string; + break; + #endif + case 10: + /* if this is a negative value insert the minus sign. */ + if (value < 0) + { + *ptr++ = '-'; + + /* Make the value positive. */ + value *= -1; + } + i = D_value_max; + if (value > i) + { + value = i; + } + for (;i > 0; i /= 10) + { + d = value / i; + + if (d || flag) + { + *ptr++ = (char)(d + 0x30); + value -= (d * i); + flag = 1; + } + } + + /* Null terminate the string. */ + *ptr = 0; + + return string; + break; + default: + *ptr++ = 0x30; + *ptr = 0; + return string; + break; + } + + +} /* NCL_Itoa */ +/// bits:生成的字符共几位数据 +void Lc_int2D(vS16 value, char *string,char bits) +{ + vS16 i, d; + UN_TYPE flag = 0; +// vU16 U16temp = 0; + char *ptr = string; + + /* This implementation only works for decimal numbers. */ + //value + +// U16temp = value; + /* if this is a negative value insert the minus sign. */ + if (value < 0) + { + *ptr++ = '-'; + value *= -1; + }else + { + *ptr++ = ' '; + + } + + + + i = us2fun2[bits-1]; + for (;i > 0; i /= 10) + { + d = value / i; + if((0 == d)&&(0 == flag)&&(1 != i)) + {/// + *ptr++ = ' '; + + }else + { + flag = 1;///第一个非零的数据出现 + *ptr = (char)(d + 0x30); + *ptr++; + value -= (d * i); + } + } + +} /* NCL_Itoa */ + + +//void (*L0_uart0_uc)(U8 ww); + +// 带buf的printf fixme: 需要精简地方 +void Lc_print_buf(char *dat4,...) +{ + const char *s; + vS32 d; + char buf[64]; ///取决于cpu的内存大小,如果出现问题,请先定位到此处 +// char send[16]; + char n = 0; + char *dat = 0; + va_list ap;//va_list 是一个字符指针,可以理解为指向当前参数的一个指针, + //取参必须通过这个指针进行。 +// 在调用参数表之前,定义一个 va_list 类型的变量, +//(假设va_list 类型变量被定义为ap); + va_start(ap, dat); +// 然后应该对ap 进行初始化,让它指向可变参数表里面的第一个参数, +//这是通过 va_start 来实现的,第一个参数是 ap 本身,第二个参数是在 +//变参表前面紧挨着的一个变量,即“...”之前的那个参数; + + dat = dat4; +// 然后是获取参数,调用va_arg,它的第一个参数是ap, +//第二个参数是要获取的参数的指定类型,然后返回这个指定类型的值, +//并且把 ap 的位置指向变参表的下一个变量位置; + //"e645654675y73\0" + while ( *dat != 0) // 判断是否到达字符串结束符 + { + if ( *dat == 0x5c ) //'\' + { + switch ( *++dat ) + { + case 'r': //回车符 + ts_uart_send_depot.buf[n ++] = 0x0d;//L0pf_send_uc(0x0d); + dat ++; + break; + + case 'n': //换行符 + ts_uart_send_depot.buf[n ++] = 0x0a;//L0pf_send_uc(0x0a); + dat ++; + break; + + case 't': // + ts_uart_send_depot.buf[n ++] = 0x09;//L0pf_send_uc(0x09); + dat ++; + break; + default: + dat ++; + break; + } + } + else if ( *dat == '%') + { // + switch ( *++dat ) + { + case 'C': + case 'c': //字符 + //va_arg()里的任务就是根据指定的参数类型 + //取得本参数的值,并且把指针调到下一 + //个参数的起始地址 + //#define va_arg(ap,t) + //( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) ) + + //char *ap; %c " , 0x30, + s = va_arg(ap, const char *); // 0x30 + ts_uart_send_depot.buf[n ++] = (char)s;// L0pf_send_uc((char)s); // '0' + dat++; + break; + case 'd': //十进制 + //" %d",0x30, + //" %d",48, + // int i = 48; + //" %d",i, + + d = va_arg(ap, int); // 0x30 =48d + Lc_int2a(d, buf, 10); //"buf="48" buf[0]='4' buf[1]='8' + for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s + { //\0 + ts_uart_send_depot.buf[n ++] = *s;//L0pf_send_uc(*s); + //printf("%c",*s); + } + dat++; + break; + case 'X': + case 'x': //字符串 + d = va_arg(ap, int); // 0x30 =48d + dat++;//%X2 %X4 %X8 + Lc_int2a(d, buf, *dat); //"buf="48" buf[0]='4' buf[1]='8' + for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s + { //\0 + ts_uart_send_depot.buf[n ++] = *s;//L0pf_send_uc(*s); + } + dat++; + break; + case 'S': + case 's': //字符串 + s = va_arg(ap, const char *); + for ( ; *s; s++) + { + ts_uart_send_depot.buf[n ++] = *s;//L0pf_send_uc(*s); + } + dat++; + break; + case 'f': //十进制 + d = va_arg(ap, int); + Lc_int2a(d, buf, 10); + for (s = buf; *s; s++) + { + ts_uart_send_depot.buf[n ++] = *s;//L0pf_send_uc(*s); + + } + dat++; + break; + default: + dat++; + break; + } + } /* end of else if */ + else + { + ts_uart_send_depot.buf[n ++] = (*dat++);//L0pf_send_uc( *dat++); + } + }//end while.... + ts_uart_send_depot.max = n; + ts_uart_send_depot.p = ts_uart_send_depot.buf; + L0_uart0_sendbuf(); +}// +#endif + +#ifdef D_use_crc16 +/* +CRC码的步骤为: + +(1).预置16位寄存器为FFFFH。称此寄存器为CRC寄存器; + +(2).把第一个8位数据与CRC寄存器的低位相异或,把结果放于CRC寄存器; + +(3).把寄存器的内容右移一位(朝低位),用0填补最高位,检查最低位; + +(4).如果最低位为0:重复第3步(再次移位)如果最低位为1:CRC寄存器与多项式A001(1010 0000 0000 0001)进行异或; + +(5).重复步骤3和4,直到右移8次,这样整个8位数据全部进行了处理; + +(6).重复步骤2到步骤5,进行下一个8位数据的处理; + +(7).最后得到的CRC寄存器即为CRC码。(CRC码 = CRC_L +CRC_H) + +*/ + + +/*****************crc校验**********************************************/ + +//crc生成函数,并将crc存储在预先定于的数组中 + +//调用方式crc16(指向数据的指针,需要校验的数据长度) + +unsigned char CRC[2];//定义数组 + +void crc16(unsigned char *ptr,unsigned int len) +{ + unsigned long wcrc=0XFFFF;//预置16位crc寄存器,初值全部为1 + unsigned char temp;//定义中间变量 + int i=0,j=0;//定义计数 + for(i=0;i>=1;//先将数据右移一位 + wcrc^=0XA001;//与上面的多项式进行异或 + } + else//如果不是1,则直接移出 + { + wcrc>>=1;//直接移出 + } + } + } + temp=wcrc;//crc的值 + CRC[0]=wcrc;//crc的低八位 + CRC[1]=wcrc>>8;//crc的高八位 +} +code U8 auchCRCHi[]= +{ +0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, +0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, +0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, +0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, +0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, +0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, +0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, +0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, +0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, +0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, +0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, +0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, +0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, +0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, +0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, +0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, +0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, +0x40 +}; + +code U8 auchCRCLo[] = +{ +0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, +0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, +0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, +0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, +0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7, +0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, +0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, +0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, +0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2, +0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, +0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, +0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, +0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 0x50, 0x90, 0x91, +0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, +0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, +0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, +0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, +0x40 +}; + +U16 N_CRC16(U8 *updata,U8 len) +{ + U8 uchCRCHi=0xff; + U8 uchCRCLo=0xff; + U8 uindex; + while(len--) + { + uindex = uchCRCHi^*updata++; + uchCRCHi = uchCRCLo^auchCRCHi[uindex]; + uchCRCLo = auchCRCLo[uindex]; + } + return (uchCRCHi<<8 | uchCRCLo); +} + +#endif +#if 0 //5436345673456 +/******************************************************************** +* +* 名称: L0_Usend_uc_hex +* 说明: 例如:L0_Usend_uc_hex(0x0c); output " 0c " +* 功能: 发送数据 +* 调用: SendHUc()Lc_HexToChar() +* 输入: +* 返回值: 无 +***********************************************************************/ +void Lc_uc_hex(char ww) +{ + L0_uart0_uc(Lc_Hex2Char((ww>>4)&0x0f)); + L0_uart0_uc(Lc_Hex2Char(ww&0x0f)); +} + +void Lc_us_hex(U16 ww) +{// + U8 t; + t = (U8)(((ww >> 8)&0x00ff)); + Lcp_uc_hex(t); + t = (U8)(((ww )&0x00ff)); + Lcp_uc_hex(t); +} + +void Lc_print_NC(char *dat,...) +{ + +} +// 非缓存模式的打印 fixme: 发送16进制数据时有bug +void Lc_print33333(char *dat4,...) +{ + const char *s; + vS32 d; + char buf[16];//char t; + char *dat = NULL; + va_list ap;//va_list 是一个字符指针,可以理解为指向当前参数的一个指针, + //取参必须通过这个指针进行。 +// 在调用参数表之前,定义一个 va_list 类型的变量, +//(假设va_list 类型变量被定义为ap); + va_start(ap, dat4); +// 然后应该对ap 进行初始化,让它指向可变参数表里面的第一个参数, +//这是通过 va_start 来实现的,第一个参数是 ap 本身,第二个参数是在 +//变参表前面紧挨着的一个变量,即“...”之前的那个参数; +dat =dat4; +// 然后是获取参数,调用va_arg,它的第一个参数是ap, +//第二个参数是要获取的参数的指定类型,然后返回这个指定类型的值, +//并且把 ap 的位置指向变参表的下一个变量位置; + //"e645654675y73\0" + while ( *dat != 0) // 判断是否到达字符串结束符 + { + if ( *dat == 0x5c ) //'\' + { + switch ( *++dat ) + { + case 'r': //回车符 + L0_uart0_uc(0x0d); + dat ++; + break; + + case 'n': //换行符 + L0_uart0_uc(0x0a); + dat ++; + break; + + case 't': // + L0_uart0_uc(0x09); + dat ++; + break; + default: + dat ++; + break; + } + } + else if ( *dat == '%') + { // + switch ( *++dat ) + { + case 'C': + case 'c': //字符 + //va_arg()里的任务就是根据指定的参数类型 + //取得本参数的值,并且把指针调到下一 + //个参数的起始地址 + //#define va_arg(ap,t) + //( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) ) + + //char *ap; %c " , 0x30, + s = va_arg(ap, const char *); // 0x30 + L0_uart0_uc((char)s); // '0' + dat++; + break; + case 'd': //十进制 + //" %d",0x30, + //" %d",48, + // int i = 48; + //" %d",i, //#define va_arg(ap,t) (((t *)ap)++[0]) //(((int *)ap)++[0]) + + d = va_arg(ap, int); // 0x30 =48d + d >>= 8; + Lc_int2a(d, buf, 10); //"buf="48" buf[0]='4' buf[1]='8' + for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s + { //\0 + L0_uart0_uc(*s); + //printf("%c",*s); + } + dat++; + break; + case 'X': + case 'x': //字符串 + d = va_arg(ap, int); // 0x30 =48d + d >>= 8; + dat++;//%X2 %X4 %X8 + Lc_int2a(d, buf, *dat); //"buf="48" buf[0]='4' buf[1]='8' + for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s + { //\0 + L0_uart0_uc(*s); + } + dat++; + break; + case 'S': + case 's': //字符串 + s = va_arg(ap, const char *); + for ( ; *s; s++) + { + L0_uart0_uc(*s); + } + dat++; + break; + case 'f': //十进制 + d = va_arg(ap, int); + Lc_int2a(d, buf, 10); + for (s = buf; *s; s++) + { + L0_uart0_uc(*s); + + } + dat++; + break; + default: + dat++; + break; + } + } /* end of else if */ + else + { + L0_uart0_uc(*dat ++); + //t = *dat; + //L0pf_send_uc = L0_uart0_uc; + //L0pf_send_uc(t); + //L0_uart0_uc(t); + //dat++; + } + }//end while....斯蒂芬 +}// + + + + + +///计算CRC校验码 +unsigned int CRC16(unsigned char *ptr, unsigned char len) +{ + unsigned int crc=0xffff; + unsigned char i; + while(len--) + { + crc ^=*ptr++; + for(i=0;i<8;i++) + { + if(crc & 0x1) + { + crc>>=1; + crc^=0xa001; + } + else + { + crc>>=1; + } + } + } + return crc; +} + + + +///检测CRC校验码是否正确 +unsigned char CheckCRC(unsigned char *ptr,unsigned char len) +{ + unsigned int crc; + crc = (unsigned int)CRC16(ptr,(len-2)); + if(ptr[len-1]==(crc>>8) && ptr[len-2]==(crc & 0x00ff)) + { + return 0xff; + } + else + { + return 0x0; + } +} + + +char *strstr(const char *str1, const char *str2) +{ + char *cp = (char*)str1; + char *s1, *s2; + + if (!*str2) + return((char *)str1); + + while (*cp) + { + s1 = cp; + s2 = (char *)str2; + + while (*s1 && *s2 && !(*s1 - *s2)) + s1++, s2++; + + if (!*s2) + return(cp); + + cp++; + } + return(NULL); +} + + + +//12,34 +void Lc_int2str_2_2(U32 ui_in,char *d) +{ + U8 m = 0;//,i; + + if (ui_in >= ul2fun2[4])// 1000 123456 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(4));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + if (ui_in >= ul2fun2[3])// 1000 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(3));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + + if (ui_in >= ul2fun2[2])// 100 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = '0'; + m ++; + } + + *(d+m) = '.'; + m ++; + if (ui_in >= ul2fun2[1])// 10 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = '0'; + m ++; + } + *(d+m) = 0x30 + Lc_WEI(ui_in,0); + +} + + + +// 123.4 + +void Lc_int2str_3_1(U32 ui_in,char *d) +{ + U8 m = 0;//,i; + if (ui_in >= ul2fun2[4])// 1000 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(4));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + + + if (ui_in >= ul2fun2[3])// 1000 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(3));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + + if (ui_in >= ul2fun2[2])// 100 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + + if (ui_in >= ul2fun2[1])// 10 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = '0'; + m ++; + } + *(d+m) = '.'; + m ++; + *(d+m) = 0x30 + Lc_WEI(ui_in,0); + +} + + +//-123 +void Lc_sint2str_3(int i_in,char *d) +{ + U8 m = 0;//,i; + U32 ui_in; + if(i_in < 0) + { + ui_in = (U32)(0-i_in); + *(d+m) = '-'; + }else + { + ui_in = (U32)(i_in); + *(d+m) = ' '; + } + m ++; + + if (ui_in >= ul2fun2[2])// 100 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + + if (ui_in >= ul2fun2[1])// 10 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + *(d+m) = 0x30 + Lc_WEI(ui_in,0); +} + + +// 12345 + +void Lc_int2str_5(U32 ui_in,char *d) +{ + U8 m = 1;//,i; + *(d+0) = ' '; + if (ui_in >= ul2fun2[4])// 10,000 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(4));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + + + if (ui_in >= ul2fun2[3])// 1,000 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(3));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + + if (ui_in >= ul2fun2[2])// 100 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + + if (ui_in >= ul2fun2[1])// 10 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + + *(d+m) = 0x30 + Lc_WEI(ui_in,0); + +} +//40 +void Lc_int2str_4(U32 ui_in,char *d) +{ + U8 m = 0;//,i; + + if (ui_in >= ul2fun2[3])// 1,000 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(3));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + + if (ui_in >= ul2fun2[2])// 100 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + + if (ui_in >= ul2fun2[1])// 10 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + *(d+m) = 0x30 + Lc_WEI(ui_in,0); +} + + +// 123 +void Lc_int2str_3(U32 ui_in,char *d) +{ + U8 m = 0;//,i; + + if (ui_in >= ul2fun2[2])// 100 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + + if (ui_in >= ul2fun2[1])// 10 12345 + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + *(d+m) = 0x30 + Lc_WEI(ui_in,0); +} + + +//Lc_int2str(123456, 5,3,&str[0]'); +/* + + +blank 填充字符 ' '或者其他unsigned char *blank)//保留以后使用 + + +*/ + + + +void Lc_int2str(U32 ui_in,UN_TYPE len,UN_TYPE point,char *d) +{ + U8 m = 0,i; + for(i = 0;i < len;i++) + { + if(point != 0) + { + if(point == (len-i+1)) + { + *(d+m) = '.'; + m ++; + } + } + if (ui_in>=ul2fun2[len-i]) + { + *(d+m) = 0x30 + Lc_WEI(ui_in,(len-i));// (unsigned char)((ui_in/ul2fun2[len-i])%10); + m ++; + } + else + { + *(d+m) = ' '; + m ++; + } + } + *(d+m) = 0x30 + Lc_WEI(ui_in,1); + m++; + *(d+m) = 0x00; + //*(d+m) = 'e'; +} + + +// input: 123456d +// output: '1' '2' '3'.... +//对应的点阵 为 0123456789. ,最后为空格,专为显示点阵类的数值使用 +void Lc_int2number(U32 ui_in,UN_TYPE len,UN_TYPE point,char *d) +{ + U8 i,m = 0; //uc_temp, + for(i = len+1;i != 0;i--)// len + 1 point 占用一位 + { + if(point == (len-i)) + { + d[len-m] = '.';//'.' + m ++; + } + { + if (ui_in>=ul2fun2[i-1]) + { + d[len-m] = (U8)((ui_in/ul2fun2[i-1])%10); + + } + else + { + d[len-m] = ' ';//' ' + } + m ++; + } + } + d[len-m] = (U8)(ui_in%10); +} + +void Lc_Byte_cp(BYTE *src,BYTE *dis, int len) +{ + int i; + for(i = 0; i < len ;i ++) + { + *dis = *src; + dis ++; + src ++; + } + //return 0; +} +/* +void Lc_Byte_print(BYTE *src,int len) +{ + int i, d; + for(i = 0; i < len ;i ++) + { + *dis = *src; + dis ++; + src ++; + } + //return 0; +} +*/ + + +// -10........+10 + +U32 L2_fun_number_show(int i,char str[4]) +{ + U8 c; + int cint; + + if(i >= 0) + { + cint = i; + str[0] =' '; + + } + else + { + cint = 0 - i; + str[0] ='-'; + + + } + c = Lc_WEI(cint,1); + if(0 == c) + { + str[1] =' '; + } + else + { + str[1] = 0x30+ c; + + } + str[2] = 0x30+ Lc_WEI(cint,0); + return 0; +} + +//L1_lkt_write(s_room_val.ui_t3,s_room_val.ui_t3,s_task_lkt.din); +//U_uluiuc + +void Lc_2ui2buf(vU32 ui_t2,vU32 ui_t3,volatile BYTE out[]) +{ +#if 0 + volatile U_uluiuc t; + //s_temp[] + t.uiv[0] = ui_t2; + t.uiv[1] = ui_t3; + + + Lc_Byte_cp(t.dv,out,8); + + out[3] = D_ul2uc_0( ui_t2); + ui_t2 >>= 8; + out[2] = D_ul2uc_0( ui_t2); + ui_t2 >>= 8; + out[1] = D_ul2uc_0( ui_t2); + ui_t2 >>= 8; + out[0] = D_ul2uc_0( ui_t2); + + + out[7] = D_ul2uc_0( ui_t3); + ui_t2 >>= 8; + out[6] = D_ul2uc_0( ui_t3); + ui_t2 >>= 8; + out[5] = D_ul2uc_0( ui_t3); + ui_t2 >>= 8; + out[4] = D_ul2uc_0( ui_t3); + + + #else + out[0] = D_ul2uc_0( ui_t2); + ui_t2 >>= 8; + out[1] = D_ul2uc_0( ui_t2); + ui_t2 >>= 8; + out[2] = D_ul2uc_0( ui_t2); + ui_t2 >>= 8; + out[3] = D_ul2uc_0( ui_t2); + +/* + out[4] = D_ul2uc_0( ui_t3); + ui_t2 >>= 8; + out[5] = D_ul2uc_0( ui_t3); + ui_t2 >>= 8; + out[6] = D_ul2uc_0( ui_t3); + ui_t2 >>= 8; + out[7] = D_ul2uc_0( ui_t3); +*/ +#endif + +} + +void L1_buf22ui(volatile BYTE in[],vU32 *ui_t2,vU32 *ui_t3) +{ + #if 0 + volatile U_uluiuc t; + Lc_Byte_cp(in,t.dv,8); + *ui_t2 = t.uiv[0]; + *ui_t3 = t.uiv[1]; + *ui_t2 = 0; + *ui_t2|= (U32)in[3]; + *ui_t2|= (U32)(in[2]<<8); + *ui_t2|= (U32)(in[1]<<16); + *ui_t2|= (U32)(in[0]<<24); + + *ui_t3 = 0; + *ui_t3|= (U32)in[7]; + *ui_t3|= (U32)(in[6]<<8); + *ui_t3|= (U32)(in[5]<<16); + *ui_t3|= (U32)(in[4]<<24); + + #else + + + *ui_t2 = 0; + *ui_t2|= (U32)in[0]; + *ui_t2|= (U32)(in[1]<<8); + *ui_t2|= (U32)(in[2]<<16); + *ui_t2|= (U32)(in[3]<<24); + /* + *ui_t3 = 0; + *ui_t3|= (INT32U)in[4]; + *ui_t3|= (INT32U)(in[5]<<8); + *ui_t3|= (INT32U)(in[6]<<16); + *ui_t3|= (INT32U)(in[7]<<24); + */ + #endif +} + +U32 Lc_abs(vU32 a,vU32 b,vU32 *diff) +{ + if(a >= b) + { + *diff = a-b; + return 1; + }else + { + *diff = b-a; + return 0; + } +} + + + + + + +#endif //#if 0 //5436345673456 + +/****************************************************************************** +** End Of File +******************************************************************************/ + diff --git a/source/clib/clib.h b/source/clib/clib.h new file mode 100644 index 0000000..7aecaf3 --- /dev/null +++ b/source/clib/clib.h @@ -0,0 +1,112 @@ +/***************************************************************************** + * uart.h: Header file for NXP LPC17xx Family Microprocessors + * + * Copyright(C) 2009, NXP Semiconductor + * All rights reserved. + * + * History + * 2009.05.27 ver 1.00 Prelimnary version, first Release + * +******************************************************************************/ +#ifndef _CLIB_H_ +#define _CLIB_H_ + + +#include +#include +#include "../clib/type.h" +//#include "../clib/Clib.h" +//#include "../debug/debug_drv.h" +//extern char guc_send[128]; +extern unsigned char code cguHex2Char[16][2]; +typedef struct +{ + vU16 up_point; + vU16 down_point; + + +}TS_up_down_p_; + +extern U8 Lc_Hex2Char(U8 CharStr); +//extern void Lc_int2str(U32 ui_in,UN_TYPE len,UN_TYPE point,char *d); +// input: 123456d +// output: '1' '2' '3'.... +//Ӧĵ Ϊ 0123456789. ΪոרΪʾֵʹ +//extern void Lc_int2number(U32 ui_in,UN_TYPE len,UN_TYPE point,char *d); +//extern U32 L2_fun_number_show(int i,char str[4]); +#if 0 + +struct _s_temp_ +{ + U8 d[16]; + +}; + +extern struct _s_temp_ s_temp22; +extern U8 s_temp[16]; + +extern U32 ul2fun2[10]; +extern void Lc_Byte_cp(BYTE *src,BYTE *dis, int len); + +extern void L1_buf22ui(volatile BYTE in[],vU32 *ui_t2,vU32 *ui_t3); + +extern void Lc_2ui2buf(vU32 ui_t2,vU32 ui_t3,volatile BYTE out[]); +extern void Lc_int2str_3(U32 ui_in,char *d); +extern U32 Lc_abs(vU32 a,vU32 b,vU32 *diff); +extern void Lc_int2str_4(U32 ui_in,char *d); + +extern void Lc_sint2str_3(int i_in,char *d); +#define Lc_WEI(WEIx,WEIn) (U8)((WEIx/ul2fun2[WEIn])%10); +#define Lc_eee(WEIn) ul2fun2[WEIn] + + +#endif + +extern char *Lc_int2a(vS32 value, char *string, UN_TYPE radix); + +extern void Lc_int2D(vS16 value, char *string,char bits); + +extern char *strstr(const char *str1, const char *str2); +extern unsigned char catch_protocol (const char d_src[],char d_protocol[]) ; +#define Lc_delay_1us() L0_delay_1us() + + +extern void Lc_delay_us(vU16 i); +extern void Lc_delay_ms(vU16 i); +extern void Lc_delay_nop(U8 i); + +//////////////// + +extern void Lc_uc_hex(char ww); +extern void Lc_us_hex(U16 ww); +//extern void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...); +extern void Lc_print(char *dat4,...); +extern void Lc_print_NC(char *dat,...); +extern void Lc_print_buf(char *dat4,...); + + +extern void L3_us_big(U16 *d); +extern void L3_ui_big(vU32 *d); +extern void Lc_buf_copy_uc(U8 *d,const U8 *s,U16 num); + +///void L2_line_algo_media(U8 *buf,vU16 len); +extern vU8 Lc_U8_media3(vU8 a,vU8 b,vU8 c); +extern vS32 Lc_S32_media3(vS32 a,vS32 b,vS32 c); +extern vS32 Lc_S32_media(vS32 val[],S16 num); +extern void Lc_array_sort(S32 arr[],int n); + +/// 0x11 0x22 ---> 0x31 0x31 0x32 0x32 '1' '1' '2' '2' +extern void Lc_hex2ascii(U8 *buf,U16 len,U8 *ascii); +extern void crc16(unsigned char *CRC,void *dat,unsigned int len); +extern int isBigEndianOrder(void); +extern U32 ntohl(U32 dat); +extern U32 htonl(U32 dat); +extern U16 ntohs(U16 dat); +extern U16 htons(U16 dat); +extern U32 Lc_abs(vS32 a,vS32 b); +extern void Lc_encrypt_id(U8 *enc_dst, U8 *enc_src, U32 enc_key, U8 src_len); + +#endif /* end __UART_H */ +/***************************************************************************** +** End Of File +******************************************************************************/ diff --git a/source/clib/type.h b/source/clib/type.h new file mode 100644 index 0000000..4ae3ebd --- /dev/null +++ b/source/clib/type.h @@ -0,0 +1,316 @@ +////////////////////////////////////////////////////////////////////////// +/// COPYRIGHT NOTICE +/// Copyright (c) 2020, ؿƼ +/// All rights reserved. +/// +/// @file main.c +/// @brief main app +/// +///ļʵֵĹܵ +/// +/// @version 1.1 CCsens technology +/// @author CC +/// @date 20150102 +/// +/// +/// ޶˵汾 +/// Modified by: cc +/// Modified date: 20200531 +/// Version: +/// Descriptions: add u8 +////////////////////////////////////////////////////////////////////////// + + +//#include + +#ifndef __TYPE_H__ +#define __TYPE_H__ + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#ifndef FALSE +#define FALSE (0) +#endif + +#ifndef D_stop +#define D_stop (1) +#endif + +#ifndef D_run +#define D_run (0) +#endif + +#ifndef D_ready +#define D_ready (1) +#endif + +#ifndef D_ready2 +#define D_ready2 (2) +#endif + + +#ifndef D_max +#define D_max (3) +#endif + + + +#ifndef D_diff +#define D_diff (4) +#endif + +#ifndef D_set +#define D_set (1) +#endif + + + +#ifndef D_clear +#define D_clear (0) +#endif +#define D_ON 1 +#define D_OFF 0 + +#define D_sleep_wakeup 3 +#define D_sleep 1 +#define D_wakeup 0 + +#ifndef TRUE +#define TRUE (1) +#endif +/********************************************************************************************************* + ޹ص +*********************************************************************************************************/ + +typedef unsigned char U8; +typedef unsigned char u8; +typedef volatile U8 vU8; + + + +typedef U8 BOOLEAN; /* */ +typedef U8 *PU8; +typedef U8 BYTE; +typedef signed char S8; +typedef signed char *PS8; + + + +#define bit char +//#define code + +typedef unsigned short u16; +typedef unsigned short U16; /* ޷16λͱ */ +typedef volatile U16 vU16; /* ޷16λͱ */ +typedef signed short S16; +typedef volatile S16 vS16; /* з16λͱ */ + +typedef signed long S32; +typedef unsigned long U32; /* ޷32λͱ */ +typedef volatile U32 vU32; /* з32λͱ */ +typedef volatile signed long vS32; + +typedef float FP32; /* ȸ32λȣ */ +typedef double FP64; /* ˫ȸ64λȣ */ + + +//typedef unsigned char BOOLEAN; // +typedef unsigned char INT8U; // ޷8λͱ +typedef signed char INT8S; // з8λͱ +typedef unsigned short INT16U; // ޷16λͱ +typedef signed short INT16S; // з16λͱ +typedef unsigned long INT32U; // ޷32λͱ + +typedef signed long INT32S; // з32λͱ +//typedef float FP32; // ȸ32λȣ +//typedef double FP64; // ˫ȸ64λȣ + +typedef unsigned int FLAG_P; // ׼ +//typedef unsigned char INTU; // ׼8BIT MCU +typedef unsigned int INTU; // ׼32BIT MCU +/****************** +**************************/ + + + +/********************************************************************************************************* + ֵ +*********************************************************************************************************/ +#define ZY_OK 0 /* ɹ */ +#define ZY_NOT_OK 1 /* ʧ */ +#define ZY_PARAMETER_ERR 2 /* */ +#define ZY_NO_FIND_FUNCTION 6 /* ûзָ */ +#define ZY_NO_MEMORY 12 /* ڴ治 */ +#define ZY_TIME_OUT 13 /* ʱ */ +#define ZY_NO_FIND_OBJECT 16 /* ûзֶ */ + +/********************************************************************************************************* + realViewҪӵͷļ +*********************************************************************************************************/ +#include +#include +#include +//#include +#define D_flag_lock 2 +#define D_flag_clear 0 +#define D_flag_CanUse 1 + + +typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; +typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; + +typedef U8 UN_TYPE; +typedef U8 vtype; + + + +/************* + +******************/ + +//>>>>> + + +typedef union +{ + vU32 ui; + vU16 s[2]; + vU8 d[4]; +}tu_ui4uc; + +typedef union +{ + vU16 word; + struct + { + vU8 h; + vU8 l; + }BYTE2; +}U_U16; + +typedef union +{ + vU32 dWord; + ///High 0123 Low + struct + { + vU8 byte0; + vU8 byte1; + vU8 byte2; + vU8 byte3; + }BYTE4; +}U_U32; +typedef union +{ + vU16 us; + vU8 uc[2]; + struct + { + vU8 H; + vU8 L; + }BYTE2; +}U_F16; +/********** +k.us = 0x1234 +uc + [0]=0x12 + [1]=0x34 +byte2 + H=0x12 + L=0x34 + +**********/ + + + +typedef union +{ + float fl; + vU8 uc[4]; + +}U_F32; + +typedef struct +{ + vU8 *buffer; + vU8 wpt; + vU8 rpt; + vU8 cnt; +}byte_len_fifo_struct; + +typedef struct +{ + vU16 *buffer; + vU16 wpt; + vU16 rpt; + vU16 cnt; +}word_len_fifo_struct; + +typedef struct +{ + vU16 x; + vU16 y; +}point_struct; + + +typedef struct +{ + vU16 x; + vU16 y; + vU16 width; + vU16 height; +}rect_struct; + + +#define HIGHT 1 +#define LOW 0 + +#ifndef MIN +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif + +#ifndef ABS +#define ABS(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) +#endif + + +#define F_FINSIH 1 +#define F_WORKING 0 +#define F_WAITINGKEY 2 + + +#define DF_var_up(v,step,max,init) (v) += (step);if((v) > (max)) (v) = (init); +//if step > 1 bug warning!! +#define DF_var_down(v,step,min,init) \ +if((v) < ((min) + (step))) \ +{ \ + (v) = (init); \ +}else \ +{ \ + (v) -= (step); \ +} + +#define D_us2uc_H(x) (U8)(0x00ff&((x)>>8)) +#define D_us2uc_L(x) (U8)(0x00ff&(x)) + + +#define D_ul2uc_0(xx) (U8)(0x000000ff&(xx)) +#define D_uc_high(ww) ((ww)>>4) +#define D_uc_low(ww) ((ww)&0x0f) + +#define L0_type_byte(x) ((U8 *) &(x)) + + +//#define _nop_ __NOP +// #define _nop_ + + +extern void L3_us_big(U16 *d); +extern void L3_ui_big(vU32 *d); +#endif /* __TYPE_H__ */ diff --git a/source/cpu/STARTUP.A51 b/source/cpu/STARTUP.A51 new file mode 100644 index 0000000..fbe7294 --- /dev/null +++ b/source/cpu/STARTUP.A51 @@ -0,0 +1,198 @@ +$NOMOD51 +;------------------------------------------------------------------------------ +; This file is part of the C51 Compiler package +; Copyright (c) 1988-2005 Keil Elektronik GmbH and Keil Software, Inc. +; Version 8.01 +; +; *** <<< Use Configuration Wizard in Context Menu >>> *** +;------------------------------------------------------------------------------ +; STARTUP.A51: This code is executed after processor reset. +; +; To translate this file use A51 with the following invocation: +; +; A51 STARTUP.A51 +; +; To link the modified STARTUP.OBJ file to your application use the following +; Lx51 invocation: +; +; Lx51 your object file list, STARTUP.OBJ controls +; +;------------------------------------------------------------------------------ +; +; User-defined Power-On Initialization of Memory +; +; With the following EQU statements the initialization of memory +; at processor reset can be defined: +; +; IDATALEN: IDATA memory size <0x0-0x100> +; Note: The absolute start-address of IDATA memory is always 0 +; The IDATA space overlaps physically the DATA and BIT areas. +IDATALEN EQU 80H +; +; XDATASTART: XDATA memory start address <0x0-0xFFFF> +; The absolute start address of XDATA memory +XDATASTART EQU 0 +; +; XDATALEN: XDATA memory size <0x0-0xFFFF> +; The length of XDATA memory in bytes. +XDATALEN EQU 0 +; +; PDATASTART: PDATA memory start address <0x0-0xFFFF> +; The absolute start address of PDATA memory +PDATASTART EQU 0H +; +; PDATALEN: PDATA memory size <0x0-0xFF> +; The length of PDATA memory in bytes. +PDATALEN EQU 0H +; +; +;------------------------------------------------------------------------------ +; +; Reentrant Stack Initialization +; +; The following EQU statements define the stack pointer for reentrant +; functions and initialized it: +; +; Stack Space for reentrant functions in the SMALL model. +; IBPSTACK: Enable SMALL model reentrant stack +; Stack space for reentrant functions in the SMALL model. +IBPSTACK EQU 0 ; set to 1 if small reentrant is used. +; IBPSTACKTOP: End address of SMALL model stack <0x0-0xFF> +; Set the top of the stack to the highest location. +IBPSTACKTOP EQU 0xFF +1 ; default 0FFH+1 +; +; +; Stack Space for reentrant functions in the LARGE model. +; XBPSTACK: Enable LARGE model reentrant stack +; Stack space for reentrant functions in the LARGE model. +XBPSTACK EQU 1 ; set to 1 if large reentrant is used. +; XBPSTACKTOP: End address of LARGE model stack <0x0-0xFFFF> +; Set the top of the stack to the highest location. +XBPSTACKTOP EQU 0xFFFF +1 ; default 0FFFFH+1 +; +; +; Stack Space for reentrant functions in the COMPACT model. +; PBPSTACK: Enable COMPACT model reentrant stack +; Stack space for reentrant functions in the COMPACT model. +PBPSTACK EQU 0 ; set to 1 if compact reentrant is used. +; +; PBPSTACKTOP: End address of COMPACT model stack <0x0-0xFFFF> +; Set the top of the stack to the highest location. +PBPSTACKTOP EQU 0xFF +1 ; default 0FFH+1 +; +; +;------------------------------------------------------------------------------ +; +; Memory Page for Using the Compact Model with 64 KByte xdata RAM +; Compact Model Page Definition +; +; Define the XDATA page used for PDATA variables. +; PPAGE must conform with the PPAGE set in the linker invocation. +; +; Enable pdata memory page initalization +PPAGEENABLE EQU 0 ; set to 1 if pdata object are used. +; +; PPAGE number <0x0-0xFF> +; uppermost 256-byte address of the page used for PDATA variables. +PPAGE EQU 0 +; +; SFR address which supplies uppermost address byte <0x0-0xFF> +; most 8051 variants use P2 as uppermost address byte +PPAGE_SFR DATA 0A0H +; +; +;------------------------------------------------------------------------------ + +; Standard SFR Symbols +ACC DATA 0E0H +B DATA 0F0H +SP DATA 81H +DPL DATA 82H +DPH DATA 83H + + NAME ?C_STARTUP + + +?C_C51STARTUP SEGMENT CODE +?STACK SEGMENT IDATA + + RSEG ?STACK + DS 1 + + EXTRN CODE (?C_START) + PUBLIC ?C_STARTUP + + CSEG AT 0 +?C_STARTUP: LJMP STARTUP1 + + RSEG ?C_C51STARTUP + +STARTUP1: + +IF IDATALEN <> 0 + MOV R0,#IDATALEN - 1 + CLR A +IDATALOOP: MOV @R0,A + DJNZ R0,IDATALOOP +ENDIF + +IF XDATALEN <> 0 + MOV DPTR,#XDATASTART + MOV R7,#LOW (XDATALEN) + IF (LOW (XDATALEN)) <> 0 + MOV R6,#(HIGH (XDATALEN)) +1 + ELSE + MOV R6,#HIGH (XDATALEN) + ENDIF + CLR A +XDATALOOP: MOVX @DPTR,A + INC DPTR + DJNZ R7,XDATALOOP + DJNZ R6,XDATALOOP +ENDIF + +IF PPAGEENABLE <> 0 + MOV PPAGE_SFR,#PPAGE +ENDIF + +IF PDATALEN <> 0 + MOV R0,#LOW (PDATASTART) + MOV R7,#LOW (PDATALEN) + CLR A +PDATALOOP: MOVX @R0,A + INC R0 + DJNZ R7,PDATALOOP +ENDIF + +IF IBPSTACK <> 0 +EXTRN DATA (?C_IBP) + + MOV ?C_IBP,#LOW IBPSTACKTOP +ENDIF + +IF XBPSTACK <> 0 +EXTRN DATA (?C_XBP) + + MOV ?C_XBP,#HIGH XBPSTACKTOP + MOV ?C_XBP+1,#LOW XBPSTACKTOP +ENDIF + +IF PBPSTACK <> 0 +EXTRN DATA (?C_PBP) + MOV ?C_PBP,#LOW PBPSTACKTOP +ENDIF + + MOV SP,#?STACK-1 + +; This code is required if you use L51_BANK.A51 with Banking Mode 4 +; Code Banking +; Select Bank 0 for L51_BANK.A51 Mode 4 +#if 0 +; Initialize bank mechanism to code bank 0 when using L51_BANK.A51 with Banking Mode 4. +EXTRN CODE (?B_SWITCH0) + CALL ?B_SWITCH0 ; init bank mechanism to code bank 0 +#endif +; + LJMP ?C_START + + END diff --git a/source/cpu/STC_stc8a8k.H b/source/cpu/STC_stc8a8k.H new file mode 100644 index 0000000..7c5ea25 --- /dev/null +++ b/source/cpu/STC_stc8a8k.H @@ -0,0 +1,617 @@ +#ifndef __STC_stc8a8k_H_ +#define __STC_stc8a8k_H_ +// STC_stc8a8k.h +#include +///////////////////////////////////////////////// +//注意: STC15W4K32S4系列的芯片,上电后所有与PWM相关的IO口均为 +// 高阻态,需将这些口设置为准双向口或强推挽模式方可正常使用 +//相关IO: P0.6/P0.7/P1.6/P1.7/P2.1/P2.2 +// P2.3/P2.7/P3.7/P4.2/P4.4/P4.5 +///////////////////////////////////////////////// + +///////////////////////////////////////////////// + +//包含本头文件后,不用另外再包含"REG51.H" + +//内核特殊功能寄存器 // 复位值 描述 +sfr ACC = 0xE0; //0000,0000 累加器Accumulator +sfr B = 0xF0; //0000,0000 B寄存器 +sfr PSW = 0xD0; //0000,0000 程序状态字 +sbit CY = PSW^7; +sbit AC = PSW^6; +sbit F0 = PSW^5; +sbit RS1 = PSW^4; +sbit RS0 = PSW^3; +sbit OV = PSW^2; +sbit P = PSW^0; +sfr SP = 0x81; //0000,0111 堆栈指针 +sfr DPL = 0x82; //0000,0000 数据指针低字节 +sfr DPH = 0x83; //0000,0000 数据指针高字节 + +//I/O 口特殊功能寄存器 +sfr P0 = 0x80; //1111,1111 端口0 +sbit P00 = P0^0; +sbit P01 = P0^1; +sbit P02 = P0^2; +sbit P03 = P0^3; +sbit P04 = P0^4; +sbit P05 = P0^5; +sbit P06 = P0^6; +sbit P07 = P0^7; +sfr P1 = 0x90; //1111,1111 端口1 +sbit P10 = P1^0; +sbit P11 = P1^1; +sbit P12 = P1^2; +sbit P13 = P1^3; +sbit P14 = P1^4; +sbit P15 = P1^5; +sbit P16 = P1^6; +sbit P17 = P1^7; +sfr P2 = 0xA0; //1111,1111 端口2 +sbit P20 = P2^0; +sbit P21 = P2^1; +sbit P22 = P2^2; +sbit P23 = P2^3; +sbit P24 = P2^4; +sbit P25 = P2^5; +sbit P26 = P2^6; +sbit P27 = P2^7; +sfr P3 = 0xB0; //1111,1111 端口3 +sbit P30 = P3^0; +sbit P31 = P3^1; +sbit P32 = P3^2; +sbit P33 = P3^3; +sbit P34 = P3^4; +sbit P35 = P3^5; +sbit P36 = P3^6; +sbit P37 = P3^7; +sfr P4 = 0xC0; //1111,1111 端口4 +sbit P40 = P4^0; +sbit P41 = P4^1; +sbit P42 = P4^2; +sbit P43 = P4^3; +sbit P44 = P4^4; +sbit P45 = P4^5; +sbit P46 = P4^6; +sbit P47 = P4^7; +sfr P5 = 0xC8; //xxxx,1111 端口5 +sbit P50 = P5^0; +sbit P51 = P5^1; +sbit P52 = P5^2; +sbit P53 = P5^3; +sbit P54 = P5^4; +sbit P55 = P5^5; +sbit P56 = P5^6; +sbit P57 = P5^7; +sfr P6 = 0xE8; //0000,0000 端口6 +sbit P60 = P6^0; +sbit P61 = P6^1; +sbit P62 = P6^2; +sbit P63 = P6^3; +sbit P64 = P6^4; +sbit P65 = P6^5; +sbit P66 = P6^6; +sbit P67 = P6^7; +sfr P7 = 0xF8; //0000,0000 端口7 +sbit P70 = P7^0; +sbit P71 = P7^1; +sbit P72 = P7^2; +sbit P73 = P7^3; +sbit P74 = P7^4; +sbit P75 = P7^5; +sbit P76 = P7^6; +sbit P77 = P7^7; + + +///00 准双向口 灌电流20mA 拉电流270-150uS +///01 推挽输出 20mA 加限流 +///10 高阻 +///11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平 + + +sfr P0M0 = 0x94; //0000,0000 端口0模式寄存器0 +sfr P0M1 = 0x93; //0000,0000 端口0模式寄存器1 +sfr P1M0 = 0x92; //0000,0000 端口1模式寄存器0 +sfr P1M1 = 0x91; //0000,0000 端口1模式寄存器1 +sfr P2M0 = 0x96; //0000,0000 端口2模式寄存器0 +sfr P2M1 = 0x95; //0000,0000 端口2模式寄存器1 +sfr P3M0 = 0xB2; //0000,0000 端口3模式寄存器0 +sfr P3M1 = 0xB1; //0000,0000 端口3模式寄存器1 +sfr P4M0 = 0xB4; //0000,0000 端口4模式寄存器0 +sfr P4M1 = 0xB3; //0000,0000 端口4模式寄存器1 +sfr P5M0 = 0xCA; //0000,0000 端口5模式寄存器0 +sfr P5M1 = 0xC9; //0000,0000 端口5模式寄存器1 +sfr P6M0 = 0xCC; //0000,0000 端口6模式寄存器0 +sfr P6M1 = 0xCB; //0000,0000 端口6模式寄存器1 +sfr P7M0 = 0xE2; //0000,0000 端口7模式寄存器0 +sfr P7M1 = 0xE1; //0000,0000 端口7模式寄存器1 + +//系统管理特殊功能寄存器 +sfr PCON = 0x87; //0001,0000 电源控制寄存器 +sfr AUXR = 0x8E; //0000,0000 辅助寄存器 + +#define TOx12 BITN7 +#define T1x12 BITN6 +#define UART_M0x6 BITN5 //串口1模式0速度 =0 12倍 = 1 两倍 +#define T2R BITN4 //定时器2 运行 =1 +#define T2_C BITN3 //定时器/计数器选择 +#define T2x12 BITN2 +#define EXTRAM BITN1 +#define S1ST2 BITN0 //串口1选择定时器1 =0 选择定时器2 =1 + + +sfr VOCTR = 0xBB; //电压控制寄存器 +///BITN_1(VOCTR, BITN7) VOCTR +#define D_VOCTR_SCCIN 0x00 +#define D_VOCTR_SCC 0x80 +#define D_VOCTR_SET(X) VOCTR = (X) + +sfr AUXR1 = 0xA2; //0000,0000 辅助寄存器1 +sfr P_SW1 = 0xA2; //0000,0000 外设端口切换寄存器1 +sfr CLK_DIV = 0x97; //0000,0000 时钟分频控制寄存器 +sfr BUS_SPEED = 0xA1; //xx10,x011 总线速度控制寄存器 +sfr P1ASF = 0x9D; //0000,0000 端口1模拟功能配置寄存器 +//----------------------------------------------------------------- +sfr P_SW2 = 0xBA; //0xxx,x000 外设端口切换寄存器 +#define EAXFR BITN7 +#define I2C_S1 BITN5 +#define I2C_S2 BITN4 +#define CMPO_S BITN3 +#define S4_S BITN2 +#define S3_S BITN1 +#define S2_S BITN0 + +//----------------------------------------------------------------- + +//中断特殊功能寄存器 +sfr IE = 0xA8; //0000,0000 中断控制寄存器 +sbit EA = IE^7; +sbit ELVD = IE^6; +sbit EADC = IE^5; +sbit ES = IE^4; +sbit ET1 = IE^3; +sbit EX1 = IE^2; +sbit ET0 = IE^1; +sbit EX0 = IE^0; +sfr IE2 = 0xAF; //0000,0000 中断控制寄存器2 +sfr IP = 0xB8; //0000,0000 中断优先级寄存器 +sbit PPCA = IP^7; +sbit PLVD = IP^6; +sbit PADC = IP^5; +sbit PS = IP^4; +sbit PT1 = IP^3; +sbit PX1 = IP^2; +sbit PT0 = IP^1; +sbit PX0 = IP^0; +/// 不可位寻址 +#define ET4 BITN6 +#define ET3 BITN5 +#define ES4 BITN4 +#define ES3 BITN3 +#define ET2 BITN2 +#define ESPI BITN1 +#define ES2 BITN0 + +sfr IPH = 0xB7; //xxxx,xx00 中断优先级寄存器2 +#define PPCAH BITN7 +#define PLVDH BITN6 +#define PADCH BITN5 +#define PSH BITN4 +#define PT1H BITN3 +#define PX1H BITN2 +#define PT0H BITN1 +#define PX0H BITN0 + + + +sfr IP2 = 0xB5; //xxxx,xx00 中断优先级寄存器2 +#define IP2_7 BITN7 +#define PI2C BITN6 +#define PCMP BITN5 +#define PX4 BITN4 +#define PPWMFD BITN3 +#define PPWM BITN2 +#define PSPI BITN1 +#define PS2 BITN0 + +sfr IP2H = 0xB6; //xxxx,xx00 中断优先级寄存器2 +#define IP2_7 BITN7 +#define PI2CH BITN6 +#define PCMPH BITN5 +#define PX4H BITN4 +#define PPWMFDH BITN3 +#define PPWMH BITN2 +#define PSPIH BITN1 +#define PS2H BITN0 + + + + + +sfr INT_CLKO = 0x8F; //0000,0000 外部中断与时钟输出控制寄存器 +#define INT_EX4 BITN6 +#define INT_EX3 BITN5 +#define INT_EX2 BITN4 +//定时器特殊功能寄存器 +sfr TCON = 0x88; //0000,0000 T0/T1控制寄存器 +sbit TF1 = TCON^7; +sbit TR1 = TCON^6; +sbit TF0 = TCON^5; +sbit TR0 = TCON^4; +sbit IE1 = TCON^3; +sbit IT1 = TCON^2; +sbit IE0 = TCON^1; +sbit IT0 = TCON^0; +sfr TMOD = 0x89; //0000,0000 T0/T1模式寄存器 +sfr TL0 = 0x8A; //0000,0000 T0低字节 +sfr TL1 = 0x8B; //0000,0000 T1低字节 +sfr TH0 = 0x8C; //0000,0000 T0高字节 +sfr TH1 = 0x8D; //0000,0000 T1高字节 +sfr T4T3M = 0xD1; //0000,0000 T3/T4模式寄存器 +sfr T3T4M = 0xD1; //0000,0000 T3/T4模式寄存器 +sfr T4H = 0xD2; //0000,0000 T4高字节 +sfr T4L = 0xD3; //0000,0000 T4低字节 +sfr T3H = 0xD4; //0000,0000 T3高字节 +sfr T3L = 0xD5; //0000,0000 T3低字节 +sfr T2H = 0xD6; //0000,0000 T2高字节 +sfr T2L = 0xD7; //0000,0000 T2低字节 +sfr WKTCL = 0xAA; //0000,0000 掉电唤醒定时器低字节 +sfr WKTCH = 0xAB; //0000,0000 掉电唤醒定时器高字节 +sfr16 WKTC = 0xAA; +sfr WDT_CONTR = 0xC1; //0000,0000 看门狗控制寄存器 + +//串行口特殊功能寄存器 +sfr SCON = 0x98; //0000,0000 串口1控制寄存器 +sbit SM0 = SCON^7; +sbit SM1 = SCON^6; +sbit SM2 = SCON^5; +sbit REN = SCON^4; +sbit TB8 = SCON^3; +sbit RB8 = SCON^2; +sbit TI = SCON^1; +sbit RI = SCON^0; +//sfr SBUF = 0x99; //xxxx,xxxx 串口1数据寄存器 +//sfr S2CON = 0x9A; //0000,0000 串口2控制寄存器 +//sfr S2BUF = 0x9B; //xxxx,xxxx 串口2数据寄存器 +//sfr SADDR = 0xA9; //0000,0000 从机地址寄存器 +//sfr SADEN = 0xB9; //0000,0000 从机地址屏蔽寄存器 + +sfr SBUF = 0x99; //Serial Data Buffer +sfr SBUF0 = 0x99; //Serial Data Buffer xxxx,xxxx +sfr SADEN = 0xB9; //Slave Address Mask 0000,0000 +sfr SADDR = 0xA9; //Slave Address 0000,0000 +//----------------------------------- +// 7 6 5 4 3 2 1 0 Reset Value +sfr S2CON = 0x9A; //S2 Control S2SM0 S2SM1 S2SM2 S2REN S2TB8 S2RB8 S2TI S2RI 00000000B +#define S2SM0 BITN7 +#define S2ST4 BITN6 +#define S2SM2 BITN5 +#define S2REN BITN4 +#define S2TB8 BITN3 +#define S2RB8 BITN2 +#define S2TI BITN1 +#define S2RI BITN0 + +sfr S2BUF = 0x9B; //S2 Serial Buffer xxxx,xxxx +//sfr BRT = 0x9C; //S2 Baud-Rate Timer 0000,0000 + +//--------------------------------------------------------------- +sfr S3CON = 0xAC; //0000,0000 串口3控制寄存器 +#define S3SM0 BITN7 +#define S3ST4 BITN6 +#define S3SM2 BITN5 +#define S3REN BITN4 +#define S3TB8 BITN3 +#define S3RB8 BITN2 +#define S3TI BITN1 +#define S3RI BITN0 + +sfr S3BUF = 0xAD; //xxxx,xxxx 串口3数据寄存器 +//--------------------------------------------------------------- +sfr S4CON = 0x84; //0000,0000 串口4控制寄存器 +#define S4SM0 BITN7 +#define S4ST4 BITN6 +#define S4SM2 BITN5 +#define S4REN BITN4 +#define S4TB8 BITN3 +#define S4RB8 BITN2 +#define S4TI BITN1 +#define S4RI BITN0 + +sfr S4BUF = 0x85; //xxxx,xxxx 串口4数据寄存器 + +//ADC 特殊功能寄存器 +sfr ADC_CONTR = 0xBC; //0000,0000 A/D转换控制寄存器 +sfr ADC_RES = 0xBD; //0000,0000 A/D转换结果高8位 +sfr ADC_RESL = 0xBE; //0000,0000 A/D转换结果低2位 + +//SPI 特殊功能寄存器 +sfr SPSTAT = 0xCD; //00xx,xxxx SPI状态寄存器 +sfr SPCTL = 0xCE; //0000,0100 SPI控制寄存器 +sfr SPDAT = 0xCF; //0000,0000 SPI数据寄存器 + +//IAP/ISP 特殊功能寄存器 +sfr IAP_DATA = 0xC2; //0000,0000 EEPROM数据寄存器 +sfr IAP_ADDRH = 0xC3; //0000,0000 EEPROM地址高字节 +sfr IAP_ADDRL = 0xC4; //0000,0000 EEPROM地址第字节 +sfr IAP_CMD = 0xC5; //xxxx,xx00 EEPROM命令寄存器 +sfr IAP_TRIG = 0xC6; //0000,0000 EEPRPM命令触发寄存器 +sfr IAP_CONTR = 0xC7; //0000,x000 EEPROM控制寄存器 + +//PCA/PWM 特殊功能寄存器 +sfr CCON = 0xD8; //00xx,xx00 PCA控制寄存器 +sbit CF = CCON^7; +sbit CR = CCON^6; +sbit CCF2 = CCON^2; +sbit CCF1 = CCON^1; +sbit CCF0 = CCON^0; +sfr CMOD = 0xD9; //0xxx,x000 PCA 工作模式寄存器 +sfr CL = 0xE9; //0000,0000 PCA计数器低字节 +sfr CH = 0xF9; //0000,0000 PCA计数器高字节 +sfr CCAPM0 = 0xDA; //0000,0000 PCA模块0的PWM寄存器 +sfr CCAPM1 = 0xDB; //0000,0000 PCA模块1的PWM寄存器 +sfr CCAPM2 = 0xDC; //0000,0000 PCA模块2的PWM 寄存器 +sfr CCAP0L = 0xEA; //0000,0000 PCA模块0的捕捉/比较寄存器低字节 +sfr CCAP1L = 0xEB; //0000,0000 PCA模块1的捕捉/比较寄存器低字节 +sfr CCAP2L = 0xEC; //0000,0000 PCA模块2的捕捉/比较寄存器低字节 +sfr PCA_PWM0 = 0xF2; //xxxx,xx00 PCA模块0的PWM寄存器 +sfr PCA_PWM1 = 0xF3; //xxxx,xx00 PCA模块1的PWM寄存器 +sfr PCA_PWM2 = 0xF4; //xxxx,xx00 PCA模块1的PWM寄存器 +sfr CCAP0H = 0xFA; //0000,0000 PCA模块0的捕捉/比较寄存器高字节 +sfr CCAP1H = 0xFB; //0000,0000 PCA模块1的捕捉/比较寄存器高字节 +sfr CCAP2H = 0xFC; //0000,0000 PCA模块2的捕捉/比较寄存器高字节 + +//比较器特殊功能寄存器 +sfr CMPCR1 = 0xE6; //0000,0000 比较器控制寄存器1 +sfr CMPCR2 = 0xE7; //0000,0000 比较器控制寄存器2 + + +//sfr P_SW2 = 0xba; +sfr PWMCFG = 0xf1; +sfr PWMIF = 0xf6; +sfr PWMFDCR = 0xf7; +sfr PWMCR = 0xfe; + +#define PWMC (*(unsigned int volatile xdata *)0xfff0) +#define PWMCKS (*(unsigned char volatile xdata *)0xfff2) +#define TADCP (*(unsigned int volatile xdata *)0xfff3) +#define PWM0T1 (*(unsigned int volatile xdata *)0xff00) +#define PWM0T2 (*(unsigned int volatile xdata *)0xff02) +#define PWM0CR (*(unsigned char volatile xdata *)0xff04) +#define PWM0HLD (*(unsigned char volatile xdata *)0xff05) +#define PWM1T1 (*(unsigned int volatile xdata *)0xff10) +#define PWM1T2 (*(unsigned int volatile xdata *)0xff12) +#define PWM1CR (*(unsigned char volatile xdata *)0xff14) +#define PWM1HLD (*(unsigned char volatile xdata *)0xff15) +#define PWM2T1 (*(unsigned int volatile xdata *)0xff20) +#define PWM2T2 (*(unsigned int volatile xdata *)0xff22) +#define PWM2CR (*(unsigned char volatile xdata *)0xff24) +#define PWM2HLD (*(unsigned char volatile xdata *)0xff25) +#define PWM3T1 (*(unsigned int volatile xdata *)0xff30) +#define PWM3T2 (*(unsigned int volatile xdata *)0xff32) +#define PWM3CR (*(unsigned char volatile xdata *)0xff34) +#define PWM3HLD (*(unsigned char volatile xdata *)0xff35) +#define PWM4T1 (*(unsigned int volatile xdata *)0xff40) +#define PWM4T2 (*(unsigned int volatile xdata *)0xff42) +#define PWM4CR (*(unsigned char volatile xdata *)0xff44) +#define PWM4HLD (*(unsigned char volatile xdata *)0xff45) +#define PWM5T1 (*(unsigned int volatile xdata *)0xff50) +#define PWM5T2 (*(unsigned int volatile xdata *)0xff52) +#define PWM5CR (*(unsigned char volatile xdata *)0xff54) +#define PWM5HLD (*(unsigned char volatile xdata *)0xff55) +#define PWM6T1 (*(unsigned int volatile xdata *)0xff60) +#define PWM6T2 (*(unsigned int volatile xdata *)0xff62) +#define PWM6CR (*(unsigned char volatile xdata *)0xff64) +#define PWM6HLD (*(unsigned char volatile xdata *)0xff65) +#define PWM7T1 (*(unsigned int volatile xdata *)0xff70) +#define PWM7T2 (*(unsigned int volatile xdata *)0xff72) +#define PWM7CR (*(unsigned char volatile xdata *)0xff74) +#define PWM7HLD (*(unsigned char volatile xdata *)0xff75) + + +#define CKSEL (*(unsigned char volatile xdata *)0xfE00)//108@ST8.PDF +#define MCLKODIV BIT4 +#define MCLKO_S BITN3 +#define MCLKSEL BIT0 + +#define CLKDIV (*(unsigned char volatile xdata *)0xfE01)//108@ST8.PDF +#define IRC24MCR (*(unsigned char volatile xdata *)0xfE02)//108@ST8.PDF +#define XOSCCR (*(unsigned char volatile xdata *)0xfE03)//108@ST8.PDF +#define IRC32KCR (*(unsigned char volatile xdata *)0xfE04)//108@ST8.PDF + + + +#define I2CTXD (*(unsigned char volatile xdata *)0xfE86)//423@ST8.PDF + +#define I2CRXD (*(unsigned char volatile xdata *)0xfE87)//423@ST8.PDF + + + +///------------------------------------- + +#define gRccUs01_H (*(unsigned char volatile data *)0xd2) +#define gRccUs01_L (*(unsigned char volatile data *)0xd3) + + + +#define gRccUs01 (*(unsigned short volatile data *)0xd2)//226@ST8.PDF T4H定时器4的高字节 D2H T4H定时器4的低字节 D3H +#define gRccUs02 (*(unsigned short volatile data *)0xEA)//351@ST8.PDF CCAP0l CCAP1L EAH EBH +#define gRccUs03 (*(unsigned short volatile data *)0xEC)//351@ST8.PDF CCAP0l CCAP1L EAH EBH +//#define gRccUs03 s_task_GC032A.n + + + +#define gRccUs04 (*(unsigned short volatile data *)0xFA)///351@ST8.PDF +#define gRccUs05 (*(unsigned short volatile data *)0xFC)///351@ST8.PD CCAP2H + +///////////////////////////////////////////////// + + + +/* P3 */ +sbit RD = 0xB7; +sbit WR = 0xB6; +sbit T1 = 0xB5; +sbit T0 = 0xB4; +sbit INT1 = 0xB3; +sbit INT0 = 0xB2; +sbit TXD = 0xB1; +sbit RXD = 0xB0; + + +sfr AUXINTIF = 0xef; + +#define T2IF 0x01 +#define INT4IF BITN6 +#define INT3IF BITN5 +#define INT2IF BITN4 + +//#define T4IF BITN2 +//#define T3IF BITN1 +//#define T2IF BITN0 + + +/// >>>>> add by cc + +#include "../clib/bit.h" + +#define D_stdIO_P0_ALL() P0M1=0;P0M0=0; +#define D_HighI_P0_ALL() P0M1=0;P0M0=0XFF; +#define D_HighR_P0_ALL() P0M1=0XFF;P0M0=0; +#define D_OpenD_P0_ALL() P0M1=0XFF;P0M0=0XFF; + +#define D_stdIO_P1_ALL() P1M1=0;P1M0=0; +#define D_HighI_P1_ALL() P1M1=0;P1M0=0XFF; +#define D_HighR_P1_ALL() P1M1=0XFF;P1M0=0; +#define D_OpenD_P1_ALL() P1M1=0XFF;P1M0=0XFF; + + +#define D_stdIO_P0(n) BITN_0(P0M1,n);BITN_0(P0M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS +#define D_HighI_P0(n) BITN_0(P0M1,n);BITN_1(P0M0,n); //////01 推挽输出 20mA 加限流 +#define D_HighR_P0(n) BITN_1(P0M1,n);BITN_0(P0M0,n); /////////10 高阻 +#define D_OpenD_P0(n) BITN_1(P0M1,n);BITN_1(P0M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平 + +#define D_stdIO_P1(n) BITN_0(P1M1,n);BITN_0(P1M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS +#define D_HighI_P1(n) BITN_0(P1M1,n);BITN_1(P1M0,n); //////01 推挽输出 20mA 加限流 +#define D_HighR_P1(n) BITN_1(P1M1,n);BITN_0(P1M0,n); /////////10 高阻 +#define D_OpenD_P1(n) BITN_1(P1M1,n);BITN_1(P1M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平 + +#define D_stdIO_P2(n) BITN_0(P2M1,n);BITN_0(P2M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS +#define D_HighI_P2(n) BITN_0(P2M1,n);BITN_1(P2M0,n); //////01 推挽输出 20mA 加限流 +#define D_HighR_P2(n) BITN_1(P2M1,n);BITN_0(P2M0,n); /////////10 高阻 +#define D_OpenD_P2(n) BITN_1(P2M1,n);BITN_1(P2M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平 + +#define D_stdIO_P3(n) BITN_0(P3M1,n);BITN_0(P3M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS +#define D_HighI_P3(n) BITN_0(P3M1,n);BITN_1(P3M0,n); //////01 推挽输出 20mA 加限流 +#define D_HighR_P3(n) BITN_1(P3M1,n);BITN_0(P3M0,n); /////////10 高阻 +#define D_OpenD_P3(n) BITN_1(P3M1,n);BITN_1(P3M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平 + +#define D_stdIO_P4(n) BITN_0(P4M1,n);BITN_0(P4M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS +#define D_HighI_P4(n) BITN_0(P4M1,n);BITN_1(P4M0,n); //////01 推挽输出 20mA 加限流 +#define D_HighR_P4(n) BITN_1(P4M1,n);BITN_0(P4M0,n); /////////10 高阻 +#define D_OpenD_P4(n) BITN_1(P4M1,n);BITN_1(P4M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平 + +#define D_stdIO_P5(n) BITN_0(P5M1,n);BITN_0(P5M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS +#define D_HighI_P5(n) BITN_0(P5M1,n);BITN_1(P5M0,n); //////01 推挽输出 20mA 加限流 +#define D_HighR_P5(n) BITN_1(P5M1,n);BITN_0(P5M0,n); /////////10 高阻 +#define D_OpenD_P5(n) BITN_1(P5M1,n);BITN_1(P5M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平 + +#define D_stdIO_P6(n) BITN_0(P6M1,n);BITN_0(P6M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS +#define D_HighI_P6(n) BITN_0(P6M1,n);BITN_1(P6M0,n); //////01 推挽输出 20mA 加限流 +#define D_HighR_P6(n) BITN_1(P6M1,n);BITN_0(P6M0,n); /////////10 高阻 +#define D_OpenD_P6(n) BITN_1(P6M1,n);BITN_1(P6M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平 + +#define D_stdIO_P7(n) BITN_0(P7M1,n);BITN_0(P7M0,n); //////00 准双向口 灌电流20mA 拉电流270-150uS +#define D_HighI_P7(n) BITN_0(P7M1,n);BITN_1(P7M0,n); //////01 推挽输出 20mA 加限流 +#define D_HighR_P7(n) BITN_1(P7M1,n);BITN_0(P7M0,n); /////////10 高阻 +#define D_OpenD_P7(n) BITN_1(P7M1,n);BITN_1(P7M0,n); /////11 开漏 open-Drain 内部上拉电阻断开 开漏模式既可以度外部状态也可以对外输出高低电平 + +/*** + +#define P0_conf_in(n) BITN_1(P0M1,n);BITN_0(P0M0,n); +#define P1_conf_in(n) BITN_1(P1M1,n);BITN_0(P1M0,n); +#define P2_conf_in(n) BITN_1(P2M1,n);BITN_0(P2M0,n); +#define P2_conf_port(n) BITN_0(P2M1,n);BITN_0(P2M0,n); + + +#define P3_conf_in(n) BITN_1(P3M1,n);BITN_0(P3M0,n); +#define P3_conf_port(n) BITN_0(P3M1,n);BITN_0(P3M0,n); + +#define P4_conf_in(n) BITN_1(P4M1,n);BITN_0(P4M0,n); +#define P5_conf_in(n) BITN_1(P5M1,n);BITN_0(P5M0,n); + +***/ + + + +#define NOP() _nop_() + +#define L0_INT4_OPEN() BITN_1(INT_CLKO, INT_EX4) +#define L0_INT4_CLOSE() BITN_0(INT_CLKO, INT_EX4) + +#define L0_INT4_AT() BITN_G(INT_CLKO, INT_EX4) + + + + +#define L0_INT4_CLEAR() BITN_0(AUXINTIF, INT4IF) +#define L0_INT3_CLEAR() BITN_0(AUXINTIF, INT3IF) +#define L0_INT2_CLEAR() BITN_0(AUXINTIF, INT2IF) + + + + +////// + +#define L0_INT3_OPEN() BITN_1(INT_CLKO, INT_EX3); +#define L0_INT3_CLOSE() BITN_0(INT_CLKO, INT_EX3); +#define L0_INT2_OPEN() BITN_1(INT_CLKO, INT_EX2); +#define L0_INT2_CLOSE() BITN_0(INT_CLKO, INT_EX2); +#define L0_INT1_OPEN() EX1 = 1; +#define L0_INT1_CLOSE() EX1 = 0; +#define L0_INT0_OPEN() EX0 = 1; +#define L0_INT0_CLOSE() EX0 = 0; + +#define D_ISR_int0 0 ///int0 下降沿触发 = 0 上下沿均可触发 +#define D_ISR_timer0 1 +#define D_ISR_int1 2 ///int1 下降沿触发 = 0 上下沿均可触发 +#define D_ISR_timer1 3 +#define D_ISR_int2 10 /////只有下降沿 +#define D_ISR_int3 11 /////只有下降沿 +#define D_SERVE_UART 4 +#define D_ISR_int4 16 /////只有下降沿 + +#if 0 +#define L0_TIMER1_start() TR1 = 1; +#define L0_TIMER1_end() TR1 = 0; + + +#define L0_TIMER1_isr_OPEN() ET1 = 1; +#define L0_TIMER1_isr_CLOSE() ET1 = 0; + + +#else + +#define L0_TIMER1_start() ET1 = 1; +#define L0_TIMER1_end() ET1 = 0; + + +#define L0_TIMER1_isr_OPEN() TR1 = 1; +#define L0_TIMER1_isr_CLOSE() TR1 = 0; + + +#endif + +/// fixme 颠倒定义会让c51锁死#define _nop_() NOP() + +///#define L0_INT3_OPEN() BITN_1(INT_CLKO,INT_EX3); //使能INT3中断 +///#define L0_INT3_CLOSE() BITN_0(INT_CLKO,INT_EX3); +#endif //STC_stc8a8k + + + + + + + + diff --git a/source/cpu/c51_macro.H b/source/cpu/c51_macro.H new file mode 100644 index 0000000..5bbfab9 --- /dev/null +++ b/source/cpu/c51_macro.H @@ -0,0 +1,301 @@ +////////////////////////////////////////////////////////////////////////// +/// COPYRIGHT NOTICE +/// Copyright (c) 2018, 传控科技 +/// All rights reserved. +/// +/// @file __C51_MACRO_H_ +/// @brief macro define 和cpu相关,可以和同一个系列的cpu共享 +/// +///(本文件实现的功能的详述) +/// +/// @version 1.1 CCsens technology +/// @author CC +/// @date 20180102 + +// +////////////////////////////////////////////////////////////////////////// + + + +#ifndef __C51_MACRO_H_ +#define __C51_MACRO_H_ + +#include + +#define D_P07_ON() P07 = 1 +#define D_P06_ON() P06 = 1 +#define D_P05_ON() P05 = 1 +#define D_P04_ON() P04 = 1 +#define D_P03_ON() P03 = 1 +#define D_P02_ON() P02 = 1 +#define D_P01_ON() P01 = 1 +#define D_P00_ON() P00 = 1 +#define D_P07_OFF() P07 = 0 +#define D_P06_OFF() P06 = 0 +#define D_P05_OFF() P05 = 0 +#define D_P04_OFF() P04 = 0 +#define D_P03_OFF() P03 = 0 +#define D_P02_OFF() P02 = 0 +#define D_P01_OFF() P01 = 0 +#define D_P00_OFF() P00 = 0 +#define D_P07_AT() (P07) +#define D_P06_AT() (P06) +#define D_P05_AT() (P05) +#define D_P04_AT() (P04) +#define D_P03_AT() (P03) +#define D_P02_AT() (P02) +#define D_P01_AT() (P01) +#define D_P00_AT() (P00) +#define D_P07_REV() P07 = ~P07 +#define D_P06_REV() P06 = ~P06 +#define D_P05_REV() P05 = ~P05 +#define D_P04_REV() P04 = ~P04 +#define D_P03_REV() P03 = ~P03 +#define D_P02_REV() P02 = ~P02 +#define D_P01_REV() P01 = ~P01 +#define D_P00_REV() P00 = ~P00 + + +#define D_P17_ON() P17 = 1 +#define D_P16_ON() P16 = 1 +#define D_P15_ON() P15 = 1 +#define D_P14_ON() P14 = 1 +#define D_P13_ON() P13 = 1 +#define D_P12_ON() P12 = 1 +#define D_P11_ON() P11 = 1 +#define D_P10_ON() P10 = 1 +#define D_P17_OFF() P17 = 0 +#define D_P16_OFF() P16 = 0 +#define D_P15_OFF() P15 = 0 +#define D_P14_OFF() P14 = 0 +#define D_P13_OFF() P13 = 0 +#define D_P12_OFF() P12 = 0 +#define D_P11_OFF() P11 = 0 +#define D_P10_OFF() P10 = 0 +#define D_P17_AT() (P17) +#define D_P16_AT() (P16) +#define D_P15_AT() (P15) +#define D_P14_AT() (P14) +#define D_P13_AT() (P13) +#define D_P12_AT() (P12) +#define D_P11_AT() (P11) +#define D_P10_AT() (P10) +#define D_P17_REV() P17 = ~P17 +#define D_P16_REV() P16 = ~P16 +#define D_P15_REV() P15 = ~P15 +#define D_P14_REV() P14 = ~P14 +#define D_P13_REV() P13 = ~P13 +#define D_P12_REV() P12 = ~P12 +#define D_P11_REV() P11 = ~P11 +#define D_P10_REV() P10 = ~P10 + +#define D_P27_ON() P27 = 1 +#define D_P26_ON() P26 = 1 +#define D_P25_ON() P25 = 1 +#define D_P24_ON() P24 = 1 +#define D_P23_ON() P23 = 1 +#define D_P22_ON() P22 = 1 +#define D_P21_ON() P21 = 1 +#define D_P20_ON() P20 = 1 +#define D_P27_OFF() P27 = 0 +#define D_P26_OFF() P26 = 0 +#define D_P25_OFF() P25 = 0 +#define D_P24_OFF() P24 = 0 +#define D_P23_OFF() P23 = 0 +#define D_P22_OFF() P22 = 0 +#define D_P21_OFF() P21 = 0 +#define D_P20_OFF() P20 = 0 +#define D_P27_AT() (P27) +#define D_P26_AT() (P26) +#define D_P25_AT() (P25) +#define D_P24_AT() (P24) +#define D_P23_AT() (P23) +#define D_P22_AT() (P22) +#define D_P21_AT() (P21) +#define D_P20_AT() (P20) +#define D_P27_REV() P27 = ~P27 +#define D_P26_REV() P26 = ~P26 +#define D_P25_REV() P25 = ~P25 +#define D_P24_REV() P24 = ~P24 +#define D_P23_REV() P23 = ~P23 +#define D_P22_REV() P22 = ~P22 +#define D_P21_REV() P21 = ~P21 +#define D_P20_REV() P20 = ~P20 + + +#define D_P37_ON() P37 = 1 +#define D_P36_ON() P36 = 1 +#define D_P35_ON() P35 = 1 +#define D_P34_ON() P34 = 1 +#define D_P33_ON() P33 = 1 +#define D_P32_ON() P32 = 1 +#define D_P31_ON() P31 = 1 +#define D_P30_ON() P30 = 1 +#define D_P37_OFF() P37 = 0 +#define D_P36_OFF() P36 = 0 +#define D_P35_OFF() P35 = 0 +#define D_P34_OFF() P34 = 0 +#define D_P33_OFF() P33 = 0 +#define D_P32_OFF() P32 = 0 +#define D_P31_OFF() P31 = 0 +#define D_P30_OFF() P30 = 0 +#define D_P37_AT() (P37) +#define D_P36_AT() (P36) +#define D_P35_AT() (P35) +#define D_P34_AT() (P34) +#define D_P33_AT() (P33) +#define D_P32_AT() (P32) +#define D_P31_AT() (P31) +#define D_P30_AT() (P30) +#define D_P37_REV() P37 = ~P37 +#define D_P36_REV() P36 = ~P36 +#define D_P35_REV() P35 = ~P35 +#define D_P34_REV() P34 = ~P34 +#define D_P33_REV() P33 = ~P33 +#define D_P32_REV() P32 = ~P32 +#define D_P31_REV() P31 = ~P31 +#define D_P30_REV() P30 = ~P30 + + +#define D_P47_ON() P47 = 1 +#define D_P46_ON() P46 = 1 +#define D_P45_ON() P45 = 1 +#define D_P44_ON() P44 = 1 +#define D_P43_ON() P43 = 1 +#define D_P42_ON() P42 = 1 +#define D_P41_ON() P41 = 1 +#define D_P40_ON() P40 = 1 +#define D_P47_OFF() P47 = 0 +#define D_P46_OFF() P46 = 0 +#define D_P45_OFF() P45 = 0 +#define D_P44_OFF() P44 = 0 +#define D_P43_OFF() P43 = 0 +#define D_P42_OFF() P42 = 0 +#define D_P41_OFF() P41 = 0 +#define D_P40_OFF() P40 = 0 +#define D_P47_AT() (P47) +#define D_P46_AT() (P46) +#define D_P45_AT() (P45) +#define D_P44_AT() (P44) +#define D_P43_AT() (P43) +#define D_P42_AT() (P42) +#define D_P41_AT() (P41) +#define D_P40_AT() (P40) +#define D_P47_REV() P47 = ~P47 +#define D_P46_REV() P46 = ~P46 +#define D_P45_REV() P45 = ~P45 +#define D_P44_REV() P44 = ~P44 +#define D_P43_REV() P43 = ~P43 +#define D_P42_REV() P42 = ~P42 +#define D_P41_REV() P41 = ~P41 +#define D_P40_REV() P40 = ~P40 + +#define D_P57_ON() P57 = 1 +#define D_P56_ON() P56 = 1 +#define D_P55_ON() P55 = 1 +#define D_P54_ON() P54 = 1 +#define D_P53_ON() P53 = 1 +#define D_P52_ON() P52 = 1 +#define D_P51_ON() P51 = 1 +#define D_P50_ON() P50 = 1 +#define D_P57_OFF() P57 = 0 +#define D_P56_OFF() P56 = 0 +#define D_P55_OFF() P55 = 0 +#define D_P54_OFF() P54 = 0 +#define D_P53_OFF() P53 = 0 +#define D_P52_OFF() P52 = 0 +#define D_P51_OFF() P51 = 0 +#define D_P50_OFF() P50 = 0 +#define D_P57_AT() (P57) +#define D_P56_AT() (P56) +#define D_P55_AT() (P55) +#define D_P54_AT() (P54) +#define D_P53_AT() (P53) +#define D_P52_AT() (P52) +#define D_P51_AT() (P51) +#define D_P50_AT() (P50) +#define D_P57_REV() P57 = ~P57 +#define D_P56_REV() P56 = ~P56 +#define D_P55_REV() P55 = ~P55 +#define D_P54_REV() P54 = ~P54 +#define D_P53_REV() P53 = ~P53 +#define D_P52_REV() P52 = ~P52 +#define D_P51_REV() P51 = ~P51 +#define D_P50_REV() P50 = ~P50 + +#define D_P67_ON() P67 = 1 +#define D_P66_ON() P66 = 1 +#define D_P65_ON() P65 = 1 +#define D_P64_ON() P64 = 1 +#define D_P63_ON() P63 = 1 +#define D_P62_ON() P62 = 1 +#define D_P61_ON() P61 = 1 +#define D_P60_ON() P60 = 1 +#define D_P67_OFF() P67 = 0 +#define D_P66_OFF() P66 = 0 +#define D_P65_OFF() P65 = 0 +#define D_P64_OFF() P64 = 0 +#define D_P63_OFF() P63 = 0 +#define D_P62_OFF() P62 = 0 +#define D_P61_OFF() P61 = 0 +#define D_P60_OFF() P60 = 0 +#define D_P67_AT() (P67) +#define D_P66_AT() (P66) +#define D_P65_AT() (P65) +#define D_P64_AT() (P64) +#define D_P63_AT() (P63) +#define D_P62_AT() (P62) +#define D_P61_AT() (P61) +#define D_P60_AT() (P60) +#define D_P67_REV() P67 = ~P67 +#define D_P66_REV() P66 = ~P66 +#define D_P65_REV() P65 = ~P65 +#define D_P64_REV() P64 = ~P64 +#define D_P63_REV() P63 = ~P63 +#define D_P62_REV() P62 = ~P62 +#define D_P61_REV() P61 = ~P61 +#define D_P60_REV() P60 = ~P60 + +#define D_P77_ON() P77 = 1 +#define D_P76_ON() P76 = 1 +#define D_P75_ON() P75 = 1 +#define D_P74_ON() P74 = 1 +#define D_P73_ON() P73 = 1 +#define D_P72_ON() P72 = 1 +#define D_P71_ON() P71 = 1 +#define D_P70_ON() P70 = 1 +#define D_P77_OFF() P77 = 0 +#define D_P76_OFF() P76 = 0 +#define D_P75_OFF() P75 = 0 +#define D_P74_OFF() P74 = 0 +#define D_P73_OFF() P73 = 0 +#define D_P72_OFF() P72 = 0 +#define D_P71_OFF() P71 = 0 +#define D_P70_OFF() P70 = 0 +#define D_P77_AT() (P77) +#define D_P76_AT() (P76) +#define D_P75_AT() (P75) +#define D_P74_AT() (P74) +#define D_P73_AT() (P73) +#define D_P72_AT() (P72) +#define D_P71_AT() (P71) +#define D_P70_AT() (P70) +#define D_P77_REV() P77 = ~P77 +#define D_P76_REV() P76 = ~P76 +#define D_P75_REV() P75 = ~P75 +#define D_P74_REV() P74 = ~P74 +#define D_P73_REV() P73 = ~P73 +#define D_P72_REV() P72 = ~P72 +#define D_P71_REV() P71 = ~P71 +#define D_P70_REV() P70 = ~P70 + + + +#endif //__C51_MACRO_H_ + + + + + + + diff --git a/source/ctask/task.c b/source/ctask/task.c new file mode 100644 index 0000000..15e272c --- /dev/null +++ b/source/ctask/task.c @@ -0,0 +1,288 @@ +/***************************************************** +*============================================================================ +* HISTORY +* Below this line, this part is controlled by TSTS. DO NOT MODIFY!! +αʱƬǶʽƽ̨(Task Step by Step Turn by Turn StructureTSTS +*============================================================================ +****************************************************************************/ + +#include "task.h" +//: +// 1:һ +/// 0оƬ flash +/// 1оƬӦü save +/// 2Ӧü jilu_save +// +// 2:ڶ/flash/i2c/7290/ȸоƬ +// 3:/ͬоƬ/ +// + +void L1_task_init(TS_task *s) +{ +// s->en = 1; +// s->pfun = 0; + s->sh = 0; + s->sh_next= 0; +/// s->sh_pre= 0; + s->n= 0; +} + + +/////ʾtask ṹʹ ɾ +#define D_task_test_01 0x20 +#define D_task_test_02 0x22 +#define D_task_test_03 0x23 +#ifdef D_debug_task_test +////>>>>>>>>>>>>>>>>>>>>>_s_task_test_>>>>>>>>>>>>>>>>>>>>>> +struct _s_task_test_ s_task_test; +void L2_task_test_init(void) +{ +ddd + L1_task_init(&s_task_test.task); + L3_task_s_go(s_task_test,D_task_init); +} + + +///L2_task_test_handle(&s_task_test); +void L2_task_test_handle(struct _s_task_test_ *s) +{ + unsigned char d = 0; + TTSS_Task_init(); + L2_task_go(D_task_test_01); + TTSS_Task_step(D_task_test_01): + if(d > 8) + { + d = 0; + L2_task_go(D_task_test_02); + L1_task_Cdelay(D_Cdelay_200us); + }else + { + d ++; + } + TTSS_Task_step(D_task_test_02): + if(d > 4) + { + d = 0; + L2_task_go(D_task_test_01); + L1_task_Tdelay(D_Tdelay_100ms); + }else + { + d ++; + } + + TTSS_Task_end(); +} +#endif//#ifdef D_debug_task_test +////<<<<<<<<<<<<<<<<<<<<<_s_task_test_<<<<<<<<<<<<<<<<<<<<<< + +/////<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<ʾtask ṹʹ ɾ + + +//example : +#if 0 + + +//L2_task_voice_handle(&s_task_music.task); +//L1_task_go(D_task_close); +//if(L1_task_busy(s)){ L1_task_goout(s_task_music.task,D_task_voice_send_single) } +void L2_task_voice_handle(struct _s_task_music_ *s) +{ //s_task_music.task.sh + switch(s->task.sh) + { + + case D_task_voice_init:// + + s->sector = 0; + break; + case D_task_voice_cuimian : + s->sector = D_voice_music_wantsleep; + L2_task_go_son(D_task_voice_play,D_task_voice_cuimian1); + break; + case D_task_voice_cuimian1:// + L2_task_go(D_task_voice_cuimian2); + + break; + case D_task_voice_cuimian2:// + + if(0 == s->volume_change) + { + //L3_voice_stop(); + s->sector = D_voice_stop; + s->status = D_voice_status_stop; + //L2_task_go(D_task_voice_play); + L2_task_go_son(D_task_voice_play,0); + }else + { + s->volume_change --; + s->volume_temp = s->volume; + s->volume = s->volume_change*s->volume_shop/20;// + if (s->volume_temp != s->volume) + { + s->sector = D_voice_volume|s->volume; + //s->status = D_voice_status_stop; + //L2_task_go(D_task_voice_volume3); + L2_task_go_son(D_task_voice_play,D_task_voice_cuimian2); + } + //else + { + L2_task_delay(D_task_delay_1m); + } + } + break; + + //>>>>>>>>>>>>>>>>>> son function + case D_task_voice_play:// + if(L3_task_s_busy(s_task_wt558d)) + { + }else + { + s_task_wt558d.reg = s_task_music.sector; + L3_task_s_go(s_task_wt558d,D_task_wt558d_fun); + + L2_task_go(D_task_voice_ask); + } + break; + case D_task_voice_ask:// + if(L3_task_s_busy(s_task_wt558d)) + { + + }else + { + + L2_task_go_father();//ص + } + break; + //<<<<<<<<<<<<<<<<<<<<<< son function + //-----------------------task standerd code + case D_task_Tdelay://---- + s->task.n--; + if (s->task.n == 0) + { + s->task.n = 0; + L2_task_delay_over(); + } + break; + + default : + break; + } + L2_task_wt558d_handle(&s_task_wt558d); +} + + +void L2_task_voice_handle(struct _s_task_music_ *s) +{ //s_task_music.task.sh + switch(s->task.sh) + { + + case D_task_voice_init:// + + s->sector = 0; + break; + case D_task_voice_cuimian : + s->sector = D_voice_music_wantsleep; + L2_task_go_son(D_task_voice_play,D_task_voice_cuimian1); + break; + case D_task_voice_cuimian1:// + L2_task_go(D_task_voice_cuimian2); + + break; + + //-----------------------task standerd code + case D_task_Tdelay://---- + s->task.n--; + if (s->task.n == 0) + { + s->task.n = 0; + L2_task_delay_over(); + } + break; + + default : + break; + } + L2_task_wt558d_handle(&s_task_wt558d); +} + +//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +//>>>>>>>>>>>>>>>>>>>>>¼task +struct _s_task_4ChuShengRiQi_ +{ + TS_task task; + unsigned char pic_id;//ID + + +}; +extern struct _s_task_4ChuShengRiQi_ s_task_4ChuShengRiQi_; + +#define D_task_4ChuShengRiQi_init 0x10 +#define D_task_4ChuShengRiQi_key 0x11 + + +extern void L2_task_4ChuShengRiQi_handle(struct _s_task_4ChuShengRiQi_ *s); + +void L2_task_4ChuShengRiQi_handle(struct _s_task_4ChuShengRiQi_ *s) +{ + switch(s->task.sh) + { + + case D_task_4ChuShengRiQi_init:// + + s->pic_id= 0; + break; + case D_task_4ChuShengRiQi_key : + if(1 == s_task_keyx1.down ) + { + s_task_keyx1.down = 0; + + if(D_keyx_left == s_task_keyx1.key_value) + {} + + + }else if(1 == s_task_keyx_4.down) + { + s_task_keyx_4.down = 0; + + + } + else {} + + //L2_task_go_son(D_task_4ChuShengRiQi_play,D_task_4ChuShengRiQi_cuimian1); + break; + + L0_task_delay(); + } +} + + + +//<<<<<<<<<<<<<<<<<<<¼task + + + + + +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + + + + + + +/***************************************************** +*============================================================== +* HISTORY +* Below this line, this part is controlled by TSTS. DO NOT MODIFY!! +αʱƬǶʽƽ̨(Task Step by Step Turn by Turn StructureTSTS +*============================================================== +****************************************************************************/ + + + + + + +#endif + + diff --git a/source/ctask/task.h b/source/ctask/task.h new file mode 100644 index 0000000..5b08832 --- /dev/null +++ b/source/ctask/task.h @@ -0,0 +1,288 @@ +/******************************** +2013.7.23 add dictionary and task step by cc + +:task +:task step +־:sh ( struct handle) + +һsh_next +,sh_nextִִsh_pre + +***************************/ +/***************************************************** +*============================================================== +* HISTORY +* Below this line, this part is controlled by TSTS. DO NOT MODIFY!! +αʱƬǶʽƽ̨(Task Step by Step Turn by Turn StructureTSTS +*============================================================== + +20190217 and step01 Ұdelay_nű + + + +****************************************************************************/ + +#ifndef _TASK_H_ +#define _TASK_H_ +#include "../clib/type.h" +#include "../msp/time.h" +#include "task.h" +#include "tick.h" + +typedef struct +{ + vU32 n; +/// volatile UN_TYPE en; //ر,ҲΪͣ,ʹidelayĵطʱں̨ʱ˺ͣ,delay൱ͣ + volatile UN_TYPE sh; //ǰ + volatile UN_TYPE sh_next; //һ,һһһ,пмʱ +/// volatile UN_TYPE sh_pre; //ǰһ,һΪʹ +}TS_task; +//extern TS_task ts_task_stcadc; +#define D_task_close 0 + +#define D_task_Tdelay 0x01 +#define D_task_stop 0x04 +#define D_task_Cdelay 0x09 +#define D_task_init 0x10 +#define D_task_quit 0xf0 + +#define TTS_for_add(i,start,len) for((i) = (start); (i) < (len); (i) ++){ +#define TTS_for_add_end() } + + + +//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>ڲ s->task +#define L2_task_delay_over() s->task.sh = s->task.sh_next +#define L2_task_go(next) s->task.sh = next +#define L2_task_en(onf) s->task.en = onf + +#define L2_task_busy(s) (D_task_close != s.task.sh) +#define L2_task_free(s) (D_task_close == s.task.sh) + +#define L2_task_go_father() s->task.sh = s->task.sh_pre +#define L2_task_go_son(fun,pre) s->task.sh = fun;s->task.sh_pre = pre + + +//>task ʱ>>>>>>>>>>>>>>TTSS +/// D_task_Tdelay == task timer delay ҪиʱԪ time0ʱ +/// Delay_cycle ʱ̵,һѭȡѭʱ,Tdelay,Cdelayʱʱ +#define L2_task_switch_default_idelay(); \ + case D_task_Tdelay:\ + if (s_nos_tick.t_10ms >= s->task.n)\ + {\ + L2_task_delay_over();\ + }\ + break; \ + case D_task_Cdelay:\ + s->task.n--; \ + if (s->task.n == 0) \ + { \ + s->task.n = 0; \ + L2_task_delay_over();\ + } \ + break;\ + default : \ + break; +#if 0 + +#define L2_task_switch_default_idelay2(); \ + case D_task_Tdelay:\ + if (s_nos_tick.t_10ms >= s->task.n)\ + {\ + L2_task_delay_over();\ + }else\ + {\ + L2_time_beat_heart(D_TBH_ch0,3,'i');\ + }\ + break; \ + case D_task_Cdelay:\ + s->task.n--; \ + if (s->task.n == 0) \ + { \ + s->task.n = 0; \ + L2_task_delay_over();\ + } \ + break;\ + default : \ + break; + + + +//ڵȴĹüʱ,ʱfunxx +//ڵȴĿʱԶʱʾһЩϢ +//ִ + +#define L2_task_switch_fun_idelay(invent,ch) L2_task_switch_default_idelay() +#define L2_task_switch_fun_idelay0000(chhh,invent,funxx); \ + case D_task_Tdelay:\ + if (s_nos_tick.t_10ms >= s->task.n)\ + {\ + L2_task_delay_over();\ + }else\ + {\ + L2_time_beat_heart_fun(chhh,invent,funxx);\ + }\ + break; \ + case D_task_Cdelay:\ + s->task.n--; \ + if (s->task.n == 0) \ + { \ + s->task.n = 0; \ + L2_task_delay_over();\ + } \ + break;\ + default : \ + break; + + + + +//ڵȴĹüʱ,ʱʾַch +//ڵȴĿʱԶʱʾһЩϢch +// ͨchĿǰеĽ׶κϢ +#define L2_task_switch_flag_idelay(invent,ch) L2_task_switch_default_idelay() +#define L2_task_switch_flag_idelay000(invent,ch); \ + case D_task_Tdelay:\ + if (s_nos_tick.t_10ms >= s->task.n)\ + {\ + L2_task_delay_over();\ + }else\ + {\ + L2_time_beat_heart(D_TBH_ch0,invent,ch);\ + }\ + break; \ + case D_task_Cdelay:\ + s->task.n--; \ + if (s->task.n == 0) \ + { \ + s->task.n = 0; \ + L2_task_delay_over();\ + } \ + break;\ + default : \ + break; + + +TTSS_Task_init, Highlight +TTSS_Task_step, Highlight +TTSS_Task_end, Highlight +L2_task_go, Highlight +L1_task_Tdelay, Highlight +L1_task_Cdelay, Highlight +L2_task_go, Highlight + + + + +#endif + + +//if(delay_n+s_time0.t_10ms > 655340) +//{s_time0.t_10ms = 0;} + +//fix 201312 ֹs_time0.t_10ms +// з +//>>L2_task_delayһҪL2_task_go֮ +#define L1_task_Tdelay(delay_n) s->task.sh_next = s->task.sh;\ + s->task.sh = D_task_Tdelay;\ + s->task.n = (delay_n) + s_nos_tick.t_10ms; + + +//>>L2_task_delayһҪL2_task_go֮ +#define L1_task_Cdelay(delay_n) s->task.sh_next = s->task.sh;\ + s->task.sh = D_task_Cdelay;\ + s->task.n = (delay_n) + + +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<ڲ s->task + +//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ⲿ +#define L2_task_s_go_son(s,fun,pre) (s).task.sh = fun;(s).task.sh_pre = pre; + +#define L3_task_s_time_start(s,delay) (s).task.n = delay+s_nos_tick.t_1s; +#define L3_task_s_go(s,next) (s).task.sh = next; +#define L3_task_s_en(s,onf) (s).task.en = onf; +//L1_task_goout(s_task_music.task,D_task_close); + +#define L3_task_s_busy(s) (D_task_close != (s).task.sh) +#define L3_task_s_free(s) (D_task_close == (s).task.sh) + +#define L3_task_s_step(s) ((s).task.sh) + + +#define D_task_uc unsigned char +#define D_task_ui unsigned int +///>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +#define TTSS_Task_init() switch(s->task.sh){\ + case D_task_init + +#define TTSS_Task_step(step) break;\ + case (step) +#define TTSS_step01(step) break;case (step) +#define TTSS_step02(step) break;case (step) +#define TTSS_step03(step) break;case (step) +#define TTSS_step04(step) break;case (step) +#define TTSS_step05(step) break;case (step) +#define TTSS_step06(step) break;case (step) +#define TTSS_step07(step) break;case (step) +#define TTSS_step08(step) break;case (step) +#define TTSS_step09(step) break;case (step) +#define TTSS_step10(step) break;case (step) +#define TTSS_step11(step) break;case (step) +#define TTSS_step12(step) break;case (step) + + + + + + + +#define TTSS_Task_end(); break;\ + L2_task_switch_default_idelay();} + + +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +extern void L1_task_init(TS_task *s); + + + +////>>>>>>>>>>>>>>>>>>>_s_task_test_>>>>>>>>>>>>>>>>>>>>>>>> + +#ifdef D_debug_task_test + +struct _s_task_test_ +{ + TS_task task; +}; +extern struct _s_task_test_ s_task_test; +extern void L2_task_test_handle(struct _s_task_test_ *s); +extern void L2_task_test_init(void); +#else + +#define L2_task_test_handle(x); +#define L2_task_test_init(); + +#endif//#ifdef D_debug_task_test + +////<<<<<<<<<<<<<<<<<<<_s_task_test_<<<<<<<<<<<<<<<<<<<<<<<< + + + + + + + + +#endif//_TASK_H_ +/***************************************************** +*============================================================== +* HISTORY +* Below this line, this part is controlled by TSTS. DO NOT MODIFY!! +αʱƬǶʽƽ̨(Task Step by Step Turn by Turn StructureTSTS +*============================================================== +****************************************************************************/ + + + diff --git a/source/ctask/tick.c b/source/ctask/tick.c new file mode 100644 index 0000000..0d3d01d --- /dev/null +++ b/source/ctask/tick.c @@ -0,0 +1,133 @@ +/***************************************************************************** + * uart.h: Header file for NXP LPC17xx Family Microprocessors + * + * Copyright(C) 2017,SensorControl + * All rights reserved. + * + * History + * 2009.05.27 ver 1.00 Prelimnary version, first Release + *2017.01.10 ver 1.10 rename tick.h tick.c + 2019.03.11 ver 1.30 ʱʱΪ25ms ڽܸŵ +****************************************************************************************/ +/***************************************************** +*============================================================================ +* HISTORY +* Below this line, this part is controlled by TSTS. DO NOT MODIFY!! +αʱƬǶʽƽ̨(Task Step by Step Turn by Turn StructureTSTS +*============================================================================ +****************************************************************************/ + +#include "tick.h" + + +struct _s_nos_tick_ s_nos_tick; + + + +#ifdef D_use_tick_fum +void L1_tick_init(void) +{ + s_nos_tick.tp_count = 0; + + s_nos_tick.n_stamp = 0; + s_nos_tick.t1s_heatbeart= 0; + /***** + s_nos_tick.t1s_flag[0] = 0; + s_nos_tick.t1s_flag[1] = 0; + s_nos_tick.t1s_flag[2] = 0; + s_nos_tick.t1s_flag[3] = 0; + s_nos_tick.t1s_flag[4] = 0; + s_nos_tick.t1s_flag[5] = 0; + if(L2_tick_time_interval(n_stamp,7*D_Tdelay_1s)) + {// ʱ + + + L2_tick_time_stamp(s->t_stamp); + + + ********/ + + s_nos_tick.t_10ms = 0; + s_nos_tick.t_1s = 0; + +/// s_nos_tick.flag_1s = 0; + +/// s_nos_tick.t_n = 0; + //s_nos_tick.tmp = 0; + //L0_timer0_ONF(1); +} + +/// ʱ 10ms һж +/// ʱ 25ms һж +void L1_tick_tick (void) +{ /// 65535*65535 /3600/24/365=139nian/s=1.39nian/10ms + ///൱1.39t_10ms ڵعϵͳ ȫ + // 4,294,836,225 = 65535*65535 ;3600*24*60*60 = 31,536,000/ + s_nos_tick.tp_count++; + s_nos_tick.t_10ms ++;//D_led_D1_REV(); 20160522 ֤ + if(s_nos_tick.t_10ms%D_TIMER0_1S_COUNT == 0) + {// 65535*65535/24/60/60/356/10 =12.7 + s_nos_tick.t_1s ++;//// 65535*65535/24/60/60/356/10 =12.7 + s_nos_tick.flag_1s2 = 1; + s_nos_tick.t1s_heatbeart = 1; + } +//<<<<<<<<<<<<<<<<<<<<<< +} +#else + +#endif + +#if 0 +void L1_tick_tick (void) +{ + s_nos_tick.t_n++; + if (s_nos_tick.t_n >= D_TIMER0_10MS_COUNT)// 5500--- 100 10s--556 + /// s 5ms 65535*65535 /3600/24/365=139nian/s + // 4,294,836,225 = 65535*65535 ;3600*24*60*60 = 31,536,000/ + // fixme:˴ һbug:) + { + s_nos_tick.t_10ms ++;//D_led_D1_REV(); 20160522 ֤ + if(s_nos_tick.t_10ms%D_TIMER0_1S_COUNT == 0) + {// 65535*65535/24/60/60/356/10 =12.7 + s_nos_tick.t_1s ++;// + + // led_red =~led_red; + //s_nos_tick.t1s_flag[0] = 1; + //s_nos_tick.t1s_flag[1] = 1; + //s_nos_tick.t1s_flag[2] = 1; + //s_nos_tick.t1s_flag[3] = 1; + //s_nos_tick.t1s_flag[4] = 1; + //s_nos_tick.t1s_flag[5] = 1; + s_nos_tick.flag_1s = 1; + s_nos_tick.t1s_heatbeart = 1; + } + s_nos_tick.t_n = 0; + } + /******************* +// 0.2mm 4/0.2 = 20 20/60s = 333ms/maicong +// 0.2mm 60s 60 100 ms +// 0.2 6000ms +// ƽʱΪ1 ˮһΪ0 +// rain = 1;Ҫijʼ + if(0 == rain) + { + if(1 == s_rain.temp) + {// ````\___ + s_rain.pool = s_rain.t; + s_rain.all ++; + s_rain.t = 0; + } + s_rain.temp = 0; + }else + { + s_rain.temp = 1; + } + s_rain.t ++; + + ******/ +//<<<<<<<<<<<<<<<<<<<<<< +} + + +#endif + diff --git a/source/ctask/tick.h b/source/ctask/tick.h new file mode 100644 index 0000000..dafeb42 --- /dev/null +++ b/source/ctask/tick.h @@ -0,0 +1,210 @@ +/***************************************************************************** + * uart.h: Header file for NXP LPC17xx Family Microprocessors + * + * Copyright(C) 2017,SensorControl + * All rights reserved. + * + * History + * 2009.05.27 ver 1.00 Prelimnary version, first Release + *2017.01.10 ver 1.10 rename tick.h tick.c +******************************************************************************/ +/***************************************************** +*============================================================================ +* HISTORY +* Below this line, this part is controlled by TSTS. DO NOT MODIFY!! +αʱƬǶʽƽ̨(Task Step by Step Turn by Turn StructureTSTS +*============================================================================ +****************************************************************************/ +#ifndef __tick_H +#define __tick_H +#include "../clib/Type.h" +//#include "../bsp/type_hs.h" +#include "../msp/time.h" +#define D_use_tick_fum + + +struct _s_nos_tick_ +{ + vU32 tp_count; //һνʱ䵽Ŀǰtick +/// vU32 sys_clock; +// vU32 t_n; // noosϵͳʱСԪ + vU32 t_10ms; // noos ϵͳʱ10m +#ifdef D_use_tick_fum + + + //volatile INT32U t_100ms; + vU32 t_1s; +/// vU32 t_10s; +// vU32 t_60s; + vU8 flag_1s; + vU8 flag_1s2; +/// volatile INT32U tmp; +/// volatile INT32U time_left; +/// volatile INT32U h; +/// volatile INT32U m; + vU32 n_stamp; +// vU32 t1s_flag[6]; //fixme: INT32U ݲͬϵͳ + //volatile unsigned char t1s_flag; +/// vU8 ts_flag; + vU32 n_stamp3; +#endif + vU8 t1s_heatbeart; //noos ϵͳʱʱ̱־,Ҫ +}; +extern struct _s_nos_tick_ s_nos_tick; + +#ifdef D_timer0_10ms +//10ms ʹã10msСʱ޷ʹ +#define D_Tdelay_ms D_TIMER0_10MS_COUNT//D_TIMER0_10MS_COUNT +#define D_Tdelay_10ms 2 +#define D_Tdelay_20ms (2+D_Tdelay_ms) +#define D_Tdelay_30ms (3+D_Tdelay_ms) +#define D_Tdelay_40ms (4+D_Tdelay_ms) +#define D_Tdelay_50ms (5+D_Tdelay_ms) +#define D_Tdelay_60ms (6+D_Tdelay_ms) + +#define D_Tdelay_80ms (8+D_Tdelay_ms) + + +#define D_Tdelay_100ms (10+D_Tdelay_ms) + +#else +//10ms ʹã10msСʱ޷ʹ +#define D_Tdelay_ms D_TIMER0_10MS_COUNT//D_TIMER0_10MS_COUNT +#define D_Tdelay_10ms 1 +#define D_Tdelay_20ms (0+D_Tdelay_ms) +#define D_Tdelay_30ms (0+D_Tdelay_ms) +#define D_Tdelay_40ms (2+D_Tdelay_ms) +#define D_Tdelay_50ms (2+D_Tdelay_ms) +#define D_Tdelay_60ms (2+D_Tdelay_ms) + +#define D_Tdelay_80ms (3+D_Tdelay_ms) + +#define D_Tdelay_100ms (4+D_Tdelay_ms) + +#endif + + +#define D_Tdelay_200ms (D_Tdelay_100ms*2) +#define D_Tdelay_300ms (D_Tdelay_100ms*3) +#define D_Tdelay_400ms (D_Tdelay_100ms*4) +#define D_Tdelay_500ms (D_Tdelay_100ms*5) + +#define D_Tdelay_600ms (D_Tdelay_100ms*6) +#define D_Tdelay_700ms (D_Tdelay_100ms*7) +#define D_Tdelay_800ms (D_Tdelay_100ms*8) +#define D_Tdelay_900ms (D_Tdelay_100ms*9) + + +#define D_Tdelay_1s (D_Tdelay_100ms*10) +#define D_Tdelay_1s2 (D_Tdelay_100ms*12) +#define D_Tdelay_1s5 (D_Tdelay_100ms*15) +#define D_Tdelay_2s (D_Tdelay_100ms*20) +#define D_Tdelay_2s5 (D_Tdelay_100ms*25) +#define D_Tdelay_3s (D_Tdelay_100ms*30) +#define D_Tdelay_5s (D_Tdelay_100ms*50) +#define D_Tdelay_8s (D_Tdelay_100ms*80) +#define D_Tdelay_9s (D_Tdelay_100ms*90) +#define D_Tdelay_10s (D_Tdelay_100ms*100) + +#define D_Tdelay_1min (D_Tdelay_1s*60) +#define D_Tdelay_1h (D_Tdelay_1min*60) +#define D_Tdelay_1day (D_Tdelay_1h*24) +#define D_TIMER0_1S_COUNT 100 +//#define D_10mS 1//D_TIMER0_10MS_COUNT +//#define D_100mS (D_10mS*10) +//#define D_1S (D_10mS*100) + + + + +//>> ʱ: ʼ ʱ䵽 +// L0_nos_tick10ms_start(s->times); ʼʼs->times 10msΪһλ +// if( L0_nos_tick10ms_interval(s->times) < 20)// s->times ִ20κ,Ҳ ʱ20*10m + + +// +#define L0_nos_tick10ms_start(start_n) start_n = s_nos_tick.t_10ms +#define L0_nos_tick10ms_interval(start_n) (s_nos_tick.t_10ms - start_n) + + + +#define L0_nos_tick1s_start(start_n) start_n = s_nos_tick.t_1s +#define L0_nos_tick1s_interval(start_n) (s_nos_tick.t_1s - start_n) + + + +//>>>// +#define L2_tick_time_stamp(time_stamp) time_stamp = s_nos_tick.t_10ms; +#define L2_tick_time_interval(time_stamp,time_overflow) (( s_nos_tick.t_10ms - time_stamp) > time_overflow) + + +#define L3_tick_interval(x) L2_tick_time_interval(s_nos_tick.n_stamp,x) +#define L2_tick_stamp() L2_tick_time_stamp(s_nos_tick.n_stamp); + + +//>>>ʾ: +#if 0 +{ + case D_task_init:// + Lc_print_buf(" \r\n YL_ init"); + s->step = D_AT; + L0_esp_open(); + L2_task_go(D_task_YL_ready); + s_uart0_rec.ok = 0; + L2_tick_time_stamp(s->t_stamp); + // L1_task_Tdelay(1*D_Tdelay_1s); //Լ6s + break; + case D_task_YL_ready: + if(1 == s_uart0_rec.ok) + { + if(strstr(s_uart0_rec.array,"ready") != NULL) + { + + Ldi_print("ready..\r\n"); + s->step = D_AT; + L2_task_go(D_task_YL_ask); + } + s_uart0_rec.ok = 0; + } + if(L2_tick_time_stamp(s->t_stamp,1*D_Tdelay_1s)) + {// ʱ + L0_esp_close(); + Ldi_print("fail esp restart.\r\n"); + L2_task_go(D_task_init); + L1_task_Tdelay(2*D_Tdelay_1s); + } + break; +} +#endif + +// t_10ms ,t_10msΪ1ʱΪ(D_TIMER0_10MS_COUNT*ʱ) +/// #define D_TIMER0_10MS_COUNT 1 //ʱΪ 10msһж +#ifdef D_use_tick_fum +extern void L1_tick_init(void); +extern void L1_tick_tick (void); + +#else + + +#define L1_tick_init() +#define L1_tick_tick() s_nos_tick.t_10ms ++; + +#endif + + + +//L2_time_beat_heart(D_TBH_ch1,2,'t') +#define D_TBH_ch0 0 +#define D_TBH_ch1 1 +#define D_TBH_ch2 2 +#define D_TBH_ch3 3 +#define D_TBH_ch4 4 +#define D_TBH_ch5 5 +extern void L2_time_beat_heart(vU32 ch,U8 invent,U8 s); +//void L2_time_beat_heart_fun(INT32U ch,unsigned char invent,void *fun(void)); +extern void L2_time_beat_heart_fun(vU32 ch,U8 invent,void (*fun)(void)); + +#endif /* end __tick_H */ +/***************************************************************************** +** End Of File +******************************************************************************/ diff --git a/source/msp/UART0.C b/source/msp/UART0.C new file mode 100644 index 0000000..94f1962 --- /dev/null +++ b/source/msp/UART0.C @@ -0,0 +1,448 @@ +////////////////////////////////////////////////////////////////////////// +/// 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: + +/***************************************************************************** +update by cc @201800400 +针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是 +个需要平衡的事情. + +clib/clib.c: +公用的函数 和硬件无关 +放置串行模式(串口等其他通讯总线类的输出)输出的函数, +一些覆盖模式输出的(lcd等固屏输出的)的也可使用 + void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...) +----------------------------------------------------------------------------------------- + +----------------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------------------- +msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 + L0_UART0_Init + UART0_IRQHandler + L0_Usend_uc------UserDef +----------------------------------------------------------------------------------------- +********************************************************************************/ +#include "uart0.h" +//#include "uart2.h" +//#include "uart3.h" +//#include "uart4.h" + #include + #include "../ctask/tick.h" + #include "../app/common.h" + #include "../msp/time.h" + +// TS_Handle_PH1 volatile s_uart0_rec; +// TS_Handle_PH1A volatile s_uart0_rec; +TS_Handle_PH4 volatile s_uart0_rec; + +///struct _s_uart0_send_buf_ ts_uart_send_shop; +//struct _s_uart0_send_buf_ ts_uart_send_depot; +volatile Ts_uart_send_buf ts_uart_send_shop; +////volatile Ts_uart_send_buf ts_uart_send_depot; + +#if(MainFre_5M == D_sys_MainFre) + void L0_uart0_init32K_290BPS(void) //290bps@32kHz + {//定时器2 16位重载 作为串口波特率 + SCON = 0x50; //8位数据,可变波特率 + AUXR |= 0x01; //串口1选择定时器2为波特率发生器 + BITN_1(AUXR, BITN5);// f/2 + T2L = 0xFE; //设定定时初值 + T2H = 0xFF; //设定定时初值 /// 32K 280---290BPS + AUXR |= 0x10; //启动定时器2 + } + + +#elif(MainFre_27M == D_sys_MainFre) +#elif(MainFre_22M == D_sys_MainFre) + #if(BRT_115200 == D_uart0_BRT) + void L0_uart0_init(void) //115200bps@22.1184MHz + {//定时器2 16位重载 作为串口波特率 + SCON = 0x50; //8位数据,可变波特率 + AUXR |= 0x01; //串口1选择定时器2为波特率发生器 + AUXR &= 0xFB; //定时器2时钟为Fosc/12,即12T + T2L = 0xFC; //设定定时初值 + T2H = 0xFF; //设定定时初值 + AUXR |= 0x10; //启动定时器2 + } + + #elif(BRT_4800 == D_uart0_BRT) + void L0_Uart0_Init(void) //4800bps@22.1184MHz + { + SCON = 0x50; //8位数据,可变波特率 + AUXR |= 0x01; //串口1选择定时器2为波特率发生器 + AUXR |= 0x04; //定时器2时钟为Fosc,即1T + T2L = 0x80; //设定定时初值 + T2H = 0xFB; //设定定时初值 + AUXR |= 0x10; //启动定时器2 + } + #elif(BRT_SIM == D_uart0_BRT) + void L0_uart0_init(void) + { + SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */ + TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */ + TH1 = 221; /* TH1: reload value for 1200 baud @ 16MHz */ + TR1 = 1; /* TR1: timer 1 run */ + TI = 1; /* TI: set TI to send first char of UART */ + EA = 1; + AUXR = 0x40; + // TI = 0; + RI = 0; + D_uart0_ES_INT(1); //打开串口中断 + } + #endif + +#else ///MainFre_11M + + #if(BRT_115200 == D_uart0_BRT && SBIT_1 == D_uart0_SBIT) + void L0_uart0_init(void) //115200bps@11.0592MHz + { + SCON = 0x50; //8位数据,可变波特率 + AUXR |= 0x01; //串口1选择定时器2为波特率发生器 + AUXR &= 0xFB; //定时器2时钟为Fosc/12,即12T + T2L = 0xFE; //设定定时初值 + T2H = 0xFF; //设定定时初值 + AUXR |= 0x10; //启动定时器2 + } + #elif(BRT_19200 == D_uart0_BRT && SBIT_1 == D_uart0_SBIT) + void L0_uart0_init(void) //19200@11.0592MHz + { + xxxx + SCON = 0x50; //8位数据,可变波特率 + AUXR |= 0x01; //串口1选择定时器2为波特率发生器 + AUXR |= 0x04; //定时器2时钟为Fosc,即1T + T2L = 0x70; //设定定时初值 + T2H = 0xFF; //设定定时初值 + AUXR |= 0x10; //启动定时器2 + } + #elif(BRT_19200 == D_uart0_BRT && SBIT_2 == D_uart0_SBIT) + void L0_uart0_init(void) //19200@11.0592MHz + { + //使用第9位数据模拟1个停止位,可变波特率;SM2=0, TB8=1(第9bit总为1模拟1个停止位) + SCON = 0xD8; + AUXR |= 0x01; //串口1选择定时器2为波特率发生器 + AUXR |= 0x04; //定时器2时钟为Fosc,即1T + T2L = 0x70; //设定定时初值 + T2H = 0xFF; //设定定时初值 + AUXR |= 0x10; //启动定时器2 + } + #elif (BRT_9600 == D_uart0_BRT) + void L0_uart0_init(void) //9600bps@11.0592MHz + { + SCON = 0x50; //8位数据,可变波特率 + AUXR |= 0x01; //串口1选择定时器2为波特率发生器 + AUXR &= 0xFB; //定时器2时钟为Fosc/12,即12T + T2L = 0xE8; //设定定时初值 + T2H = 0xFF; //设定定时初值 + AUXR |= 0x10; //启动定时器2 + } + #endif +#endif//D_sys_MainFre) +void L1_uart0_buf_init(void) +{ +/// ts_uart_send_depot.p = ts_uart_send_depot.buf; + ts_uart_send_shop.now = 0; + s_uart0_rec.head = 0; + s_uart0_rec.ok = 0; + s_uart0_rec.num = 0; +// L1_s2b_PH4_init(&s_uart0_rec,G.p.slaver_id); +// s_uart0_rec.sp = s_uart0_rec.buf; +// s_uart0_rec.cmd = 0; +// head_0 = D_CMD_Filter1_ff; +// s_uart0_rec.head_1 = D_CMD_Filter2_fe; +// s_uart0_rec.sp = (U8*)&(s_uart0_rec.ts_ccmodbus); + + L0_uart0_init(); + +// L0_uart0_init(); + BITN_0(P3M1,BITN1);BITN_1(P3M0,BITN1);/// p31 01 tuiwan + + ts_uart_send_shop.ok = D_ready; + + D_uart0_ES_INT(1); //打开串口中断 + +} +//115200 0.1ms /Byte 115200/4800=23 0.1*23=2.3ms +/// 4800 uartb波形 2.1ms 一个数据 b8s 共10bits 1000ms 发送480个Bytes 大约就是2.1ms 一个数据 + +//// ````\_b_|___________________________/``s`|```2.1ms 0x00 sscom 测试 + +//// s 1 1 1 1 1 1 1 0 b11111111s + +//// ````\_b_/```````````````````````````|``s`|```200us 0xff + +//// ````\_b_|__/```\__/```\__/```\__/```|``s`|```1.9ms`\0xaa +//// b 1 0 1 0 1 0 1 0 b10101010s + +//// +//// ````\_b_|__/```\__/```\__/```\__/```|``s`|```1.9ms`\0xaa +//// b 1 0 1 0 1 0 1 0 b10101010s + +/// 1.9ms`\0xaa 0xaa 0xaa +//// ````\_b_|__/```\__/```\__/```\__/```|``s`|\_b_|__/```\__/```\__/```\__/```|``s`|\_b_|__/```\__/```\__/```\__/```|``s`| +//// b 1 0 1 0 1 0 1 0 s b 1 0 1 0 1 0 1 0 s b 1 0 1 0 1 0 1 0 s + + +//// ````\_200us_/`````0xff +//// ````\_200us_/`````0xff +void L0_uart0_uc(U8 ww) +{ + L0_uart0_sendArray(&ww,1); +} +extern void L2_waitFree_uart0(void); + + +#define D_waitFree_uart0() L2_waitFree_uart0() + + +/********* +while(ts_uart_send_shop.ok != D_ready)\ + {\ + if(ts_uart_send_shop.over ++ > 600000)\ + {\ + break;\ + }\ + }\ +*********************/ +void L0_uart0_us(vU32 ww) +{ + U_U16 uStemp; + uStemp.word = ww; + L0_uart0_uc(uStemp.BYTE2.h); + L0_uart0_uc(uStemp.BYTE2.l); +} +void L0_uart0_ul(vU32 ww) +{ + L0_uart0_uc(ww >> 24 & 0xFF); + L0_uart0_uc(ww >> 16 & 0xFF); + L0_uart0_uc(ww >> 8 & 0xFF); + L0_uart0_uc(ww >> 0 & 0xFF); +} +void L0_uart0_uchex(U8 ww) +{ + D_waitFree_uart0(); + ts_uart_send_shop.buf3[0] = cguHex2Char[D_uc_high(ww)][1]; + ts_uart_send_shop.buf3[1] = cguHex2Char[D_uc_low(ww)][1]; + L0_uart0_sendArray(ts_uart_send_shop.buf3,2); +} + +// void L0_uart0_ushex(U16 ww) +// { +// L0_uart0_uchex(ww >> 8 & 0xFF); +// L0_uart0_uchex(ww >> 0 & 0xFF); +// } + +void L0_uart0_ulhex(U32 ww) +{ + L0_uart0_uchex(ww >> 24 & 0xFF); + L0_uart0_uchex(ww >> 16 & 0xFF); + L0_uart0_uchex(ww >> 8 & 0xFF); + L0_uart0_uchex(ww >> 0 & 0xFF); +} + +void L0_uart0_uldec(U32 ww) +{ + L0_uart0_uc(ww / 1000000 % 10 + '0'); + L0_uart0_uc(ww / 100000 % 10 + '0'); + L0_uart0_uc(ww / 10000 % 10 + '0'); + L0_uart0_uc(ww / 1000 % 10 + '0'); + L0_uart0_uc(ww / 100 % 10 + '0'); + L0_uart0_uc(ww / 10 % 10 + '0'); + L0_uart0_uc(ww / 1 % 10 + '0'); +} + +/********** +void L0_uart0_uc_debug(U8 ww) +{ + L0_uart0_sendArray(&ww,1); + while(0 != ts_uart_send_shop.now){} +} + +void L0_uart0_ushex(vU16 ww,U8 hex) +{ + U8 buf3[4]; + U_F16 k; + k.us = ww; + if(16 == hex ) + { + buf3[0] = cguHex2Char[D_uc_high(k.BYTE2.H)][1]; + buf3[1] = cguHex2Char[D_uc_low(k.BYTE2.H)][1]; + buf3[2] = cguHex2Char[D_uc_high(k.BYTE2.L)][1]; + buf3[3] = cguHex2Char[D_uc_low(k.BYTE2.L)][1]; + L0_uart0_sendArray(buf3,4); + + }else if(2 == hex) + { + buf3[0] = (k.BYTE2.H); + buf3[1] = (k.BYTE2.L); + L0_uart0_sendArray(buf3,2); + }else + { + + buf3[0] = 0x55; + buf3[1] = 0x66; + + L0_uart0_sendArray(buf3,2); + + } +} +k.us = 0x1234 +uc + [0]=0x12 + [1]=0x34 +byte2 + H=0x12 + L=0x34 + +**********/ + +void L0_uart0_ushex(vU16 ww,U8 hex) +{ + U_F16 k; + k.us = ww; + D_waitFree_uart0(); + if(16 == hex ) + { + ts_uart_send_shop.buf3[0] = cguHex2Char[D_uc_high(k.BYTE2.H)][1]; + ts_uart_send_shop.buf3[1] = cguHex2Char[D_uc_low(k.BYTE2.H)][1]; + ts_uart_send_shop.buf3[2] = cguHex2Char[D_uc_high(k.BYTE2.L)][1]; + ts_uart_send_shop.buf3[3] = cguHex2Char[D_uc_low(k.BYTE2.L)][1]; + L0_uart0_sendArray(ts_uart_send_shop.buf3,4); + + } + + + /**************** + else if(2 == hex) + { + ts_uart_send_shop.buf3[0] = (k.BYTE2.H); + ts_uart_send_shop.buf3[1] = (k.BYTE2.L); + L0_uart0_sendArray(ts_uart_send_shop.buf3,2); + }else + { + ts_uart_send_shop.buf3[0] = 0x55; + ts_uart_send_shop.buf3[1] = 0x66; + L0_uart0_sendArray(ts_uart_send_shop.buf3,2); + } + + */ +} +void L2_waitFree_uart0(void) +{ + while(ts_uart_send_shop.ok != D_ready) + { + if(ts_uart_send_shop.over ++ > 600000) + { + break; + } + } +} + +void L0_uart0_sendArray(U8 *buf,U16 len) +{ + //D_485_TX(); //切换到输出状态 + + D_waitFree_uart0(); // P31 = 1; + ts_uart_send_shop.over = 0; + ts_uart_send_shop.p = buf; + ts_uart_send_shop.max = len; + ts_uart_send_shop.now = 1; + ts_uart_send_shop.ok = D_clear; + L0_uart0_set(ts_uart_send_shop.p[0]); +} + + +/************************************************* +UART 中断 +*************************************************/ +void INTERRUPT_UART(void) interrupt D_SERVE_UART// using 2 +{ + NOP(); NOP(); NOP(); + if(L0_uart0_IntRI()) //如果是U0接收中断 + { + L0_uart0_IntRIClear(); //清除接收中断标志 + //s_nos_tick.tp_count = 0; + L0_timer1_reset(); + s_uart0_rec.reg = L0_uart0_get(); + L1_s2b_PH4(&s_uart0_rec); + } + if(L0_uart0_IntTI()) //如果是U0发送中断 + { + L0_uart0_IntTIClear(); //清除发送中断标志 + if(ts_uart_send_shop.max != ts_uart_send_shop.now) + { + L0_uart0_set(ts_uart_send_shop.p[ts_uart_send_shop.now]); + ts_uart_send_shop.now ++; + } + else + { + ts_uart_send_shop.ok = D_ready; + ts_uart_send_shop.max = 0; + ts_uart_send_shop.now = 0;//可以发送下一个数据 + // P31 = 0; + //切换到接收状态 + //D_485_RX(); + } + } + else + { + //其他中断 + } + NOP(); NOP(); NOP(); +} + +#if 1 +void timer1_isrHanddle (void) interrupt D_ISR_timer1 +{// + TF1 = 0; + //s_nos_tick.uart0_free = 1; + if(s_uart0_rec.head == 1) //收到一条协议 + { + s_uart0_rec.head = 0; + P10 ^= 1; + if(s_uart0_rec.ok == 0) + { + s_uart0_rec.ok = 1; + //Lc_buf_copy_uc(); + } + } +} + +#else + +void timer1_isrHanddle (void) interrupt D_ISR_timer1 +{// + TF1 = 0; + //s_nos_tick.uart0_free = 1; + if(s_uart0_rec.head == 1) //收到一条协议 + { + s_uart0_rec.head = 0; + s_uart0_rec.ok = 1; + L3_task_uart0_modbus_handler(&s_uart0_rec); + } +} + + + +#endif + + + + diff --git a/source/msp/UART0.h b/source/msp/UART0.h new file mode 100644 index 0000000..3df7585 --- /dev/null +++ b/source/msp/UART0.h @@ -0,0 +1,152 @@ +////////////////////////////////////////////////////////////////////////// +/// 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: cc +/// Modified date: 20190222 +/// Version: +/// Descriptions: 中断的now和max调整类型 可以支持int型的数据一次发送,前提是指向已有的数组 +////////////////////////////////////////////////////////////////////////// +/***************************************************************************** +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_uart_rec_ 的公共协议包(关键的结构体)的声明------struct _s_uart_rec_ + void L1_uart_2buf(struct _s_uart_rec_ *p)串行数据保存到指向特定协议的缓冲中 +-------------------------------------------------------------------------------------------- +msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 + L0_UART0_Init + UART0_IRQHandler + L0_Usend_uc------UserDef +----------------------------------------------------------------------------------------- +********************************************************************************/ + + +#ifndef _uart0_H +#define _uart0_H +#include "../bsp/bsp_config.h" +#include "../clib/type.h" +//#include "../debug/debug_drv.h" +//#include "../uartcom/urec2protocol.h" +//?include "../uartcom/uprotocol2app.h" +#include "../tpc/tpc_modbus.h" +#define Ldi_print(x) Lc_print_buf(x) +//#include "../uartcom/UProtocol.h" +#include "../ctask/task.h" +#include "../clib/Clib.h" + + +//extern struct _s_uart_rec_ s_uart0_rec; +// extern TS_Handle_PH1 volatile s_uart0_rec; +//extern TS_Handle_PH1A volatile s_uart0_rec; +extern TS_Handle_PH4 s_uart0_rec; + + +///#define D_s_uart0_rec_close(); s_uart0_rec.ok = 2;// 关闭串口协议解析 +///#define D_s_uart0_rec_open(); s_uart0_rec.ok = 0;// 关闭串口协议解析 +#define D_uart0_free() (0 == ts_uart_send_shop.max) +#define D_uart0_busy() (0 != ts_uart_send_shop.max) + + + +//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +////fixme:和cpu的程序容量息息相关 +#define D_send_buf_max 8 /// 9600bps = 10000bps = 1000 Bps = 1Byte/ms + /// 19200bps = 20000bps = 2000Bps = 2Byte/ms = 1Byte/0.5ms + /// 128Bytes = 128*0.5ms = 64ms + +#define D_send_buf2_max 6 + +typedef struct _ts_uart0_send_buf_ +{//8byte + U8 num; //接收到的数目注意数据长度的范围 + U8 *p; + vU16 now; /// 当前buf所在的位置 0------(max-1) + vU16 max; /// 当前buf的最大值,也就是需要发送的长度 + vU16 over; /// 当前buf的最大值,也就是需要发送的长度 + U8 ok; /// 当前buf的最大值,也就是需要发送的长度 + U8 buf[D_send_buf_max]; +/// U8 buf2[D_send_buf2_max]; + U8 buf3[D_send_buf2_max]; +//// U8 buf4[D_send_buf_max]; + /// U8 buf[D_send_buf_max + 1];//buffer 的第一位是 长度 +}Ts_uart_send_buf; + + +extern volatile Ts_uart_send_buf ts_uart_send_shop; +///extern volatile Ts_uart_send_buf ts_uart_send_depot; + + +#define D_uart0_ES_INT(x) ES = (x) + + +#define L0_uart0_IntRI() (RI)//BITN_G(SCON,U0RI) +#define L0_uart0_IntTI() (TI)//BITN_G(SCON,U0TI) +#define L0_uart0_IntRIClear(); RI = 0;//BITN_0(SCON,U0RI) +#define L0_uart0_IntTIClear(); TI = 0;//BITN_0(SCON,U0TI) +#define L0_uart0_set(x) SBUF = (x); +#define L0_uart0_get() (SBUF) +//#define D_send_us(x) gRccUs01 = x;L0_uart0_uc(gRccUs01_H);L0_uart0_uc(gRccUs01_L); + +#define D_send_ushex(x) L0_uart0_ushex(x,16);///Lc_delay_ms(2);//gRccUs01 = x;L0_uart0_uchex(gRccUs01_H);L0_uart0_uchex(gRccUs01_L); +#define D_uart0_send_over() (D_ready == ts_uart_send_shop.ok) + + +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +void L1_uart0_buf_init(void); + +extern void L0_uart0_init(void); +extern void L0_uart0_init32K_290BPS(void); + +extern void L0_Uart0_Init4800(void) ; + +extern void L0_uart0_uchex(U8 ww); + +extern void L0_uart0_ulhex(vU32 ww); + +extern void L0_uart0_ul(vU32 ww); +extern void L0_uart0_sendstr(U8 *str); +extern void L0_uart0_0d0a(void); +extern void L0_uart0_uc(U8 ww); +extern void L0_uart0_uc_debug(U8 ww); +extern void L0_uart0_us(vU32 ww); +extern void L0_uart0_ushex(vU16 ww,U8 hex); +extern void L0_uart0_uldec(U32 ww); + +/////////////////////////////////////////////////////////////// +extern void L0_uart0_sendArray(U8 *buf,U16 len); +extern void L0_uart0_sendbuf(void); +///extern void L0_uart0_sendArraylong(U8 *buf,U16 usStart,U16 usEnd); + +#endif //#ifndef _uart0_H + + diff --git a/source/msp/msp_eeprom.c b/source/msp/msp_eeprom.c new file mode 100644 index 0000000..4af41b6 --- /dev/null +++ b/source/msp/msp_eeprom.c @@ -0,0 +1,170 @@ +//////////////////////////////////////////////////////////////////////////// +///@copyright Copyright (c) 2018, 传控科技 All rights reserved. +///------------------------------------------------------------------------- +/// @file msp_eeprom.c +/// @brief msp @ driver config +///------------------------------------------------------------------------- +/// @version 1.0 +/// @author CC +/// @date 20190106 +/// @note cc_AS_stc02 由stc-isp v6.0860 +////////////////////////////////////////////////////////////////////////////// +#include "msp_eeprom.h" + +#include "../tpc/tpc_uart.h" + + +#define WT_30M 0x80 +#define WT_24M 0x81 +#define WT_20M 0x82 +#define WT_12M 0x83 +#define WT_6M 0x84 +#define WT_3M 0x85 +#define WT_2M 0x86 +#define WT_1M 0x87 + + +U_F16 uf_ee_add; + + +void L0_Iap_Idle() +{ + IAP_CONTR = 0; //关闭IAP功能 + IAP_CMD = 0; //清除命令寄存器 + IAP_TRIG = 0; //清除触发寄存器 + IAP_ADDRH = 0x80; //将地址设置到非IAP区域 + IAP_ADDRL = 0; +} + +char L0_Iap_Read(vU16 addr) +{ + char dat; + + IAP_CONTR = WT_12M; //使能IAP + IAP_CMD = 1; //设置IAP读命令 + IAP_ADDRL = addr; //设置IAP低地址 + IAP_ADDRH = addr >> 8; //设置IAP高地址 + IAP_TRIG = 0x5a; //写触发命令(0x5a) + IAP_TRIG = 0xa5; //写触发命令(0xa5) + _nop_(); + dat = IAP_DATA; //读IAP数据 + L0_Iap_Idle(); //关闭IAP功能 + + return dat; +} + +void L0_Iap_Program(vU16 addr, char dat) +{ + IAP_CONTR = WT_12M; //使能IAP + IAP_CMD = 2; //设置IAP写命令 + IAP_ADDRL = addr; //设置IAP低地址 + IAP_ADDRH = addr >> 8; //设置IAP高地址 + IAP_DATA = dat; //写IAP数据 + IAP_TRIG = 0x5a; //写触发命令(0x5a) + IAP_TRIG = 0xa5; //写触发命令(0xa5) + _nop_(); + L0_Iap_Idle(); //关闭IAP功能 +} + +///每个扇区512字节 +///指定地址可以为当前扇区内的任意地址,都会完整擦除当前扇区 +void L0_Iap_Erase(vU16 addr) +{ + IAP_CONTR = WT_12M; //使能IAP + IAP_CMD = 3; //设置IAP擦除命令 + IAP_ADDRL = addr; //设置IAP低地址 + IAP_ADDRH = addr >> 8; //设置IAP高地址 + IAP_TRIG = 0x5a; //写触发命令(0x5a) + IAP_TRIG = 0xa5; //写触发命令(0xa5) + _nop_(); // + L0_Iap_Idle(); //关闭IAP功能 +} + +void L0_Iap_Program_array(vU16 addr,U8 *buf,U8 len) +{ + U8 i = 0; + for(i=0;i>8 & 0xFF); + L0_uart0_uchex(i>>0 & 0xFF); + } + } +#endif + Lc_delay_ms(100); + L0_uart0_uc('%'); + + while(1); +} +#endif + + + diff --git a/source/msp/msp_eeprom.h b/source/msp/msp_eeprom.h new file mode 100644 index 0000000..61a56e2 --- /dev/null +++ b/source/msp/msp_eeprom.h @@ -0,0 +1,47 @@ +////////////////////////////////////////////////////////////////////////// +/// COPYRIGHT NOTICE +/// Copyright (c) 2018, 传控科技 +/// All rights reserved. +/// +/// @file msp_eeprom +/// @brief msp_eeprom +/// @info +///(本文件实现的功能的详述) +/// +/// @version 1.1 CCsens technology +/// @author CC +/// @date 20190106 + +// +////////////////////////////////////////////////////////////////////////// + +#ifndef _msp_eeprom_H_ +#define _msp_eeprom_H_ + +#include "../clib/type.h" +#include "../clib/clib.h" +#include "../ctask/tick.h" + + +///>>>端口位定义,可修改!!!!!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +#include "../cpu/stc_stc8a8k.h" +#include "../cpu/c51_macro.h" +#include "../bsp/bsp_config.h" + + +#include "uart0.h" + +extern void L3_eeprom_fun(U8 *pPara); + +///每个扇区512字节 +extern void L0_Iap_Erase(vU16 addr); +extern void L0_Iap_Program(vU16 addr, char dat); +extern char L0_Iap_Read(vU16 addr); +extern void L0_Iap_Program_array(vU16 addr,U8 *buf,U8 len); +extern void L0_Iap_Read_array(vU16 addr,U8 *buf,U8 len); +extern void L1_Iap_main(void); + +#endif// #ifndef _msp_eeprom_H_ + + diff --git a/source/msp/msp_id.c b/source/msp/msp_id.c new file mode 100644 index 0000000..047030c --- /dev/null +++ b/source/msp/msp_id.c @@ -0,0 +1,49 @@ + +//////////////////////////////////////////////////////////////////////////// +///@copyright Copyright (c) 2018, 传控科技 All rights reserved. +///------------------------------------------------------------------------- +/// @file msp_eeprom.c +/// @brief msp @ driver config +///------------------------------------------------------------------------- +/// @version 1.0 +/// @author CC +/// @date 20190106 +/// @note cc_AS_stc02 由stc-isp v6.0860 +////////////////////////////////////////////////////////////////////////////// +#include "msp_id.h" +#include "../app/common.h" + +void L0_id_get(U8 *id) +{ + U8 i = 0; + char *ID = (char idata *)0xf1; + for(i=0;i>>端口位定义,可修改!!!!!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +#include "../cpu/stc_stc8a8k.h" +#include "../cpu/c51_macro.h" +#include "../bsp/bsp_config.h" +#include "uart0.h" + +extern void L0_id_get(U8 *id); +extern void L0_id_get_rom(U8 *id); +extern void L0_id_main(void); + +#endif// #ifndef _msp_eeprom_H_ + + + diff --git a/source/msp/time.c b/source/msp/time.c new file mode 100644 index 0000000..e34f228 --- /dev/null +++ b/source/msp/time.c @@ -0,0 +1,255 @@ +#include "Time.h" + +/*************初始化定时器0由 stc-isp v6.86L定时器计算器生成******************/ +#if(MainFre_5M == D_sys_MainFre) +#elif(MainFre_27M == D_sys_MainFre) +#elif(MainFre_22M == D_sys_MainFre) +void L0_timer0_Init(void) //25毫秒@22.1184MHz +{ + AUXR &= 0x7F; //定时器时钟12T模式 + TMOD &= 0xF0; //设置定时器模式 + TL0 = 0x00; //设置定时初值 + TH0 = 0x4C; //设置定时初值 + TF0 = 0; //清除TF0标志 + TR0 = 1; //定时器0开始计时 + ET0 = 1; //add by cc +} + + +/******************************************** +void L0_timer0_Init(void) //10毫秒@22.1184MHz +{ + AUXR &= 0x7F; //定时器时钟12T模式 + TMOD &= 0xF0; //设置定时器模式 + TL0 = 0x00; //设置定时初值 + TH0 = 0xB8; //设置定时初值 + TF0 = 0; //清除TF0标志 + TR0 = 1; //定时器0开始计时 + ET0 = 1; //add by cc +} + +void L0_timer0_Init_32k(void) //4fen@32kHz +{ + AUXR &= 0x7F; //定时器时钟12T模式 + TMOD &= 0xF0; //设置定时器模式 + #if 0 + TL0 = 0x00; //设置定时初值 + TH0 = 0xB8; //设置定时初值/// 4m20s 71 + #else + TL0 = 0x00; //设置定时初值 + TH0 = 0xcc; //设置定时初值// ff 4s + + + #endif + TF0 = 0; //清除TF0标志 + TR0 = 1; //定时器0开始计时 + ET0 = 1; //add by cc + BITN_0(DR_who_wakeup, DRB_who_wakeup_timer0); /// 标志中断类型: 定时器 +} +****************************************************/ + +#else ///MainFre_11M +void L0_timer0_Init(void) //10毫秒@11.0592MHz +{ + AUXR &= 0x7F; //定时器时钟12T模式 + TMOD &= 0xF0; //设置定时器模式 + TL0 = 0x00; //设置定时初值 + TH0 = 0xDC; //设置定时初值 + TF0 = 0; //清除TF0标志 + TR0 = 1; //定时器0开始计时 + ET0 = 1; //add by cc +} + +/******************************************** +void L0_timer0_Init(void) //25毫秒@11.0592MHz +{ + AUXR &= 0x7F; //定时器时钟12T模式 + TMOD &= 0xF0; //设置定时器模式 + TL0 = 0x00; //设置定时初值 + TH0 = 0xA6; //设置定时初值 + TF0 = 0; //清除TF0标志 + TR0 = 1; //定时器0开始计时 + ET0 = 1; //add by cc +} +****************************************************/ +#endif//D_sys_MainFre) + +//10---87 10s +/********************** Timer0中断函数************************/ +/// 和 L0_timer0_Init 关联,需要配置 bsp_config.h中的 D_sys_MainFre +/// 默认10ms 作为TTSS系统的定时引擎 +void timer0_isrHanddle (void) interrupt D_ISR_timer0 +{// + NOP(); NOP(); NOP(); + TF0 = 0; +#if 0 + /// 65535*65535 /3600/24/365=139nian/s=1.39nian/10ms + ///相当于1.39年后t_10ms 溢出,对于电池供电的系统而言 完全可以满足 + // 4,294,836,225 = 65535*65535 ;3600*24*60*60 = 31,536,000秒/年 + s_nos_tick.t_10ms ++;//D_led_D1_REV(); 20160522 验证 + +#else + + L1_tick_tick(); ///系统中的1sflag 和以10ms为颗粒的延时使用 为tdelay服务 + +#endif + /// BITN_1(DR_who_wakeup, DRB_who_wakeup_timer0); + NOP(); NOP(); NOP(); +} + + + + + + + + + +#if(MainFre_5M == D_sys_MainFre) +#elif(MainFre_27M == D_sys_MainFre) +#elif(MainFre_22M == D_sys_MainFre) +/****************************** +void L0_Timer1_Init(void) //35毫秒@22.1184MHz +{///自动重载 + AUXR &= 0xFB; //定时器时钟12T模式 + T2L = 0x00; //设置定时初值 + T2H = 0x04; //设置定时初值 + AUXR |= 0x10; //定时器2开始计时 + + BITN_1(IE2, ET2);// IE2 = ET2; //使能定时器中断 +} +**********************************/ +#else ///MainFre_11M + +void L0_timer1_Init_7ms(void) //7毫秒@11.0592MHz +{ + AUXR &= 0xBF; //定时器时钟12T模式 + TMOD &= 0x0F; //设置定时器模式 + TL1 = 0xCD; //设置定时初值 + TH1 = 0xE6; //设置定时初值 + TF1 = 0; //清除TF1标志 + TR1 = 1; //定时器1开始计时 + ET1 = 1; //add by cc +} + +void L0_timer1_Init_5ms(void) //5毫秒@11.0592MHz +{//0x7F示波器测试大约40ms,led闪烁 肉眼可见 + AUXR &= 0xBF; //定时器时钟12T模式 + TMOD &= 0x0F; //设置定时器模式 + TL1 = 0x00; //设置定时初值 + TH1 = 0xEE; //设置定时初值 + TF1 = 0; //清除TF1标志 + TR1 = 1; //定时器1开始计时 + ET1 = 1; //add by cc +} + +void L0_timer1_Init_1ms(void) //1毫秒@11.0592MHz +{ + AUXR |= 0x40; //定时器时钟1T模式 + TMOD &= 0x0F; //设置定时器模式 + TL1 = 0xCD; //设置定时初值 + TH1 = 0xD4; //设置定时初值 + TF1 = 0; //清除TF1标志 + TR1 = 1; //定时器1开始计时 + ET1 = 1; //add by cc +} + +void L0_timer1_Init(void) //600微秒@11.0592MHz +{ + AUXR |= 0x40; //定时器时钟1T模式 + TMOD &= 0x0F; //设置定时器模式 + TL1 = 0x14; //设置定时初值 + TH1 = 0xE6; //设置定时初值 + TF1 = 0; //清除TF1标志 + TR1 = 1; //定时器1开始计时 + ET1 = 1; //add by cc +} + + +//0x7F示波器测试大约40ms,led闪烁 肉眼可见 +void L0_timer1_reset(void) +{ + TR1 = 0; + TL1 = 0x14; //设置定时初值 + TH1 = 0xE6; //设置定时初值 + TR1 = 1; + TF1 = 0; +} + +#endif//D_sys_MainFre) + + +#if 0 +void L0_Timer1Init(void) +{ + #if 0 + + //30毫秒@22.1184MHz + AUXR &= 0xBF; //定时器时钟12T模式 + TMOD &= 0x0F; //设置定时器模式 + TMOD |= 0x10; //设置定时器模式 + TL1 = 0x00; //设置定时初值 + TH1 = 0x28; //设置定时初值 + TF1 = 0; //清除TF1标志 +#else + TMOD = 0x40; //外部计数模式 + TL1 = (0xff-10); + TH1 = 0xff; + + + #endif +// TR1 = 1; //定时器1开始计时 + L0_TIMER1_start(); + //L0_TIMER1_end(); + L0_TIMER1_isr_CLOSE(); +/// ET1 = 1; // add by cc 启动定时器1的中断 +} + +void L0_timer1_Init(void) //计数器1初始化 +{ + + TMOD = 0x40; //外部计数模式 + TL1 = 0x9c; + TH1 = 0xff; + // TR1 = 1; //启动定时器 + ET1 = 1; //使能定时器中断 + // EA = 1; +} +#define L0_timer1_on(); TR1 = 1; //启动计数器 +#define L0_timer1_off(); TR1 = 0; //关闭计数器 //启动计数器 + +//10---87 10s +/********************** Timer0中断函数************************/ +/// 和 L0_timer0_Init 关联,需要配置 bsp_config.h中的 D_sys_MainFre +/// 默认10ms 作为TTSS系统的定时引擎 +void timer1_inr (void) interrupt 3 +{ + +/******* + s_task_GC032A.usN ++; + s_task_GC032A.buf[s_task_GC032A.usN] = P1; + if(s_task_GC032A.usN < D_row_max) + { + + }else + { + s_task_GC032A.status = 1; + } +// task_handler.line_camera++; +****************/ +} + +#endif + + + + + + + + +/******************************END*********************************/ + + + + diff --git a/source/msp/time.h b/source/msp/time.h new file mode 100644 index 0000000..1f49191 --- /dev/null +++ b/source/msp/time.h @@ -0,0 +1,55 @@ +#ifndef INIT_TIMER0_H +#define INIT_TIMER0_H + +#include "../clib/type.h" + +#include "../bsp/bsp_config.h" +#include "../ctask/tick.h" + + +extern void L0_timer1_Init(void); +extern void L0_timer1_reset(void); +extern void L0_timer1_off(void); +extern void L0_timer1_on(void); +extern void L0_Timer1Init(void); +extern void L0_timer0_Init(void); +extern void L0_timer0_Init_32k(void) ; +#define L0_timer0_open(x) TR0 = x // + +// 他和t_10ms 关联,如果t_10ms递增为1时间隔为(D_TIMER0_10MS_COUNT*定时器间隔) +//#define D_TIMER0_10MS_COUNT 1 //定时器为 10ms一中断 + +#define D_TIMER0_10MS_COUNT 1 //定时器为 10ms一中断 + +/**************** + +#if(MainFre_5M == D_sys_MainFre) + +#define D_Cdelay_200us 20 +#define D_Cdelay_1us 1 ////while p21翻转时测定 500k 2us 一个指令 +#elif(MainFre_22M == D_sys_MainFre) + +#define L0_delay_1us() Lc_delay_nop(2) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us +#define L0_delay_10us() Lc_delay_nop(20) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us + +#define D_Cdelay_1ms 500 +#define D_Cdelay_15ms 1200 + + +#define D_Cdelay_200us 20 +#define D_Cdelay_1us 1 + +#elif(MainFre_11M == D_sys_MainFre) +等待 +#define L0_delay_1us() NOP();NOP(); // 11.05926M + + +#endif +**********/ + + + +#endif + + + diff --git a/source/tpc/tpc_modbus.c b/source/tpc/tpc_modbus.c new file mode 100644 index 0000000..54b7561 --- /dev/null +++ b/source/tpc/tpc_modbus.c @@ -0,0 +1,77 @@ + +/***************************************************************************** +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_modbus.h" + +void L1_s2b_PH4_init(TS_Handle_PH4 *p,U8 slaver) +{ + p->max = 0; + p->ok = 0; + p->head = 0; + p->num = 0; + p->slaver = slaver; + p->error = 0; +} + +void L1_s2b_PH4(TS_Handle_PH4 *p) +{ + if(p->head == 0) + { + if(p->reg == p->slaver) + { + p->head = 1; + p->error = 0; + p->max = D_s_PH4_modbus_max; + p->sp = p->buf; + p->num = 0; + p->sp[p->num++] = p->reg; + } + } + else + { + if(p->num < p->max) + { + p->sp[p->num++] = p->reg; + } + else + { + //P10 ^= 1; + p->error = 1; + } + } +} + + + +/****************************************************************************** +** End Of File +******************************************************************************/ + diff --git a/source/tpc/tpc_modbus.h b/source/tpc/tpc_modbus.h new file mode 100644 index 0000000..37605e9 --- /dev/null +++ b/source/tpc/tpc_modbus.h @@ -0,0 +1,57 @@ +////////////////////////////////////////////////////////////////////////// +/// COPYRIGHT NOTICE +/// Copyright (c) 2018, 传控科技 +/// All rights reserved. +/// +/// @file tpc_fsk.c +/// @brief transaction protocol control of fsk +/// +///(本文件实现的功能的详述) +/// +/// @version 1.1 CCsens technology +/// @author CC +/// @date 20150102 +/// +/// +/// @version 1.2 CCsens technology +/// @author CC +/// @date 20180308 +/// @info 整理 + +// +////////////////////////////////////////////////////////////////////////// + + +#ifndef __TPC_MODBUS_H_ +#define __TPC_MODBUS_H_ + +#include "../clib/Type.h" +#include "../bsp/bsp_config.h" +#include "../app/common.h" + +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +typedef struct +{ + U8 reg; + U8 max; //接收到的数目的最大值 + U8 slaver; + vU8 head; //接收标志头标志 + vU8 ok; //接收协议ok标志 + vU8 num; + vU8 error; //错误 + vU8 *sp; + U8 buf[D_s_PH4_modbus_max + 8]; + vU8 crc[2]; +}TS_Handle_PH4; + +extern void L1_s2b_PH4_init(TS_Handle_PH4 *p,U8 slaver); +extern void L1_s2b_PH4(TS_Handle_PH4 *p); + +#endif /* end __TPC_UART_H_ */ +/***************************************************************************** +** End Of File +******************************************************************************/ + + + diff --git a/source/tpc/tpc_uart.c b/source/tpc/tpc_uart.c new file mode 100644 index 0000000..52af7b7 --- /dev/null +++ b/source/tpc/tpc_uart.c @@ -0,0 +1,192 @@ + +/***************************************************************************** +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 +******************************************************************************/ + diff --git a/source/tpc/tpc_uart.h b/source/tpc/tpc_uart.h new file mode 100644 index 0000000..cddf610 --- /dev/null +++ b/source/tpc/tpc_uart.h @@ -0,0 +1,409 @@ +////////////////////////////////////////////////////////////////////////// +/// COPYRIGHT NOTICE +/// Copyright (c) 2018, 传控科技 +/// All rights reserved. +/// +/// @file tpc_fsk.c +/// @brief transaction protocol control of fsk +/// +///(本文件实现的功能的详述) +/// +/// @version 1.1 CCsens technology +/// @author CC +/// @date 20150102 +/// +/// +/// @version 1.2 CCsens technology +/// @author CC +/// @date 20180308 +/// @info 整理 + +// +////////////////////////////////////////////////////////////////////////// + + +/***************************************************************************** +@version 1.2 +update by cc @201501101001 +针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是 +个需要平衡的事情. + +clib/uartlib.c: +公用的函数 和硬件无关 +接收各类协议的处理函数 +放置串行模式(串口等其他通讯总线类的输出)输出的函数, +一些覆盖模式输出的(lcd等固屏输出的)的也可使用 + void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...) +----------------------------------------------------------------------------------------- + + +----------------------------------------------------------------------------------------- + + +-------------------------------------------------------------------------------------------- +msp/uartx.c 底层代码 和cpu相关 + L0_UART0_Init + UART0_IRQHandler + L0_Usend_uc----------s_at0 +----------------------------------------------------------------------------------------- +********************************************************************************/ + + + +#ifndef __TPC_UART_H_ +#define __TPC_UART_H_ + +#include "../clib/Type.h" +#include "../bsp/bsp_config.h" + + +// 20170609 + +///----------------------------------------------------- + + + +//L0_type_byte(ts_cmd_pro0)[] +//#define D_CMD_Filter1 0xA5 +//#define D_CMD_Filter2 0x5A +#define D_CMD_Filter1 0x0a +#define D_CMD_Filter2 0x0d + +#define D_CMD_Filter1_ff 0xFF +#define D_CMD_Filter2_fe 0xFE + + + +///协议类型: 十六进制协议1->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +/// 发送的数据为有fx开头的十六进制的短协议,和长协议的区别除了帧头简化为1个字节外,数据的长度也是比较精简,大部分按位操作的,适合低波特率rf433之类的传播 +///定长5个 适合于传感器定时上传 +/// R1 +///位数 7 6 5 4 3 2 1 0 +///定义 动作传感器AS1 (0---15) 动作传感器AS2 (0---15) + +/// R2 +///位数 7 6 5 4 3 2 1 0 +///定义 气压Press (0---15) open mic + +/// R3 +///位数 7 6 5 4 3 2 1 0 +///定义 Temp (0---15) Gsensor(0---15) + +typedef struct +{//8byte +///////// + vU8 as2:4; + vU8 as1:4; +///////// + vU8 mic:3; + vU8 open:1; + vU8 press:4; +//////////////// + vU8 Gsensor:4; + vU8 temp:4; +/////////// +}TS_P_pc_dat; + +typedef struct +{//8byte + ///////// + U8 cameraBoardPower; //当前行第4个点采集的图像数据 + vU16 paperNum:10; //10bit纸张数据 表示最大量程1024 实际170张 + vU16 cameraIndex:4; //摄像头编号 + vU16 cameraWorking:1; //是否正常工作 + vU16 LowPower:1; // =1 lowPower 提醒需要充电,或者未连接电池 +}TS_P_paper; + +//NUM: 0 1 2 3 4 +// Fx R1 R2 R3 ocr +// F+从机 R1 R2 R3 校验 +typedef struct _s_P_rf_ +{//8byte + vU8 slave:4; + vU8 filter1:4; +//////////////// + TS_P_paper r123; + vU8 ocr; +}TS_P_rf; + +typedef struct _s_P_rf433_ +{//8byte + vU8 ha; +// vU8 hb; + + vU8 slave:4; + vU8 filter1:4; +//////////////// + TS_P_paper r123; + vU8 ocr; +/// vU8 hc; +}TS_P_rf433; + +//NUM: 0 1 2 3 4 +// Fx R1 R2 R3 ocr +// F+从机 R1 R2 R3 校验 + +typedef struct +{//8byte + vU8 slave:4; + vU8 filter1:4; +//////////////// + vU8 G1; +//////////////// + vU8 G2; +//////////////// + vU8 Tmp:4; + vU8 Press:4; +//////////////// + vU8 ocr; +}TS_P_as; + +typedef struct +{//8byte + vU8 slave:4; + vU8 filter1:4; +//////////////// + vU8 cmd; +//////////////// + vU8 R2; +//////////////// + vU8 R3; +//////////////// + vU8 ocr; +}TS_P_debug; + + +#define D_HETU_FX_fi 0xa0 ///2018.7.7 +#define D_HETU_FX_H4 0xf0 ///2018.7.7 + +#define D_HETU_FX_buf_max 4 //max 是是指实际的数量,num或者cnt是指当时的 +/// Hex RTU Protocol 0xFx +typedef struct +{//8byte + vU8 reg; + vU8 n; + vU8 head; //接收标志头标志 + vU8 ok; //接收协议ok标志 + vU8 num; +// vU8 cmd; + vU8 ocr; +// vU8 *sp; + U8 buf[D_HETU_FX_buf_max+1]; +}TS_Handle_PH1; + + +extern void L1_s2b_PH1 (TS_Handle_PH1 *p);// reentrant; + +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +///协议类型: 十六进制协议2->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +/// 发送的数据为有ff fe开头的十六进制的长协议,内有数据数量 +///FF FE 52 03 98 77 88 99 地址为0x52的从机, 向PC发送了3个数据0x77,0x88,0x99 + +///FF FE 06 03 e5 77 88 99 命令(0x06)携带了3个数据0x77,0x88,0x99;校验为0x98(=0x06+0x03+0x77+0x88+0x99三个数据的和) +///附:校验位=0x12+0x34+0x56=0x9c;取低位字节得到OCR=0x9c + +typedef struct +{//8byte + vU8 filter1; + vU8 filter2; + vU8 addr; //发送方的地址或命令 + vU8 num; //接收到的数据的计数, 随着数据接收而变化注意数据长度的范围 + vU8 ocr; + vU8 buf[4];//--->_s_P_pc_dat_ +}TS_P_pc; + +// FF FE 10 02 0C 51 03 +// cashe[1] cashe[0] 本机 数量 校验 数据1 从机 数据2 命令 +// filter2 filter1 +struct _s_PH2_FFFE_ +{//8byte + vU8 cashe[2]; + vU8 reg; + vU8 max; //接收到的数目的最大值 + vU8 head_0; + vU8 head_1; + // vU8 sub_num; //接收到的数目注意数据长度的范围 + vU8 head; //接收标志头标志 + vU8 ok; //接收协议ok标志 + vU8 num; + vU8 *sp; + TS_P_pc s_FF; + // U8 pro[16]; ///解析协议用 +}; + +extern void L1_s2b_PH2(struct _s_PH2_FFFE_ *p);// reentrant; + + +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +///协议类型: 十六进制协议3->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +/// 发送的数据为有ff fe开头的十六进制的长协议,内包含标准的modbus协议 +///FF FE 08 52 16 11 22 33 44 F5 9F 发送了一个modbus协议包(8个数据52 16 11 22 33 44 F5 9F ) +/// 协议表达的意思为地址为0x52的从机, 功能码16 数据为11 22 33 44,校验码 F5 9F +/// 校验码的范围为 +#define TS_PH3_FILTER0 0xFF +#define TS_PH3_FILTER1 0xFE + +#define D_s_PH3_ccmodbus_max (16 + 8) +typedef struct +{ + U8 filter0; + U8 filter1; + U8 num; + U8 src; //源设备ID + U8 dst; //目标设备ID + U8 oper; + U8 buf[D_s_PH3_ccmodbus_max - 8]; + U8 crc[2]; +}TS_PH3_ccmodbus; + +typedef struct +{//8byte + U8 cashe[2]; + U8 reg; + U8 max; //接收到的数目的最大值 + U8 head_0; + U8 head_1; + // vU8 sub_num; //接收到的数目注意数据长度的范围 + vU8 head; //接收标志头标志 + vU8 ok; //接收协议ok标志 + vU8 num; + vU8 *sp; + U8 _buf[D_s_PH3_ccmodbus_max]; ///解析协议用 + U8 buf[D_s_PH3_ccmodbus_max]; +}TS_Handle_PH3; + +extern void L1_s2b_PH3_init(TS_Handle_PH3 *p); +extern void L1_s2b_PH3(TS_Handle_PH3 *p);// reentrant; +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +///协议类型: 字符型协议1->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +/// 发送的数据为以回车换行(即0x0a 0x0d)为结尾的字符型长协议,内有意义比较明确的命令字符和对应的数据,适合debug和速率要求不高,数据量 +/// 不大的场合 + +///----------------------------------------------------------------------------------------- +#define D_s_SSTR_0D0A_len 16 //str类的协议需要长度大一些,容易bug的地方,限制为接收64bytes的数据 +struct _s_PC1_0D0A_ +{//8byte + vU8 reg; + // vU8 sub_num; //接收到的数目注意数据长度的范围 + vU8 head; //接收标志头标志 + + vU8 cashe[2]; + //vU8 filter1; + //vU8 filter2; + vU8 num; //接收到的数据的计数, 随着数据接收而变化注意数据长度的范围 + + vU8 ok; //接收协议ok标志 + vU8 max; //接收到的数目的最大值 + vU8 buf[D_s_SSTR_0D0A_len+1];//buffer 的第一位是 长度 + // U8 pro[16]; ///解析协议用 +}; +extern void L1_s2b_PC1(struct _s_PC1_0D0A_ *p);// reentrant; +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + + + + +///modebus协议通讯使用>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +#ifdef doc_98098908 +///Modbus网络上以RTU模式通信,在消息中的每个8Bit字节按照原值传送,不做处理,如63H,RTU将直接发送01100011。 +////这种方式的主要优点是:数据帧传送之间没有间隔,相同波特率下传输数据的密度要比ASCII高,传输速度更快 [1] 。 +////ASCII模式使用的字符虽是RTU模式的两倍,但ASCII数据的译码和处理更为容易一些,此外,用RTU模式时报文字符必须以连续数据流的形式传送, +///用ASCII模式,字符之间可产生长达1s的间隔,以适应速度较慢的机器 +///01 16 1000 1234 ABCD +///这段代码的意思 是 向 地址 01 的 控制器 写入 1000 1234 。 就是这么简单 +////地址域 就是指 从站的地址,比如一个变频器,或者是一个仪表,这个地址就是它的通讯地址 +///功能码 就是你要做的事情,通讯的目的 就是读写数据,所以 MODBUS 功能码虽然很多,但是只有两个是我们常用的,就是读和写。 +///读的功能码是03 写的功能码是16,注意,这里的读写都是一次性写16个位,也就是一个WORD. +///Address Function Data Check +///8-Bits 8-Bits N x 8-Bits 16-Bits +/// 功能(Function)域 +/// 功能域代码告诉了被寻址到的终端执行何种功能。下表列出了该系列仪表用到的功能码,以及它们的意义和功能。 +/// 代码 意义 行为 +/// 03 读数据寄存器 获得一个或多个寄存器的当前二进制值 +/// 16 预置多寄存器 设定二进制值到一系列多寄存器中(不对ACRXXXE开放) + + +///离散量、开关量、数字量都是对同一类型信号的不同说法, +///0表示断开,1表示接通,在PLC和类似控制设备中,都是一种布尔型的变量? +///T谧远///像PLC中的Y/Q,均是这种类型的信号 + + + + +///cc改进版的modebus协议,添加了一个帧头 +/// ff fe num add function dat check +#endif + + +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + + + + +///协议通讯使用>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +#define D_s_protocol_len 32 +struct _s_protocol_ +{//8byte + vU8 rbr; + vU8 reg; + vU8 cashe[3]; + vU8 filter1; + vU8 filter2; + vU8 (*pfun_get)(void); + vU8 num; //接收到的数目注意数据长度的范围 + vU8 sub_num; //接收到的数目注意数据长度的范围 + vU8 head; //接收标志头标志 + vU8 ok; //接收协议ok标志 + vU8 data_ok; //接收协议ok标志 + vU8 ucXor; + vU8 array[D_s_protocol_len];//buffer 的第一位是 长度 + vU8 buf[D_s_protocol_len];//buffer 的第一位是 长度 + vU8 buf2[12];//buffer 的第一位是 长度 +}; + +extern void L1_uart_2buf(struct _s_protocol_ *p); + + + +//485 +///协议类型: 十六进制协议2 带地址判定的 第二个是地址->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +#define D_HETU_FXA 0xaa + +#define D_HETU_FXA_buf_max 8 //max 是是指实际的数量,num或者cnt是指当时的 +/// Hex RTU Protocol 0xFx +typedef struct +{//8byte + vU8 reg; + vU8 n; + vU8 head; //接收标志头标志 + vU8 ok; //接收协议ok标志 + vU8 num; + vU8 add; ///数据地址 + vU8 ocr; +// vU8 *sp; + U8 buf[D_HETU_FXA_buf_max + 1]; +}TS_Handle_PH1A; + +typedef struct +{ + vU8 filter; + vU8 src; + vU8 dst; + vU8 dat[4]; + vU8 ocr; +}TS_PH1A_DAT; + +extern void L1_s2b_PH1A (TS_Handle_PH1A *p); + + +#endif /* end __TPC_UART_H_ */ +/***************************************************************************** +** End Of File +******************************************************************************/ + + +