04.03.2013 Views

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

RESUME<br />

resume<br />

Interrupts<br />

This command is used to exit the <strong>Basic</strong> interrupt handler and return to the point in your program<br />

where execution was interrupted due to an interrupt trigger.<br />

Interrupt Example<br />

The following example uses Time V and creates a counter that will blink an LED every second<br />

regardless of what the program is doing. This is a very simple way to create a background task that<br />

can easily indicate the device is still running.<br />

;calculates the number of interrupts per 1/100th of a second<br />

;as a fl oating point constant.<br />

interval fcon MHZ/100/256/128<br />

counter var fl oat<br />

counter = 0.0<br />

milliseconds var long<br />

milliseconds = 0<br />

TCRV0 = 0x03 ;Sets Timer V to count once every 128 OSC clocks<br />

TCRV1 = 0x01<br />

;Tells the processor where to jump to when the timer V<br />

;overfl ow interrupt triggers.<br />

ONINTERRUPT TIMERVINT_OVF,handler<br />

ENABLE TIMERVINT_OVF ;enables the timer V overfl ow interrupt<br />

ENABLE ;enables interrupts in general<br />

main<br />

if(milliseconds >= 500)then<br />

toggle p0<br />

milliseconds = milliseconds - 500<br />

endif<br />

goto main<br />

handler<br />

;this interrupt is executed once per 256*128 clock cycles<br />

counter = counter + 1.0<br />

if(counter>interval)then<br />

counter=counter-interval<br />

milliseconds = milliseconds + 10<br />

endif<br />

resume<br />

207

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!