error in ANSELH and comparator bit

General discussion on mikroBasic.
Post Reply
Author
Message
kshitijnov
Posts: 4
Joined: 02 Feb 2016 14:18

error in ANSELH and comparator bit

#1 Post by kshitijnov » 02 Feb 2016 14:25

I recently started learning Mikroc and this is one of the first code that i tried to build
unsigned int temp_res;

void main() {
ANSEL = 0x04; // Configure AN2 pin as analog
ANSELH = 0; // Configure other AN pins as digital I/O
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;

TRISA = 0xFF; // PORTA is input
TRISC = 0; // PORTC is output
TRISB = 0; // PORTB is output

do {
temp_res = ADC_Read(2); // Get 10-bit results of AD conversion
PORTB = temp_res; // Send lower 8 bits to PORTB
PORTC = temp_res >> 8; // Send 2 most significant bits to RC1, RC0
} while(1);
}

The program shows the error for commands ANSELH, C1ON AND C2ON for PIC16917
I have been trying to find the correct alternate instruction from datasheet but failed

User avatar
biljana.nedeljkovic
mikroElektronika team
Posts: 1043
Joined: 30 Jun 2015 15:15

Re: error in ANSELH and comparator bit

#2 Post by biljana.nedeljkovic » 03 Feb 2016 09:57

Hello,

You can see the definition file for that MCU in our compiler (CTRL+ALT+D).

I believe you can use ADCONx and CMCONx.

Also check out the datasheet for the PIC16F917 and the section about I/O ports and registers:
http://ww1.microchip.com/downloads/en/D ... 41250E.pdf

Kind regards,
Biljana

kshitijnov
Posts: 4
Joined: 02 Feb 2016 14:18

Re: error in ANSELH and comparator bit

#3 Post by kshitijnov » 03 Feb 2016 10:39

what will happen if i dont use ADCONx commands. Whether the other pins behave as analog or digital

User avatar
biljana.nedeljkovic
mikroElektronika team
Posts: 1043
Joined: 30 Jun 2015 15:15

Re: error in ANSELH and comparator bit

#4 Post by biljana.nedeljkovic » 04 Feb 2016 11:34

Hello,

The pins are analog by default.

You can check the more in th datasheet how to use ANSEL, ADCON etc.

Kind regards,
Biljana

Post Reply

Return to “mikroBasic General”