<<Previous |
END
END
Stop program execution and enter low power mode. All of the I/O pins remain in their current state.
END works by executing a Sleep instruction continuously in a loop.An
END or STOP or GOTO should be placed at the end of every program to keep it from falling off the end of memory and starting over.END
ERASECODE Block
Some flash PICmicro MCUs, like the PIC18Fxxx series, require a portion of the code space to be erased before it can be rewritten with WRITECODE. On these devices, an erase is performed a block at a time. An erase block may be 32 words (64 bytes) or another size, depending on the device. This size is usually larger than the write block size. See the Microchip data sheet for information on the size of the erase block for the particular PICmicro MCU you are using.
The first location of the block to be erased should be specified by Block. Block is a byte address from 0 to 65535, rather than a word address, for PIC18Fxxx devices. Be careful not to specify a Block that contains program code.
Flash program writes must be enabled in the configuration for the PICmicro MCU at device programming time for ERASECODE to be able to erase.
Using this instruction on devices that do not support block erase will cause a compilation error.
ERASECODE $100 ‘ Erase code block starting at location $100
Count = Start TO End {STEP {-} Inc}FOR
{Body}
NEXT {Count}
The
FOR..NEXT loop allows programs to execute a number of statements (the Body) some number of times using a variable as a counter. Due to its complexity and versatility, FOR..NEXT is best described step by step:1) The value of Start is assigned to the index variable, Count. Count can be a variable of any type.
2) The Body is executed. The Body is optional and can be omitted (perhaps for a delay loop).3) The value of Inc is added to (or subtracted from if "-" is specified) Count. If no STEP clause is defined, Count is incremented by one.
4) If Count has not passed End or overflowed the variable type, execution returns to Step 2.If the loop needs to
Count to more than 255, a word-sized variable must be used.FOR i = 1 TO 10 ' Count from 1 to 10 Serout 0,N2400,[#i,” “] ' Send each number to Pin0 serially NEXT i ' Go back to and do next count Serout 0,N2400,[10] ' Send a linefeed FOR B2 = 20 TO 10 STEP -2 ' Count from 20 to 10 by 2 Serout 0,N2400,[#B2,” “] ' Send each number to Pin0 serially NEXT B2 ' Go back to and do next count Serout 0,N2400,[10] ' Send a linefeed
Pin,Onms,Frequency1{,Frequency2}FREQOUT
Produce the
Frequency(s) on Pin for Onms milliseconds. Pin is automatically made an output. Pin may be a constant, 0-15, or a variable that contains a number 0-15 (e.g. B0) or a pin name (e.g. PORTA.0).One or two different frequencies from 0 to 32767 hertz may be produced at a time.
FREQOUT
generates tones using a form of pulse width modulation. The raw data coming out of the pin looks pretty scary. Some kind of filter is usually necessary to smooth the signal to a sine wave get rid of some of the harmonics that are generated:
FREQOUT
works best with a 20MHz oscillator. It can also work with a 10MHz oscillator and even at 4MHz, although it will start to get very hard to filter and be of fairly low amplitude. Any other frequency will cause FREQOUT to generate a frequency that is a ratio of the actual oscillator used and 20MHz.FREQOUT is not supported on 12-bit core PICmicro MCUs due to RAM and stack constraints.
' Send 1KHz tone on Pin1 for 2 seconds FREQOUT PORTB.1,2000,1000
' Send 350Hz / 440Hz (Dial Tone) for 2 seconds FREQOUT PORTB.1,2000,350,440
LabelGOSUB
Jump to the subroutine at
Label saving its return address on the stack. Unlike GOTO, when a RETURN statement is reached, execution resumes with the statement following the last executed GOSUB statement.An unlimited number of subroutines may be used in a program. Subroutines may also be nested. In other words, it is possible for a subroutine to call another subroutine. Such subroutine nesting should be restricted to no more than four levels deep (12 levels for 17Cxxx and 27 levels for 18Cxxx).
GOSUB beep ' Execute subroutine named beep ... beep: High 0 ' Turn on LED connected to Pin0 Sound 1,[80,10] ' Beep speaker connected to Pin1 Low 0 ' Turn off LED connected to Pin0 Return ' Go back to main routine that called us
LabelGOTO
Program execution continues with the statements at
Label.GOTO send ' Jump to statement labeled send ... send: Serout 0,N2400,[“Hi”] ' Send “Hi” out Pin0 serially
<<Previous |