AD problem

General discussion on mikroC.
Post Reply
Author
Message
veljovic
Posts: 10
Joined: 11 Mar 2012 02:59

AD problem

#1 Post by veljovic » 13 Mar 2012 12:16

Hello,

in mikroC PRO for PIC I find example for analog conversion but it not work.
code is:

Code: Select all

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);
}
Problem is ANSEL, ANSELH, C1ON and C2ON (Specifier needed...invalid declarator expected...)

What is problem ?

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: AD problem

#2 Post by filip » 14 Mar 2012 12:36

Hi,

Which MCU are you using ?

Regards,
Filip.

veljovic
Posts: 10
Joined: 11 Mar 2012 02:59

Re: AD problem

#3 Post by veljovic » 14 Mar 2012 21:18

-easyPIC2 board
-16F877a
-mikroC PRO for PIC v.5.4.0

regards,
veljovic

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: AD problem

#4 Post by filip » 15 Mar 2012 10:48

Hi,

The mentioned registers belong to another chip (I suppose this is a code originally written for 16F887).
Please, try this code :

Code: Select all

unsigned int temp_res;

void main() {
  ADCON1 = 0x80;              // Configure analog inputs and Vref
  TRISA  = 0xFF;              // PORTA is input
  TRISB  = 0x3F;              // Pins RB7, RB6 are outputs
  TRISD  = 0;                 // PORTD is output

  do {
    temp_res = ADC_Read(2);   // Get 10-bit results of AD conversion
    PORTD = temp_res;         // Send lower 8 bits to PORTD
    PORTB = temp_res >> 2;    // Send 2 most significant bits to RB7, RB6
  } while(1);
}
Regards,
Filip.

veljovic
Posts: 10
Joined: 11 Mar 2012 02:59

Re: AD problem

#5 Post by veljovic » 15 Mar 2012 20:01

Hi,

ADCON1 is ok.
I can write to this register. Thank you Filip.

best regards,
veljovic

Post Reply

Return to “mikroC General”