IOPinConfig.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "global.h"
  2. void OutputPinConfig(void);
  3. void InputPinConfig(void);
  4. byte_bits_t io_inputs_M_old[(INPUT_BITS_NUMBER + 7) >> 3];
  5. //IO输入配置
  6. void InputPinConfig(void)
  7. {
  8. unsigned short ch;
  9. int ch_num = START_ADDR_INPUT + INPUT_BITS_NUMBER;
  10. memcpy(io_inputs_M_old,&middle_coils[(START_ADDR_INPUT + 7) >> 3], ((INPUT_BITS_NUMBER + 7) >> 3));
  11. for(ch=START_ADDR_INPUT; ch<ch_num;ch++)
  12. {
  13. if(io_inputs[user_datas[ch]/8].value & (1<<user_datas[ch]%8))
  14. {
  15. middle_coils[ch/8].value |= (1<<(ch%8));
  16. }
  17. else
  18. {
  19. middle_coils[ch/8].value &= ~(1<<(ch%8));
  20. }
  21. }
  22. }
  23. //IO输出配置
  24. void OutputPinConfig(void)
  25. {
  26. unsigned short ch;
  27. int ch_num = START_ADDR_OUTPUT + OUTPUT_BITS_NUMBER;
  28. memset(&io_outputs[0].value,0,(OUTPUT_BITS_NUMBER+7)>>3);
  29. for(ch=START_ADDR_OUTPUT; ch<ch_num;ch++)
  30. {
  31. if((middle_coils[ch/8].value) & (1<<(ch%8)))
  32. {
  33. io_outputs[user_datas[ch]/8].value |= (1<<(user_datas[ch]%8));
  34. }
  35. }
  36. }
  37. //输入IO默认配置
  38. void IOPinDefualtConf_INOUT(void)
  39. {
  40. unsigned short ch;
  41. for(ch=0; ch < INPUT_BITS_NUMBER;ch++)
  42. {
  43. if(user_datas[START_ADDR_INPUT+ch] != 0)
  44. break;
  45. }
  46. if(!DEFAULT_IN || (ch == INPUT_BITS_NUMBER))
  47. {
  48. DEFAULT_IN = 1;
  49. for(ch = 0; ch < INPUT_BITS_NUMBER;ch++)
  50. {
  51. user_datas[START_ADDR_INPUT+ch] = ch;
  52. }
  53. }
  54. }
  55. //输出IO默认配置
  56. void IOPinDefualtConf_OUTOUT(void)
  57. {
  58. unsigned short ch;
  59. for(ch=0; ch<OUTPUT_BITS_NUMBER;ch++)
  60. {
  61. if(user_datas[START_ADDR_OUTPUT+ch] != 0)
  62. break;
  63. }
  64. if(!DEFAULT_OUT || (ch == OUTPUT_BITS_NUMBER))
  65. {
  66. DEFAULT_OUT = 1;
  67. for(ch=0; ch<OUTPUT_BITS_NUMBER;ch++)
  68. {
  69. user_datas[START_ADDR_OUTPUT+ch] = ch;
  70. }
  71. }
  72. }
  73. //IO管脚配置
  74. void IOPinConfigure(void)
  75. {
  76. IOPinDefualtConf_OUTOUT();
  77. IOPinDefualtConf_INOUT();
  78. InputPinConfig();
  79. OutputPinConfig();
  80. }