HI Silvio,
Thanks for your help again, Yup with regards to storing data, i do think it is storing cos the LED switches off after some.
with regards to
What are the precedence of unary operators in C ?
*addr++ means :
1. increment the addr and then store the value of advalue to a cell memory pointed to by addr
or
2. store the value of advalue to a cell memory pointed to by addr, then increment the addr
It is the first one where *addr++ means :
increment the addr and then store the value of advalue to a cell memory pointed to by addr
As for your advice on
Inside INT0 ISR the scanled() function is called. But what is the value of "addr" at statement converted=(*addr)*(5/256);
Just because prior of calling scanled() function you have the statement *addr++ =advalue; // to store the values into the address
I have written another code which does not involve interrupts at all, The LED switches on for a short while and then it switches off, but the display still shows 0;
The code is below for your reference.
#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 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) {
WRITE=0; // AD conversion;
WRITE=1;
while(INTR==1);
delay();
BLANK=1;
P1=0xFF; // declaring P1 as input data after A/D conversion
READ=0;
advalue=P1; // assigning the input bits (A/D bits) to advalue
READ=1;
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=(*addr)*(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;
for(j=0;j<20000;j++);
}
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;
}
I really dont know where i went wrong.