Interface ADC0804 with 8051|Display on 16x2 LCD||Keil C – AT89C51|

 Interface ADC0804 with 8051, get Converted Data from Port 1 and Display on 16x2 LCD connected on Port 3 as shown in fig 2 Connect Data Pins (DB0-DB7) of ADC0804 with Port 1 of Microcontroller RD Pin of ADC0804 with P2.5. WR Pin of ADC0804 with P2.6. INTR Pin of ADC0804 with P2.7  Apply 2.5 Volts on Vref or leave it Unconnected Connect Data Pins (D0-D7) of LCD with Port 3 of Microcontroller RS of microcontroller with P2.0. RW of microcontroller with P2.1. EN of microcontroller with P2.2 

Source code

#include<reg51.h>

//(0x90)is address of port1, else you can write as : #defintre mydata P1

sfr mydata = 0x90;

sbit rd= P2^5;

sbit wr= P2^6;

sbit intr= P2^7;

sbit RS = P2^0;

sbit RW = P2^1;

sbit EN = P2^2;

 

void delay(int n) // For Delay

{

int i,j;

for(i=0;i<n;i++)

for(j=0;j<255;j++);

}

void lcd_cmd(char a) //LCD command Write

{

P3 = a;

RS = 0;

RW=0;

EN = 1;

delay(10);

EN = 0;

}

 

void lcd_data(char a)  //LCD data

{

P3 = a;

RS = 1;

RW=0;

EN = 1;

delay(10);

EN = 0;

}

 

void display(char *ptr) // For string display

{

while(*ptr != '\0')

{

lcd_data(*ptr);

ptr++;

}

}

void main()

{

unsigned char value;

char temp[4];

int i=0;

lcd_cmd(0x01); //clear screen

lcd_cmd(0x0E); //Display On, Cursor Blinking

lcd_cmd(0x38); //2 lines and 5*7 matrix

lcd_cmd(0x80); //Force Cursor to beginning of first

display("Value:");

lcd_cmd(0xC0);

intr = 1;

rd = 1;

wr = 1;

while(1)

{

lcd_cmd(0xC0);

wr = 0;

wr = 1;

while(intr==1);

rd=0;

value = mydata;

 

while(i<3)

{

temp[i] = (value%10) + '0'; // For converting into ASCII

value = value /10;

i++;

}

 

for(i=2;i>=0;i--)

{

lcd_cmd(0x06);

temp[i]=temp[i];

lcd_data(temp[i]);

}

i=0;

delay(1000);

rd = 1;

}

}Result:

Calculation:

Vref is Unconnected

RANGE=0-5

VIN+=2.55

Value Required= 2.55 x  =  130



Post a Comment

0 Comments