Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.cpp 980B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "mbed.h"
  2. volatile unsigned int ticks = 0;
  3. DigitalOut led(LED_BLUE);
  4. extern "C" void lptmr_isr(void) {
  5. // write 1 to TCF to clear the LPT timer compare flag
  6. LPTMR0->CSR |= LPTMR_CSR_TCF_MASK;
  7. ticks++;
  8. }
  9. int main() {
  10. /* Clock the timer */
  11. SIM->SCGC5 |= SIM_SCGC5_LPTMR_MASK;
  12. /* Reset */
  13. LPTMR0->CSR = 0;
  14. /* Compare value */
  15. LPTMR0->CMR = 1000;
  16. /* Enable interrupt */
  17. LPTMR0->CSR |= LPTMR_CSR_TIE_MASK;
  18. /* Set interrupt handler */
  19. NVIC_SetVector(LPTimer_IRQn, (uint32_t)lptmr_isr);
  20. NVIC_EnableIRQ(LPTimer_IRQn);
  21. /* select LPO for RTC and LPTMR */
  22. LPTMR0->PSR = LPTMR_PSR_PCS(3); // ERCLK32K -> 8MHz
  23. LPTMR0->PSR |= LPTMR_PSR_PRESCALE(2); // divide by 8
  24. /* Start the timer */
  25. LPTMR0->CSR |= LPTMR_CSR_TEN_MASK;
  26. led = 0;
  27. while (true) {
  28. wait(1);
  29. led = 1;
  30. printf("%d\n", ticks);
  31. wait(1);
  32. led = 0;
  33. printf("%d\n", ticks);
  34. }
  35. }