others.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "includes.h"
  2. void RCC_ClockInit(unsigned char enable)
  3. {
  4. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA |
  5. RCC_AHBPeriph_GPIOB |
  6. RCC_AHBPeriph_GPIOC |
  7. RCC_AHBPeriph_GPIOD |
  8. RCC_AHBPeriph_GPIOF, enable);
  9. }
  10. void MY_NVIC_Init(void)
  11. {
  12. NVIC_InitTypeDef NVIC_InitStructure;
  13. //串口1
  14. NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  15. NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
  16. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  17. NVIC_Init(&NVIC_InitStructure);
  18. // NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;
  19. // NVIC_InitStructure.NVIC_IRQChannelPriority=0;
  20. // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  21. // NVIC_Init(&NVIC_InitStructure);
  22. //
  23. // NVIC_InitStructure.NVIC_IRQChannel = EXTI2_3_IRQn;
  24. // NVIC_InitStructure.NVIC_IRQChannelPriority=1;
  25. // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  26. // NVIC_Init(&NVIC_InitStructure);
  27. }
  28. void AllGPIO_Init(void)
  29. {
  30. GPIO_InitTypeDef GPIO_InitStructure;
  31. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA |
  32. RCC_AHBPeriph_GPIOB |
  33. RCC_AHBPeriph_GPIOC |
  34. RCC_AHBPeriph_GPIOD |
  35. RCC_AHBPeriph_GPIOF, ENABLE);
  36. GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
  37. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  38. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  39. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  40. GPIO_InitStructure.GPIO_Pin = HC165_READ_PIN;
  41. GPIO_Init(HC165_READ_PORT, &GPIO_InitStructure);
  42. GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
  43. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  44. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  45. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
  46. GPIO_InitStructure.GPIO_Pin = RS485_DIR_PIN;
  47. GPIO_Init(RS485_DIR_PORT, &GPIO_InitStructure);
  48. //LED配置
  49. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  50. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  51. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  52. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  53. // GPIO_InitStructure.GPIO_Pin = MODEM_LED1_PIN;
  54. // GPIO_Init(MODEM_LED1_PORT, &GPIO_InitStructure);
  55. // GPIO_InitStructure.GPIO_Pin = MODEM_LED2_PIN;
  56. // GPIO_Init(MODEM_LED2_PORT, &GPIO_InitStructure);
  57. //串入并出
  58. GPIO_InitStructure.GPIO_Pin = HC595_SCLR_PIN;
  59. GPIO_Init(HC595_SCLR_PORT, &GPIO_InitStructure);
  60. GPIO_InitStructure.GPIO_Pin = HC595_SCK_PIN;
  61. GPIO_Init(HC595_SCK_PORT, &GPIO_InitStructure);
  62. GPIO_InitStructure.GPIO_Pin = HC595_RCK_PIN;
  63. GPIO_Init(HC595_RCK_PORT, &GPIO_InitStructure);
  64. GPIO_InitStructure.GPIO_Pin = HC595_DATA_PIN;
  65. GPIO_Init(HC595_DATA_PORT, &GPIO_InitStructure);
  66. //并入串出
  67. GPIO_InitStructure.GPIO_Pin = HC165_CP_PIN;
  68. GPIO_Init(HC165_CP_PORT, &GPIO_InitStructure);
  69. GPIO_InitStructure.GPIO_Pin = HC165_PL_PIN;
  70. GPIO_Init(HC165_PL_PORT, &GPIO_InitStructure);
  71. GPIO_SetBits(HC595_SCLR_PORT, HC595_SCLR_PIN|HC595_SCK_PIN|HC595_DATA_PIN|HC595_RCK_PIN);
  72. //GPIO_ResetBits(HC595_SCLR_PORT, HC595_SCLR_PIN|HC595_SCK_PIN|HC595_DATA_PIN|HC595_RCK_PIN);
  73. }