11.07.2015 Views

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

<strong>PICBASIC</strong> <strong>PLUS</strong> Compiler5.1. ADINSyntax :Overview :Operators :Example :variable = ADIN channel numberRead the value from the on-board Analogue to Digital Converter.Variable is a user defined variable.Channel number can be a constant or a variable expression.‘Read the value from channel 0 of the ADC and place in variable Var.DECLARE ADIN_RES 10 ‘ 10-bit result requiredDECLARE ADIN_TAD FRC ‘ RC Osc chosenDECLARE ADIN_STIME 50 ‘ Allow 50us sample timeDIM Var as WORDTRISA = %00000001 ‘ Configure AN0 (PortA.0) as an inputADCON1=%10000000 ‘ Set analogue input on PortA.0Var=ADIN 0‘ Place the conversion into variable VARDeclares :There are three DECLARE directives for use with ADIN.These are: -DECLARE ADIN_RES 8 , 10 , or 12.Sets the number of bits in the result.If this DECLARE is not used, then the default is the resolution of thePIC type used. For example, the new 16F87X range will result in aresolution of 10-bits, while the standard PIC types will produce an 8-bit result. Using the above DECLARE allows an 8-bit result to be obtainedfrom the 10-bit PIC types, but NOT 10-bits from the 8-bit types.DECLARE ADIN_TAD 2_FOSC , 8_FOSC , 32_FOSC , or FRC.Sets the ADC’s clock source.All compatible PICs have four options for the clock source used by theADC. 2_FOSC, 8_FOSC, and 32_FOSC, are ratios of the externaloscillator, while FRC is the PIC’s internal RC oscillator. Instead of usingthe predefined names for the clock source, values from 0 to 3 maybe used. These reflect the settings of bits 0-1 in register ADCON0.Care must be used when issuing this DECLARE, as the wrong type ofclock source may result in poor resolution, or no conversion at all. If indoubt use FRC which will produce a slight reduction in resolution andconversion speed, but is guaranteed to work first time, every time.FRC is the default setting if the DECLARE is not issued in the BASIClisting.22Copyright Crownhill 2001

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

Saved successfully!

Ooh no, something went wrong!