IOPinConfig.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "global.h"
  2. void OutputPinConfig(void);
  3. void InputPinConfig(void);
  4. byte_bits_t io_inputs_M_old[(INPUT_NUMBER + 7) >> 3];
  5. //IO输入配置
  6. void InputPinConfig(void)
  7. {
  8. unsigned short ch;
  9. memcpy(io_inputs_M_old,&middle_coils[(384 + 7) >> 3],(INPUT_NUMBER+7)>>3);
  10. for(ch=0; ch<INPUT_CONFIG_NUMBER;ch++)
  11. {
  12. //配置点位在范围内
  13. if(user_datas[START_ADDR_INPUT+ch] < INPUT_NUMBER)
  14. {
  15. if(io_inputs[user_datas[START_ADDR_INPUT+ch]/8].value & (1<<user_datas[START_ADDR_INPUT+ch]%8))
  16. {
  17. middle_coils[START_ADDR_INPUT/8 + ch/8].value |= (1<<(ch%8));
  18. }
  19. else
  20. {
  21. middle_coils[START_ADDR_INPUT/8 + ch/8].value &= ~(1<<(ch%8));
  22. }
  23. }
  24. else
  25. {
  26. middle_coils[START_ADDR_INPUT/8 + ch/8].value &= ~(1<<(ch%8));
  27. }
  28. }
  29. }
  30. //IO输出配置
  31. void OutputPinConfig(void)
  32. {
  33. unsigned short ch;
  34. int ch_num = START_ADDR_OUTPUT + OUTPUT_CONFIG_NUMBER;
  35. memset(&io_outputs[0].value,0,(OUTPUT_NUMBER+7)>>3);
  36. for(ch=START_ADDR_OUTPUT; ch<ch_num;ch++)
  37. {
  38. //配置点位在范围内
  39. if(user_datas[ch] < OUTPUT_NUMBER)
  40. {
  41. if((middle_coils[ch/8].value) & (1<<(ch%8)))
  42. {
  43. io_outputs[user_datas[ch]/8].value |= (1<<(user_datas[ch]%8));
  44. }
  45. }
  46. }
  47. }
  48. //输入IO默认配置
  49. void IOPinDefualtConf_INOUT(void)
  50. {
  51. unsigned short ch;
  52. for(ch=0; ch < INPUT_NUMBER;ch++)
  53. {
  54. if(user_datas[START_ADDR_INPUT+ch] != 0)
  55. break;
  56. }
  57. if(!DEFAULT_IN || (ch == INPUT_NUMBER))
  58. {
  59. DEFAULT_IN = 1;
  60. for(ch = 0; ch < INPUT_NUMBER;ch++)
  61. {
  62. user_datas[START_ADDR_INPUT+ch] = ch;
  63. }
  64. for(ch = INPUT_NUMBER; ch < INPUT_CONFIG_NUMBER;ch++)
  65. {
  66. user_datas[START_ADDR_INPUT+ch] = 30;//超过实际IO点数的变量暂时配置到无效点位
  67. }
  68. }
  69. // X36=0;//默认低电平的输入点位配置位
  70. // X37=1;//默认高电平的输入点位配置位
  71. }
  72. //输出IO默认配置
  73. void IOPinDefualtConf_OUTOUT(void)
  74. {
  75. unsigned short ch;
  76. for(ch=0; ch<OUTPUT_NUMBER;ch++)
  77. {
  78. if(user_datas[START_ADDR_OUTPUT+ch] != 0)
  79. break;
  80. }
  81. if(!DEFAULT_OUT || (ch == OUTPUT_NUMBER))
  82. {
  83. DEFAULT_OUT = 1;
  84. for(ch=0; ch<OUTPUT_NUMBER;ch++)
  85. {
  86. user_datas[START_ADDR_OUTPUT+ch] = ch;
  87. }
  88. for(ch=OUTPUT_NUMBER; ch<OUTPUT_CONFIG_NUMBER;ch++)
  89. {
  90. user_datas[START_ADDR_OUTPUT+ch] = OUTPUT_NUMBER;
  91. }
  92. }
  93. }
  94. //IO管脚配置
  95. void IOPinConfigure(void)
  96. {
  97. IOPinDefualtConf_OUTOUT();
  98. IOPinDefualtConf_INOUT();
  99. InputPinConfig();
  100. OutputPinConfig();
  101. }