Skip to content

Instantly share code, notes, and snippets.

@AndrioCelos
Created April 20, 2018 07:51
Show Gist options
  • Save AndrioCelos/dfd3a29b5451b368cbc07c2f4b86f883 to your computer and use it in GitHub Desktop.
Save AndrioCelos/dfd3a29b5451b368cbc07c2f4b86f883 to your computer and use it in GitHub Desktop.
void delay(unsigned int delayms) {
// Enable interrupts.
EI();
// Enable the timer 0 interrupt.
IRQ0ENH |= 0x20;
// Set the timer.
T0CTL1 = TCTL1(0, 0, 7, TMODE_ONE_SHOT);
T0CTL0 = TCTL0(0);
T0 = 1;
T0R = 145;
for (; delayms > 0; --delayms) {
T0CTL1 |= 0x80;
// HALT mode stops the CPU, reducing power use.
// Several events can resume the CPU, including interrupts.
asm("HALT");
}
}
interrupt void isr_timer0() _At TIMER0 { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment