Download EXPERIMENTING with the PICBASIC PRO

Transcript
Experimenting with the PicBasic Pro Compiler
A brief introduction to hardware interrupts
The first macro, INT_START, saves the W register along with the
STATUS and PCLATH . This macro is only required when using a PIC
with 2k or less of ROM, as the compiler automatically saves the context
for larger PICs . To use the INT_START macro, place the following
template code at the beginning of your interrupt handier : Asm
; The name of the interrupt
My_Int
; Use the context saving macro
INT START
Your
interrupt
handling
code
goes
here )
{
The second macro, INT END, restores the contents of the W register,
STATUS, and PCLATH, then performs a RETFIE instruction . This macro
must be used regardless of the PIC size, as the compiler does not
restore the context for larger PICs . To use the INTEND macro, place
the following template code at the end of your interrupt handler: { Your interrupt handling code goes here )
; Use the context restore macro
INT END
Endasm
Each macro defined in the separate include files uses exactly the right
amount of instructions according to the size of the PIC chosen . Thus
reducing wasted memory
The program TMROCLCK.BAS demonstrates the use of a TMRO
interrupt performing the functions of a (not very accurate) clock,
displaying the time on a serial LCD connected to PortA.0 . The prescaler
is assigned the ratio of 1 :64, which means that an interrupt will be called
every 16.384ms (64*256us) . Assuming a 4mHz crystal is used .
Each time the interrupt is called, the variable TICKS is incremented until
it reaches 61 . This will give us an approximate second (61 *16384 =
999.424ms or . 999424 of a second) .
When TICKS reaches 61, a second has past so the SECONDS variable
is incremented and the TICKS variable is cleared . When SECONDS
reaches 60, a minute has passed so the MINUTES variable is
incremented and the SECONDS variable is cleared . When MINUTES
reaches 60, an hour has passed so the HOURS variable is incremented
and the MINUTES variable is cleared .
Section-10- 1 5