ADC program o/p

OP #1823877
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.
(Company: nge s&c) #1838804
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);
}

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.