123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #include "global.h"
- void OutputPinConfig(void);
- void InputPinConfig(void);
- byte_bits_t io_inputs_M_old[(INPUT_NUMBER + 7) >> 3];
- //IO输入配置
- void InputPinConfig(void)
- {
- unsigned short ch;
- memcpy(io_inputs_M_old,&middle_coils[(384 + 7) >> 3],(INPUT_NUMBER+7)>>3);
- for(ch=0; ch<INPUT_CONFIG_NUMBER;ch++)
- {
- //配置点位在范围内
- if(user_datas[START_ADDR_INPUT+ch] < INPUT_NUMBER)
- {
- if(io_inputs[user_datas[START_ADDR_INPUT+ch]/8].value & (1<<user_datas[START_ADDR_INPUT+ch]%8))
- {
- middle_coils[START_ADDR_INPUT/8 + ch/8].value |= (1<<(ch%8));
- }
- else
- {
- middle_coils[START_ADDR_INPUT/8 + ch/8].value &= ~(1<<(ch%8));
- }
- }
- else
- {
- middle_coils[START_ADDR_INPUT/8 + ch/8].value &= ~(1<<(ch%8));
- }
- }
- }
- //IO输出配置
- void OutputPinConfig(void)
- {
- unsigned short ch;
- int ch_num = START_ADDR_OUTPUT + OUTPUT_CONFIG_NUMBER;
- memset(&io_outputs[0].value,0,(OUTPUT_NUMBER+7)>>3);
- for(ch=START_ADDR_OUTPUT; ch<ch_num;ch++)
- {
- //配置点位在范围内
- if(user_datas[ch] < OUTPUT_NUMBER)
- {
- if((middle_coils[ch/8].value) & (1<<(ch%8)))
- {
- io_outputs[user_datas[ch]/8].value |= (1<<(user_datas[ch]%8));
- }
- }
- }
- }
- //输入IO默认配置
- void IOPinDefualtConf_INOUT(void)
- {
- unsigned short ch;
- for(ch=0; ch < INPUT_NUMBER;ch++)
- {
- if(user_datas[START_ADDR_INPUT+ch] != 0)
- break;
- }
-
- if(!DEFAULT_IN || (ch == INPUT_NUMBER))
- {
- DEFAULT_IN = 1;
- for(ch = 0; ch < INPUT_NUMBER;ch++)
- {
- user_datas[START_ADDR_INPUT+ch] = ch;
- }
- for(ch = INPUT_NUMBER; ch < INPUT_CONFIG_NUMBER;ch++)
- {
- user_datas[START_ADDR_INPUT+ch] = 30;//超过实际IO点数的变量暂时配置到无效点位
- }
- }
- // X36=0;//默认低电平的输入点位配置位
- // X37=1;//默认高电平的输入点位配置位
- }
- //输出IO默认配置
- void IOPinDefualtConf_OUTOUT(void)
- {
- unsigned short ch;
-
- for(ch=0; ch<OUTPUT_NUMBER;ch++)
- {
- if(user_datas[START_ADDR_OUTPUT+ch] != 0)
- break;
- }
- if(!DEFAULT_OUT || (ch == OUTPUT_NUMBER))
- {
- DEFAULT_OUT = 1;
- for(ch=0; ch<OUTPUT_NUMBER;ch++)
- {
- user_datas[START_ADDR_OUTPUT+ch] = ch;
- }
- for(ch=OUTPUT_NUMBER; ch<OUTPUT_CONFIG_NUMBER;ch++)
- {
- user_datas[START_ADDR_OUTPUT+ch] = OUTPUT_NUMBER;
- }
- }
- }
- //IO管脚配置
- void IOPinConfigure(void)
- {
- IOPinDefualtConf_OUTOUT();
- IOPinDefualtConf_INOUT();
- InputPinConfig();
- OutputPinConfig();
-
-
- }
|