Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

interfacing 0808 with 8051

Status
Not open for further replies.

jyothi1

Junior Member level 1
Joined
Sep 24, 2010
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Anantpur, A.P
Activity points
1,614
Hi 2 all,
Here I have written programming code but it is not working it is giving adc value as 128 only. and it is not varying as I change in input.. can any one please help me.The below is my code.

#include<reg51.h>
#define adc_data P2 //ADC data port
sbit ADDR_2=P0^0; // CHANNEL SELECTION PORT
sbit ADDR_1=P0^1;
sbit ADDR_0=P0^2;

sbit ALE=P0^4; //ADDRES LATCH ENABLE
//sbit CLOCK=P0^7; //CLOCK GENERATED FOT THE ADC0808 AT THIS

sbit SOC = P0^3; //START OF CONVERSION
sbit EOC = P0^5; //END OF CONVERSION
sbit OE = P0^6; //READ ENABLE

void convertion(unsigned char ans)
{
unsigned char i,x,k,l,j,a[3];
i=ans;
x=i/0X0A;
j=(i%0X0A);
k=(x%0X0A);
l=(x/0x0A);
a[0]=(l | 0x30);
LCD_DELAY(500);
a[1]=(k | 0x30);
LCD_DELAY(500);
a[2]=(j | 0x30);
send(a[0]);
send(a[1]);
send(a[2]);

void main()
{
unsigned char adc_val,i;

EOC=1; // MAKE EOC PIN INPUT PIN

ALE=0;
OE=0;
SOC=0;

init_serial(); // serial intialisation
ser_string("welcome");

while(1)
{
ADDR_2 =0;
ADDR_1 =0; // BY DEFAULT SELECT CHANNEL 1
ADDR_0 =0;
adc_val=adc_read();
convertion(adc_val);
}
unsigned char adc_read(void)
{
unsigned char value;
MSDELAY(1);
ALE=1; // sending high to low pulse
MSDELAY(1);
SOC=1; // SOC starts
MSDELAY(1);
ALE=0;
SOC=0;
//while(EOC==1); // wait until conversion ends
while(EOC==0);
OE=1;
LCD_DELAY(500);
value=adc_data;
OE=0;
return (value);
}
 

This is already addressed in many earlier threads. can you do a search in this forum. if still you did not understand then the code will be updated.

Try to simulate it and see if it works in simulator, before trying on hardware.

---------- Post added at 17:50 ---------- Previous post was at 17:48 ----------

where are you seeing the output?

there are half and half program about serial and LCD.
 
#include<reg51.h>
#include<intrins.h>
#include<stdio.h>

sbit rs=P3^6;
sbit en=P3^7;

sbit eoc=P2^1;
sbit soc=P2^0;

sbit cha=P2^2;
sbit chb=P2^3;
sbit chc=P2^4;

void cmdwrt();
void delay();
void datawrt();
void asc();
void valconv();

unsigned char dis[6]={0x30,0x38,0x08,0x0c,0x06,0x80};
unsigned char a,b,c,d;

main()
{
int i;
for( i=0;i<6;i++)
{
a=dis;
cmdwrt();
delay();
}
//select channel
cha=0;
chb=0;
chc=0;
while(1)
{
a=0x80;
cmdwrt();
delay();

eoc=0x01;
soc=0x00;
delay();

soc=0x01;
delay();
soc=0x00;

while(eoc); //wait for conversion
delay();
a=P1;
asc(); //display
delay();
}
}

void asc()
{
d=a;
a=a>>4;
a=a & (0x0f);
valconv(); //conv to ascii
datawrt(); //disp on LCD

a=d;
a=a & (0x0f);
valconv();
datawrt();
}


void valconv()
{
if(a <= (0x09))
{
a=a+ (0x30);
}
else
{
a=a+ (0x37);
}
}


void cmdwrt()
{
rs=0;
P0=a;
en=1;
delay();
en=0;
}

void datawrt()
{
rs=1;
P0=a;
en=1;
delay();
en=0;
}

void delay()
{
int i;
for(i=0;i<1000;i++);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top