Hi to all,
I have troubles with reading 10 bit on AN0 , too .
Can somebody give me some ideas, please ?
Code:'**************************************************************** '* Name : UNTITLED.BAS * '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 10/2/2018 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** 'PIC16F886 #config __CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_ON & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT __CONFIG _CONFIG2, _WRT_OFF & _BOR21V #endconfig define osc 4 include "lcd886.bas" CM1CON0 = 0 'Comparator Off CM2CON0 = 0 'Comparator Off Define ADC_BITS 10 'Set number of bits in result (10) Define ADC_CLOCK 3 'Set clock source (3=rc) Define ADC_SAMPLEUS 50 'Set sampling time in microseconds (50us) TRISA = %00000001 'Set PORTA.0 as input TRISB = %00000000 'Set PORTB as outputs TRISC = %00000000 'Set PORTC as outputs ANSEL = %00000001 'Set PORTA.0 as analog ANSELH = %00000000 'The rest ports are digital 'ADCON0 = %11000011 'Set adc channel = AN0 'ADCON1 = %10000000 'SETUP ADC RIGHT JUSTIFY SET REFV to VDD & VSS PORTA = 0 PORTB = 0 PORTC = 0 light var PORTA.3 tc var word '--------light is ON and initialize the LCD --------- pause 300 high light gosub lcdrst lcdout $fe, $80,"TEST" gosub lcdrst '---------------------PROGRAM------------------------ MAIN: ADCON0 = %11000011 gosub read_tc lcdout $fe, $80, #tc pause 200 goto main end '---------------------Read AN0------------------------ read_tc: WHILE ADCON0.1 = 1:WEND 'WAIT FOR CONVERSION tc.HIGHBYTE = ADRESH tc.LOWBYTE = ADRESL return '--------------------lcd reset------------------------ lcdrst: lcdout, $fe, 1 pause 10 return




Bookmarks