adc0804 + project
Hi,
I have tried to interface ADC0804 and HY62256(S-ram) to AT89C52 microcontroller. The whole idea is to do an A/D conversion using ADC 0804 and than storing the data input to the SRAM. The Value that is stored on the SRAM is displayed on the HP display to check whether the value stored is the same as the input to the ADC.The code that i had developed is below for reference. It does not seem to work. The Display does not show the signal input. The schematic is in the attachment. Could someone please help me. Thank you.
#include <reg52.h>
void delay(void);
unsigned char xdata * data addr = 0x0000; // declares a pointer staring from external memory address of 0x0000
sbit WRITE=P3^0; // defining the WR and INTR pins
sbit INTR=P3^2 ;// The INTR pin is connected to the INTO pin, so that whenever it goes low, it cause an interrupt
sbit READ=P3^3; //This is the READ pin ( for ADC)
sbit LED=P3^1;
sbit CS=P3^4; // Used as Chip select for ADC0804
sbit BLANK=P3^5; // I am using HP 5082-7340 (display) and the display blanks when this pin goes high
unsigned int advalue,value,j,converted,k;
scanled (); // to display the ADC value on HP 5082-7340 display
void main(void){
while(1) {
P1=0xFF; // declaring P1 as input data after A/D conversion
BLANK=1; // Blank the Display
CS=0; // To enable the ADC chip
WRITE=0; // AD conversion;
WRITE=1;
while(INTR==1);
delay();
READ=0;
advalue=P1; // assigning the input bits (A/D bits) to advalue
delay();
READ=1;
CS=1; //To disable the ADC,so that no conversion occurs
for (j=0;j<20;j++){delay();} // delay for about 1 second
if(addr<=0x0014) /* keep on storing the 8 bit values obtained from the ADC in address starting from 0x0000 till
the S-RAM stores data till the address reaches 0x0014 */
{LED=1; // to check whether there is any conversion (by toggling the LED)
*addr++ =advalue; // to store the values into the address
LED=0;
scanled(); // to display the input signal value on an adc
delay();
} //to check whether there is any conversion
else{
LED=1;
}
delay();
}
}
scanled()
{
unsigned int a[10]={0xE0,0xF0,0xE1,0xF1,0xE2,0xF2,0xE3,0xF3,0xE4,0xF4}; // Configuration for display from 0-9
P1=0x00; // declare P1 as output
BLANK=0; // The Blank is made low so that the HP display shows numbers
converted=(advalue)*5/256; // Convert the ADC value obtained so that the input signal is between 0-5V;
P1=a[converted%10]; // Display the value on Port1;
}
void delay (void) // Delay function using Timer 0 for 50ms.
{
TMOD &=0xF0;
TMOD |=0x01;
ET0 =0;
TH0 =0x3C;
TL0 =0xB0;
TF0 =0;
TR0 =1;
while(TF0==0);
TR0=0;
}