Mike - K8LH
Well-Known Member
I'm stumped trying to access a local variable from assembly in XC8. If I make "duration" a global variable it works fine. Any ideas, Gentlemen?
Come to think of it, I also couldn't figure out how to use a constant for the GP2 pin mask.
TIA. Cheerful regards, Mike
Come to think of it, I also couldn't figure out how to use a constant for the GP2 pin mask.
TIA. Cheerful regards, Mike
Code:
void interrupt isr(void)
{
static unsigned char duration = 0;
T0IF = 0; // clear TMR0 interrupt flag
/* *
* Mike McLaren's non-blocking isochronous "beep task" runs *
* at 250-usec intervals and produces 'N' number of 32-msec *
* 2000-Hz beeps spaced 32-msecs apart. Set 'beep' variable *
* to 'N+N-1' for number of beeps desired (128 beep limit). *
* *
* beeptask() macro; #define beeptask(n) beep = (n+n-1) *
* */
asm("movlw 0b00000100 "); // mask for 'spkr' on GP2
asm("btfsc _beep,0 "); // beep b0 == 1? no, skip,
asm("xorwf _GPIO,F "); // else, toggle 'spkr' pin
asm("movf _beep,F "); // beep task running?
asm("skipz "); // no, skip, else
asm("incf _duration,F "); // bump 'duration'
asm("btfsc _duration,7 "); // 32-ms timout? no, skip,
asm("decf _beep,F "); // else, decrement 'beep'
asm("btfsc _duration,7 "); // 32-ms timout? no, skip,
asm("clrf _duration "); // else, reset 32-ms timer
Last edited: