• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

A/D conversion for 89LPC925

Status
Not open for further replies.

Vikky

New Member
Hi all,

I want the ADC code for 89LPC925. I have developed it according to understanding. But i think i am missing some where. Here is my code

Code:
include "stdio.h"
#include "reg925.h"


unsigned char converted_data;

void main()
{	
	int i;	

	ADMODB |= 0x40;   //Configuring clock divider and selecting ADC mode

    	P0M1 |= 0x02;  // configuring ADC chanel1 Port0.1 as input.
	P0M2 &= ~0x02 ;
	P1M1 = 0x00;
	P1M2 = 0x00;  	
	
	ADMODB &= ~0x08; // Disabling DAC

	IP1 &= 0x7F; //Interrupt priorities
	IP1H &= 0x7F;

	EAD = 1 ;   //Enabling ADC Interrupt

	ADMODA |= 0x40;		  // ADC conversion mode autoscan and continous

	ADINS &= 0x10;    // Select ADC chanel 0.	 

	ADCON1 |= 0x45;	   // Start conversion immediatly, enable ADC interrupt

	while(1)
	{
	 if (ADCON1 & 0x08)		// Conversion Completed?
		{
		 converted_data = AD1DAT0; // save the result
		ADCON1 &= ~0x08;        // clear ADCI1 flag	 
			
	
		serial(converted_data); // send the data serially

		for (i=0;i<300;i++)
			{
			} 
		}
	}
}
The serial data sending part is running fine. I think that the data are not been converted into the digital format. Can naybody pass me the sample code of the ADC for 89LPC925??

Thanks
 

Vikky

New Member
Hi all,

To get the status of the programm i have slightly modified the my previous code and try to get the converted value from the ADC on the hyterterminal. The code is
Code:
#include "stdio.h"
#include "reg925.h"

void serial(unsigned char hyper_data);
unsigned char converted_data;

void main()
{	
	int i;	

	ADMODB |= 0x60;     //Configuring clock divider and selecting ADC mode
	ADMODA |= 0x20;	    //   ADC conversion mode autoscan and continous

   	P0M1 = 0x1E;
	P0M2 = 0x00;
	P1M1 = 0x00;
	P1M2 = 0x00;  	
	
	TMOD = 0X20;
	TH1 = 0Xf4;
	SCON = 0X50;
	TR1 = 1	;

	serial('A');
	serial('D');
	serial('C');
	serial(' ');
	
	serial('S');
	serial('T');
	serial('A');
	serial('R');
	serial('T');

	ADCON1 |= 0x45;  //  Start conversion immediatly, enable ADC interrupt	   

	while(1)
	{
		while((ADCON1 & 0x08) != 0x08)  // Conversion Completed?
			{
			}

	        converted_data = AD1DAT0; // save the result
			ADCON1 = 0x00;        // clear ADCI1 flag
			

			serial('A');
			for (i=0;i<300;i++)
				{
				}
	
			serial(converted_data);

			for (i=0;i<300;i++)
				{
				} 
			
	}
}
 
void serial(unsigned char hyper_data)
{	     
	SBUF = hyper_data;
	while(TI == 0);
	TI = 0;
}

Here on the Hyperterminal i can view only "ADC START". But after that nothing happens. I have even kept a display of character "A" after each ADC value, but that too did not come upto to screen.

Need help.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top