hi i have an adc0804 interface code for pic18.I have tried so much but ı couldt solve it.İf someone might look at my code and talk about that i would be very happy.
My algoritm is like bellow
Stage 1) To trigger a new conversion, we must make pin 3 (Write) low and then return it to the high state. The conversion process starts when Write goes high (rising edge triggered).
Stage 2) When the conversion process is complete, pin 5 (Interrupt) will go low.
Stage 3) When we see pin 5 (Interrupt) go low, we must make pin 2 (Read) low to load the new value into the outputs D0 - D7.
Stage 4) Next we read the values into the 2051 Port 1.
Stage 5) Finally, we return pin 2 (Read) to the high state. The next conversion can be started immediately.
And here is my code(written in pch picc).ıf someone can solve what is the problem i would be thankfull.
#include <18f452.h>
#fuses NOPROTECT
#use delay(clock=4000000)
#BIT rd =0xF84.1
#BIT interrupt =0xF84.0
#BIT write =0xF84.2
#define allin 0xFF
#define allout 0
#define low 0
#define high 1
#BYTE porte = 0xF84
#BYTE portd = 0xF83
#BYTE portb = 0xF81
main()
{
int i;
set_tris_e(0x06);
set_tris_b(allin);
set_tris_d(allout);
for(i=1 ; ;i++)
{
rd=high;
write=low;
delay_us(10);
write=high;
don:
delay_us(10);
if(interrupt==0)
{ rd=low;
}
else goto don;
portd=portb;
}
}
My algoritm is like bellow
Stage 1) To trigger a new conversion, we must make pin 3 (Write) low and then return it to the high state. The conversion process starts when Write goes high (rising edge triggered).
Stage 2) When the conversion process is complete, pin 5 (Interrupt) will go low.
Stage 3) When we see pin 5 (Interrupt) go low, we must make pin 2 (Read) low to load the new value into the outputs D0 - D7.
Stage 4) Next we read the values into the 2051 Port 1.
Stage 5) Finally, we return pin 2 (Read) to the high state. The next conversion can be started immediately.
And here is my code(written in pch picc).ıf someone can solve what is the problem i would be thankfull.
#include <18f452.h>
#fuses NOPROTECT
#use delay(clock=4000000)
#BIT rd =0xF84.1
#BIT interrupt =0xF84.0
#BIT write =0xF84.2
#define allin 0xFF
#define allout 0
#define low 0
#define high 1
#BYTE porte = 0xF84
#BYTE portd = 0xF83
#BYTE portb = 0xF81
main()
{
int i;
set_tris_e(0x06);
set_tris_b(allin);
set_tris_d(allout);
for(i=1 ; ;i++)
{
rd=high;
write=low;
delay_us(10);
write=high;
don:
delay_us(10);
if(interrupt==0)
{ rd=low;
}
else goto don;
portd=portb;
}
}