Interfacing the AD0803 to the 8051 micro controller
This is the parallel port connector to the micro controller. The adc reading is transmitted to the serial port.
Code:
#include <reg51.h>
#include <stdio.h>
#define adc_port P1
sbit rd = P2^0;
sbit wr = P2^1;
sbit cs = P2^2;
sbit intr = P2^3;
//unsigned int adc;
float adc1;
void serial_init()
{
TMOD = 0x20;
SCON = 0x50;
TH1 = 0xFD;
TR1 = 1;
TI = 1;
RI = 0;
}
void delay(unsigned int i)
{
unsigned int j,k;
for(j=0;j<=i;j++)
{
for(k=0;k<256;k++);
}
}
void adc_conv()
{
cs = 0;
wr = 0;
wr = 1;
cs = 1;
while(intr);
}
void adc_read()
{
cs = 0;
rd = 0;
adc1 = adc_port;
delay(1);
cs = 1;
rd = 1;
}
void main()
{
serial_init();
printf("Hello World\n");
delay(5);
while(1)
{
adc_conv();
//printf("Hello\n");
adc_read();
printf(" ADC = %.2f\n\r",adc1/51);
delay(1);
}
}
The Proteus image is attached
This is the parallel port connector to the micro controller. The adc reading is transmitted to the serial port.
Code:
#include <reg51.h>
#include <stdio.h>
#define adc_port P1
sbit rd = P2^0;
sbit wr = P2^1;
sbit cs = P2^2;
sbit intr = P2^3;
//unsigned int adc;
float adc1;
void serial_init()
{
TMOD = 0x20;
SCON = 0x50;
TH1 = 0xFD;
TR1 = 1;
TI = 1;
RI = 0;
}
void delay(unsigned int i)
{
unsigned int j,k;
for(j=0;j<=i;j++)
{
for(k=0;k<256;k++);
}
}
void adc_conv()
{
cs = 0;
wr = 0;
wr = 1;
cs = 1;
while(intr);
}
void adc_read()
{
cs = 0;
rd = 0;
adc1 = adc_port;
delay(1);
cs = 1;
rd = 1;
}
void main()
{
serial_init();
printf("Hello World\n");
delay(5);
while(1)
{
adc_conv();
//printf("Hello\n");
adc_read();
printf(" ADC = %.2f\n\r",adc1/51);
delay(1);
}
}
The Proteus image is attached
nice blog checkout my blogs at
ReplyDeletehttp://www.onjokes.blogspot.com
feel free to leave a comment