Dear All, following is the code is not working..can any please guide me where is the problem.. #include<reg51.h> sbit ale=P1^0; //address latch enable sbit oe=P1^3; //output enable sbit sc=P1^1; //start conversion sbit eoc=P1^2; //end of conversion sbit clk=P1^7; // clock
sbit ADD_A=P1^4; // Address pins for selecting input channels. sbit ADD_B=P1^5; sbit ADD_C=P1^6; sfr input_port=0x80; sfr output_port=0xA0;
void timer0() interrupt 1 // Function to generate clock of frequency 500KHZ using Timer 0 interrupt. { clk=~clk; }
void delay(unsigned int count) // Function to provide time delay in msec. { int i,j; for(i=0;i<count;i++) for(j=0;j<1275;j++); }
void main() { eoc=1; input_port=0xFF; ale=0; oe=0; sc=0; TMOD=0x22; //timer0 setting for generating clock of 500KHz using interrupt enable mode. TH0=0xFD; IE=0x82; TR0=1; while(1) { ADD_C=0; // Selecting input channel 2 using address lines ADD_B=0; ADD_A=1; delay(2); ale=1; delay(2); sc=1; delay(1); ale=0; delay(1); sc=0; while(eoc==1); while(eoc==0); oe=1; output_port=input_port; delay(2); oe=0; } }
You have an interrrupt that is intended to run with 500kHz frequency. Is your processor even fast enough to manage 0.5 million interrupts / second - remember that every interrupt consumes several instructions.
Why don't you use a timer to create the 1ms delay? Don't you realize that the delay time of a software loop is affected by the percentage of CPU capacity that is consumed by interrupts?
By the way - where is the source code? You don't have anything tagged as code in your post - didn't you notice the information about how to post source code?
What is wrong? You haven't exactly spent much time explaining your troubles. Just a subject line "ADC0808 output is not stable". Nothing about exactly what happens and what things you have done to try to figure out what is wrong.
Dear Sir, i m getting unexpected values on D0-D7(outputs) of ADC,even if my input analog is stable which is 0 to 5 volt and Ref. voltage is +5Volt..i m trying to solve this problem from last one week but i m getting unstable values from the mentioned code...pls help me... if u have any source code to operate successfully ADC0808 then pls provide me ..it is very very very urgent....
IF the "unexpected values" are coming from the outputs of the ADC then, surely, it's nothing to do with the 8051 or the code running on it?
View all questions in Keil forum