setup-loop.cpp 1.6 KB

1234567891011121314151617181920212223242526
  1. #include "all-headers.h"
  2. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  3. // Led L2 is connected to PORTD:7 (active high)
  4. void setup (void) {
  5. //--- Configure PTD7 as digital port (input or output)
  6. PORTD_PCR (7) = PORT_PCR_MUX (1) ;
  7. //--- Configure PTD7 as digital output port (output level is low --> led is off)
  8. GPIOD_PDDR |= (1 << 7) ;
  9. }
  10. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  11. void loop (void) {
  12. //--- Drive PTD7 high --> led is on
  13. GPIOD_PSOR = 1 << 7 ;
  14. //--- Wait...
  15. for (volatile uint32_t i=0 ; i< 10 * 1000 * 1000 ; i++) {}
  16. //--- Drive PTD7 low --> led is off
  17. GPIOD_PCOR = 1 << 7 ;
  18. //--- Wait...
  19. for (volatile uint32_t i=0 ; i< 10 * 1000 * 1000 ; i++) {}
  20. }
  21. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————