main.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2021 IOsetting <iosetting(at)outlook.com>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /***
  15. * Demo: 28BYJ-48 Stepper Motor with ULN2003 Driver
  16. *
  17. * Pin connection:
  18. * MCU ULN2003 External Power Supply
  19. * P10 => IN1
  20. * P11 => IN2
  21. * P12 => IN3
  22. * P13 => IN4
  23. * VCC => 5V ~ 12V
  24. * GND => GND
  25. *
  26. * test-board: Minimum System; test-MCU: STC8H1K08,STC8H3K64S2
  27. */
  28. #include "fw_hal.h"
  29. // Clockwise, 8 steps
  30. uint8_t cw[8]={
  31. 0B00001001,
  32. 0B00000001,
  33. 0B00000011,
  34. 0B00000010,
  35. 0B00000110,
  36. 0B00000100,
  37. 0B00001100,
  38. 0B00001000
  39. };
  40. void GPIO_Init(void)
  41. {
  42. // P10, P11, P12, P13
  43. GPIO_P1_SetMode(GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3, GPIO_Mode_Output_PP);
  44. }
  45. int main(void)
  46. {
  47. uint8_t step;
  48. uint16_t pos;
  49. SYS_SetClock();
  50. GPIO_Init();
  51. while(1)
  52. {
  53. for (pos = 0; pos < 640; pos++)
  54. {
  55. step = 8;
  56. while (step--)
  57. {
  58. P1 = P1 & 0xF0 | cw[7 - step];
  59. SYS_Delay(5);
  60. }
  61. }
  62. SYS_Delay(500);
  63. for (pos = 0; pos < 640; pos++)
  64. {
  65. step = 8;
  66. while (step--)
  67. {
  68. P1 = P1 & 0xF0 | cw[step];
  69. SYS_Delay(5);
  70. }
  71. }
  72. SYS_Delay(500);
  73. }
  74. }