EmbDev.net

Forum: µC & Digital Electronics ADC program o/p


Author: Shaik Piebe (shaik)
Posted on:

Rate this post
0 useful
not useful
hello all,
I m working with AT89C51CC01.
I write ADC program as follows.

#include <stdio.h>
#include "reg_c51.h"
  // standard conversion
 // The variable "channel" contains the channel to convert
 // The variable "value_converted" is an unsigned int
#define channel P1_7     // ADC i/p
#define value_converted P0 // ADC o/p

void main()
{
        ADCF = 0x80;  // configure channel P1.7 for ADC
        ADCON = 0x20;   // Enable the ADC

        ADCON  &= 0xF8;    // Clear the field SCH[2:0]

        ADCON |= channel;    // Select channel

        ADCON |= 0x08;   // Start conversion in standard mode

        // Wait flag End of conversion
        while((ADCON & 0x01)!= 0x01)
        {

                ADCON &= 0xEF;// Clear the End of conversion flag
                // read the value
                value_converted = (ADDH << 2)+(ADDL);
        }
        while (1)
        {}
}

In this program my analog i/p pin is p1_7 and o/p port is P0.
I can give analog i/o through P1_7 pin but no o/p given by port P0.
I don´t know why?

I have clearly write
value_converted = (ADDH << 2)+(ADDL);
#define value_converted P0 // ADC o/p

then why this program not give o/p?

Please check this program.
Tell me ur idea or sugestion for this problem.

Thanks in advance.

Author: Sucharitha Perla (Company: nge s&c) (sucharitha)
Posted on:

Rate this post
0 useful
not useful
try, below program. it may work?


#include <stdio.h>
#include "reg_c51.h"

 // standard conversion
 // The variable "channel" contains the channel to convert
 // The variable "value_converted" is an unsigned int



void main()

{
        unsigned int value_converted;   //  ADC value is 10bit

        ADCF = 0x80;  // configure channel P1.7 for ADC

        ADCON = 0x20;   // Enable the ADC

        ADCON  &= 0xF8;    // Clear the field SCH[2:0]

        ADCON |=  0x07;    // Select channel

        ADCON |= 0x08;   // Start conversion in standard mode

        while(!(ADCON & 0x10));  // Wait flag End of conversion


        ADCON &= 0xEF;    // Clear the End of conversion flag


        value_converted = (ADDH << 2)+(ADDL); // read the value


        while(1);
}

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.