MikroC - ADC and Compare

Status
Not open for further replies.

wzhn

Newbie level 2
Joined
Jun 4, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,298
Hi,

I'm very (VERY) new to programming. Currently, I am learning the ADC module for the PC16F887 and what I'm attempting to do is as follow:

Receive TWO analog inputs on the input ports, put them through ADC conversion, compare them by a simple logic and then output a HIGH on any of the pre-determined output ports.

Like any beginner, I tried with the ADC library example first and then modify the codes to play with it as I learn. Tried searching for beginner level programming but just couldn't find an appropriate one. Helpful feedbacks are much appreciated.


attached: is my simulation circuit

 

use mikro c help ,it has its own help and examples for adc, i2c etc

Well, that's what I'm doing. Learning from its examples. But it cant tell me what I'm doing it wrong, can it?:razz:
 

MikroE ADC Example :

Code:
/*
 * Project name:
     ADC_on LEDs (Display the result of ADC on LEDs)
 * Copyright:
     (c) Mikroelektronika, 2011.
 * Revision History:
     20110929:
       - initial release (FJ);
 * Description:
      A simple example of using the ADC library.
      ADC results are displayed on PORTC and PORTD.
 * Test configuration:
     MCU:             PIC18F45K22
                      http://ww1.microchip.com/downloads/en/DeviceDoc/41412D.pdf
     Dev.Board:       EasyPIC7 - ac:ADC
                      http://www.mikroe.com/easypic/
     Oscillator:      HS-PLL 32.0000 MHz, 8.0000 MHz Crystal
     Ext. Modules:    None.
     SW:              mikroC PRO for PIC
                      http://www.mikroe.com/mikroc/pic/
 * NOTES:
     - Turn on PORTC and PORTD LEDs on SW3.3 and SW3.4.
     - To simulate analog input on ADC channel 1, use on-board potentiometer P1
       and place jumper J15 to MCU pin corresponding to ADC channel 1 input.
 */

#include <built_in.h>

unsigned int adc_rd;

void main() {
  ANSELA = 0x02;             // Configure RA1 pin as analog
  ANSELC = 0;                // Configure PORTC pins as digital
  ANSELD = 0;                // Configure PORTD pins as digital
  
  TRISA = 0x02;              // Set RA1 pin as input
  TRISC = 0x00;              // Set PORTC as output
  TRISD = 0x00;              // Set PORTD as output

  while (1) {
    adc_rd = ADC_Read(1);    // get ADC value from 1st channel
    LATC = adc_rd;           // display adc_rd[7..0]
    LATD = Hi(adc_rd);       // display adc_rd[9..8]
  }
}



Do you want to compare one ADC value with second ADC value, and if value is higher then turn some LED or something else ?
 

Do you want to compare one ADC value with second ADC value, and if value is higher then turn some LED or something else ?
i am searching for this problem .. i..e. to compare one adc value with other ... any suggestion
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…