Sign In

Problem In Interfacing Lcd With The Whole Setup

Aakash Deol aakashdeol19@gmail.com India

Hardware: ATmega16 Ic Used On Pcb Board Software: C Project Based In Atmel Studio 6

The project is on automatic irrigation system.Soil moisture sensor YL69 is used to sense moisture in soil and accordingly dc motor or a pump is used to rotate and stop.LCD displays Pump ON and OFF.The main problem is that the design has been made in isis proteus and we don't have sensorin that hence we are not able to simulate the project and also while interfacing on hardware the LCD don't show any data it simply glows.
Kindly reply to this asap.

Images

problem in interfacing lcd with the whole setup

Program

#define F_CPU 8000000UL
#include<avr/io.h>
#include<util/delay.h>
void command()
{
	PORTD=0b00010000;
	_delay_ms(50);
	PORTD=0b00000000;
}
void display()
{
	PORTD=0b00010100;
	_delay_ms(50);
	PORTD=0b00000100;
}
unsigned char arr1[]={0x38,0x0e,0x01,0x80};
unsigned char arr2[]={"pump on"};
unsigned char arr3[]={"pump off"};
unsigned char arr4[]={"welcome"};

int adc(void);
void pump(void);
int adc_value=0;
int i,j,k,l,h;
int main(void)
{
	DDRC=0x0f;                           //Defining PC0 as output
	DDRA=0x00;
	DDRB=0xff;
	DDRD=0xff;
	ADCSRA=0x87;                    //Setting the mode of operation
	ADMUX=0x00;                     //Selection of channel and bit alignment
	while(1)
	{
		
		for(l=0;l<=4;l++)
		{
			PORTB=arr1[l];
			command();
		}
		for(h=0;arr4[h]!='';h++)
		{
			PORTB=arr4[h];
			display();
		}
		PORTB=0xc0;
		command();
		adc_value=adc();                //reading moisture level
		pump();                               //Pump activator routine
	}
	return 0;
}

int adc(void)
{
	int lower_bits,higher_bits,result;
	ADCSRA |= (1 << ADSC)|(1 << ADIF);  //Turn on conversion and clear flag
	while(ADCSRA & (1 << ADIF) == 0);  //wait for flag
	lower_bits=ADCL;
	higher_bits=ADCH;
	result=lower_bits|(higher_bits<<8);         //Accessing converted value by shifting
	return result;
}

void pump(void)
{
	
	if(adc_value>=70)                                //Pump ON trigger point
	{
		for(i=0;i<=4;i++)
		{
			PORTB=arr1[i];
			command();
		}
		for(j=0;arr2[j]!='';j++)
		{
			PORTB=arr2[j];
			display();
		}
		PORTB=0xc0;
		command();
		PORTC=0x02;
		
	}
	else if(adc_value<70)                        //Pump Off trigger point
	{
		for(i=0;i<=4;i++)
		{
			PORTB=arr1[i];
			command();
		}
		for(k=0;arr3[k]!='';k++)
		{
			PORTB=arr3[k];
			display();
		}
		PORTB=0xc0;
		command();
		PORTC=0x03;
	}
}

Replies

R Avinash Gupta
2016-05-12 02:01:51
Lots of obvious error. Or you can say nothing is correct and user seems not to be knowing anything about programming.

First of all.

Their is not at all any code for lcd interface in the given program. So their is no question of a lcd showing anything!

second the program assumes 8MHz crystal by defining F_CPU as 8000000

But in schematic no crystal is connected.

Also the very important contrast adjust pin of LCD is not connected.

Please also attach the real pphotographs of you PCB
0
R Aakash Deol
2016-05-12 11:37:07
Avinash Gupta

if you closely look at the code the "for loops" are for lcd purpose and while using isis proteus software there is no requirement of connecting contrast adjustment pin.
All I want is that check the adc part in the code if it is right or not and also provide any video regarding interfacing of lcd with atmega16 (hardware) plz.
0
R Avinash Gupta
2016-05-14 04:41:41
We have made the program and schematic for simulation. It is attached with this reply. Kindly download and check if it works. Also in the attached package is the HEX file that you may use with your Proteus simulation file.

The soil moisture sensor is simulated using a variable resistor. You can click up and down arrows near it to generate different output voltages that will be feed to the ADC input of the MCU. If you take values below 7% the pump will be turned on.
0
R Aakash Deol
2016-05-14 04:59:28
Thank you Avinash Gupta and extreme electronics that was very helpful.One lastrequest, can you please provide the code in C for the same programme.That would be very helpful to me in understanding what was i doing wrong.
0
R Avinash Gupta
2016-05-14 05:08:42
First check and post screenshot of simulation.
0
R Aakash Deol
2016-05-14 05:14:06
I have checked the simulation is working fine..
Screenshots have been attached
0

Post a reply to Aakash Deol

Think you can help Aakash Deol ? Then post your thoughts that might help Aakash Deol. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.