<<Previous

Next>>

 @

@ Statement

When used at the beginning of a line, @ provides a shortcut for inserting one assembly language Statement into your PBP program. You can use this shortcut to freely mix assembly language code with PICBASIC PRO™ statements.

i	var	byte
rollme 	var	byte

	For i = 1 to 4
@	rlf	_rollme, F	; Rotate byte left once
	Next i

The @ shortcut can also be used to include assembly language routines in another file. For example:

@ Include "fp.asm"

@ resets the register page to 0 before executing the assembly language instruction. The register page should not be altered using @.

See the section on assembly language programming for more information.

 ADCIN

ADCIN Channel,Var

Read the on-chip analog to digital converter Channel and store the result in Var. While the ADC registers can be accessed directly, ADCIN makes the process a little easier.

Before ADCIN can be used, the appropriate TRIS register must be set to make the desired pins inputs. ADCON1 also needs to be set to assign the desired pins to analog inputs and in some cases to set the result format and clock source. See the Microchip data sheets for more information on these registers and how to set them for the specific device.

Depending on the device, it may have an 8-, 10- or 12-bit ADC. The high bit of ADCON1 controls whether the result is left or right justified. In most cases, 8-bit results should be left justified (ADCON1.7 = 0) and 10- and 12-bit results should be right justified (ADCON1.7 = 1).

Several DEFINEs may also be used:

	DEFINE ADC_BITS 8	' Set number of bits in result
	DEFINE ADC_CLOCK 3	' Set clock source (rc = 3)
	DEFINE ADC_SAMPLEUS 50	' Set sampling time in microseconds

ADC_SAMPLEUS is the number of microseconds the program waits between setting the Channel and starting the analog to digital conversion.

	TRISA = 255		' Set PORTA to all input
	ADCON1 = 2		' PORTA is analog
	ADCIN 0, B0		' Read channel 0 to B0

 ASM..ENDASM

ASM

ENDASM

The ASM and ENDASM instructions tells PBP that the code between these two lines is in assembly language and should not be interpreted as PICBASIC PRO™ statements. You can use these two instructions to freely mix assembly language code with PICBASIC PRO™ statements.

The maximum size for an assembler text section is 8K. This is the maximum size for the actual source, including comments, not the generated code. If the text block is larger than this, break it into multiple ASM..ENDASM sections or simply include it in a separate file.

ASM resets the register page to 0. You must ensure that the register page is reset to 0 before ENDASM if the assembly language code has altered it.

See the section on assembly language programming for more information.

	ASM
		bsf PORTA, 0	; Set bit 0 on PORTA
		bcf PORTB, 0	; Clear bit 0 on PORTB
	ENDASM
<<Previous

Next>>