EmbDev.net

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


von Shaik P. (shaik)


Rate this post
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.

von Sucharitha P. (Company: nge s&c) (sucharitha)


Rate this post
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);
}

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.