Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include "nrf52840.h"
  2. #include "nrf52840_bitfields.h"
  3.  
  4.  
  5. void init_gpio_p0_output(uint32_t pin_num)
  6. {
  7. NRF_GPIO_Type * reg = ((NRF_GPIO_Type*)NRF_P0_BASE);
  8. reg->PIN_CNF[pin_num] = ((uint32_t)GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos)
  9. |((uint32_t)GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
  10. |((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
  11. |((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
  12. |((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
  13.  
  14. }
  15.  
  16. void toggle_gpio_p0(uint32_t pin_num)
  17. {
  18. NRF_GPIO_Type * reg = ((NRF_GPIO_Type*)NRF_P0_BASE);
  19. uint32_t pins_state = reg->OUT;
  20. reg->OUTSET = (~pins_state & (1UL << pin_num));
  21. reg->OUTCLR = (pins_state & (1UL << pin_num));
  22.  
  23.  
  24. }
  25.  
  26.  
  27. int main()
  28. {
  29. // gpio config for board PCA10056 LED1,2,3,4 = P0.13, P0.14, P0.15, P0.16.
  30. init_gpio_p0_output(13); // LED1 on PCA10056
  31. init_gpio_p0_output(14); // LED2 on PCA10056
  32. init_gpio_p0_output(15); // LED3 on PCA10056
  33. init_gpio_p0_output(16); // LED4 on PCA10056
  34.  
  35. while(1)
  36. {
  37. // toggling the pin
  38. toggle_gpio_p0(13);
  39. toggle_gpio_p0(14);
  40. toggle_gpio_p0(15);
  41. toggle_gpio_p0(16);
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement