Here is another example of a small test program that will read the AN2 a/d converter and send it to a debug window.
one thing to remember is that the a/d converter names do not always match the pin #. example... AN2 does match PortA.2 but AN3 is actually on PortA.4.
If you have not used the debug feature of the PICkit programmer, you program the chip, power it up and then goto the Tools Menu and choose UART Tool. This will open up another Terminal window where you choose 2400 baud in the upper left and then click on Connect.
Good LuckCode:' 16F690 '**************************************************************** '* Name : UNTITLED.BAS * '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 12/4/2007 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** ' 10-bit A/D conversion ' Connect analog input to channel-2 (RA2) ' -----[ I/O Definitions ]------------------------------------------------- DEFINE DEBUG_REGG PORTA 'set debug port to porta DEFINE DEBUG_BIT 0 'use pin a0 of porta for debug DEFINE DEBUG_BAUD 2400 'set baud rate to 2400 DEFINE DEBUG_MODE 0 'communicate in true mode ' Define ADCIN parameters ' Set number of bits in result DEFINE ADC_BITS 10 ' Set clock source (3=rc) DEFINE ADC_CLOCK 3 ' Set sampling time in microseconds DEFINE ADC_SAMPLEUS 50 adcVar VAR WORD ' Create variable to store result ' Set PORTA to all input 'TRISA = %11111111 ' Set up AD ANSEL = %00000100 'enable AN2, ALL THE REST DIGITAL ANSELH = %00000000 'AN8-11 DIGITAL ADCON0 = %10001000 ' RIGHT JUSTIFIED ADCON1 = %00010000 'fOSC/8 Pause 500 ' Wait .5 second main: ADCIN 2, adcVar ' Read channel 0 ' do something with adVar here debug DEC adcvar," ",BIN adcVar,$0D,$0A Pause 100 ' Wait.01 second GoTo main ' Do it forever




Bookmarks