Help: LM35 & ADC0831 interfacing with 8051

Status
Not open for further replies.

hashim5003

Junior Member level 2
Joined
Jul 21, 2013
Messages
21
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Activity points
116
I am new to c language. I am trying to use LM35 for temprature reading with 8051. I need to know that how to receive serial data from ADC0831 with 8051 and then send it to LCD? I have wrote some code but can't do the receiving part? Should I create an array to save the bytes received from adc or something else?
 

What specific variant of the 8051 are you utilizing?

What programming language are you using to write the code?

Have you written the MICROWIRE interface routines?

BigDog
 

I'm using at89s52 and using c language.
Don't know about MICROWIRE interface routines.
 

The ADC0831 utilizes a three wire interface, MICROWIRE, similar to SPI.

Checkout Atmel AT89S52 product page under documents:

Documents for AT89S52

Program Examples for 8051 SPI

Code Examples for 8051 SPI



You should be able to adapt the above SPI routines for use with the MICROWIRE device.

You can also search for 8051/AT89S52 SPI routines and tutorials here in the forum and Google it as well.


BigDog
 

What are master mode, slave mode etc?
 

Typically, at least in your case, the microcontroller, AT89S52, is the master and the peripheral device, ADC0831, is the slave.

As both MICROWIRE and SPI allow for more than one peripheral device to be connected to the data input and output line at one time, the Slave Select (SS) or Chip Select (CS) line is simply a GPIO line which selects the particular peripheral device with which to communicate.

Serial Protocols Compared

Introduction to Serial Peripheral Interface


BigDog
 


I read your links, quiet helpful. but still I don't know where to start write program. Should I create an array to store data received from output pin or do something else?
 

The ADC0831 has a resolution of 8-bits, range of 0 to 255, therefore you can simply store the conversion in an unsigned char or an array of unsigned char if you wish to store more than one conversion and calculate the average of the set.

I would first recommend supplying the ADC with a stable voltage of known value and then develop your SPI/MICROWIRE read/write/control routines, using the LCD to display the resulting 8-bit value.

Once you'll succeed in transferring and storing the conversion value from the ADC0831 to the AT89S52, you can then connect the LM35 and work on the conversion routines.


BigDog
 


bigdogguru
I have worked on the code. Plz check if it is correct or not?
Edit: It's not working. What's wrong in it?
Code:
#include<reg51.h>

void delay (int);
void lcd_init (void);
void lcd_cmd (char);
void lcd_data (char);
//char read_data (char);

sbit RS = P1^0;
sbit EN = P1^1;
sbit CS = P1^2;
sbit CK = P1^3;
sbit DO = P1^4;
char value;

void delay ( int a )
{
	int i,j;
	for ( i = 0; i < a; i++ )
		for ( j = 0; j < 1275; j++ );
}

void lcd_init ()
{
	lcd_cmd(0x38);		  
	delay(5);
	lcd_cmd(0x0F);      
	delay(5);
	lcd_cmd(0x0C);
	delay(5);
	lcd_cmd(0x80);
	delay(5);
}

void lcd_data ( char y )
{
	RS = 1;
	P2 = y;
	EN = 1;
	delay(5);
	EN = 0;
	delay(5);
}

void lcd_cmd ( char z )
{
	RS = 0;
	P2 = z;
	EN = 1;
	delay(5);
	EN = 0;
	delay(5);
}

unsigned char read_data()
{
	unsigned char i;
	char result;
	
		CS = 1;
		delay(5);
		CS = 0; 
	
		CK = 1;
		delay(5);
		CK = 0;
		delay(5);
		CK = 1;
		delay(5);
		CK = 0;
		delay(5);
	
		for ( i = 0; i < 8; i++ )
		{
			CK = 1;
			delay(5);
			CK = 0;
			delay(5);
			result = result << 1;
			result = result | DO;
			delay(5);
		}
	return result;
}

void main ()
{
	lcd_init();

	while(1)
	{
		value = read_data;
		lcd_data (value);
	}
}
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…