Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F690 and LCD (16*2) with 8 bit mode .

Status
Not open for further replies.

saymondok

Newbie level 1
Newbie level 1
Joined
Feb 1, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,292
hi guys ... i am in problem with my favorite PIC16F690 and stupid LCD(16*2) . In Protues ISIS its work awesome. But in practical LCD doesn't display anything...i am really getting Upset :roll:. U guys can help me from this ****....... [MODERATOR - NO FOUL LANGUAGE]
and Can u guys help me to convert this into 4 bit mode. Just LCD part.

My code :

Code:
/*LPG LECKAGE DETECTION AND AUTO CALLING TO SELECTED PHONES
 * FINAL YEAR PROJECT
 * AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH
 * MD. SHAKHAWAT HOSSEN (ID: 08-11488-2)
 * MCU-PIC16RF690
 */

#include<pic.h>
#include<htc.h>
#define _XTAL_FREQ 4000000
__CONFIG (INTIO & WDTDIS & PWRTEN & MCLREN & UNPROTECT & UNPROTECT & BORDIS & IESODIS & FCMDIS);

#define  LCD 	PORTC
#define  rs 	RB4
//#define  rw 	RB5
#define  en 	RB5
#define  t 	10


void LCD_ini(unsigned  char com);
void LCD_data(unsigned  char cha);


void main(){
	//OSCCON=01100010;              //4MHz internal
	ANSEL=0x03;			// RA0 & RA1 are Analog.
	ANSELH=0;			//Rest of pins are digital.


	// Comparator Block
	TRISA0=1;                       // Ref input of Comparator.
	TRISA1=1;                       //Input of Comparator.
	TRISA2=0;                       //Output of Comparator.
	TRISA5=0;
	TRISA4=0;


	C1CH0=0;                        //To select -V pin out of 4
	C1CH1=0;                        // Here 00 pin(RA1) select

	C1R=0;                          //Select Referance pin(RA0)
	C1ON=1;                         //To ON the Comparator.
	C1POL=1;                        //To invert the comparator result.
	C1OE=1;                         //To eneble RA2 for getting result
	//Comparator Block

	//LCD Block
	TRISC=0x00;			// define output
	TRISB=0x00;			//define O/P
	//LCD Block

	int i,relay=1,count=1;
	RB6=0;				// Relay switch.
	RB7=0;				//LED blinking.


	LCD_ini(0x38);			//8 bit mode .
	LCD_ini(0x0C);			//Display on Cursor off.
	LCD_ini(0x80);			//Set DDRAM  & Cursor position on display

	while(1){


		if(C1OUT==0){
			relay=1;
			count=1;
			RB7=0;                          //LED blinking
			RB6=0;                          // Relay switch.

			LCD_ini(0x80);			//Set DDRAM  & Cursor position on display .
			unsigned  char j[]="GAS NOT FOUND... ";

			for (int i=0 ; i <(sizeof j) ;i++){
				LCD_data( j[i]);
				__delay_ms(t);
			}

			LCD_ini(0xC0);                  //	Start at 2nd row.

			unsigned  char m[]=" ############# ";

			for (int i=0 ; i <(sizeof m) ;i++){
				LCD_data(m[i]);
				__delay_ms(t);
			}
		}


		if(C1OUT==1){

			RB7=1;				//LED blinking


			LCD_ini(0x80);			//Set DDRAM  & Cursor position on display .
			unsigned  char k[]="   GAS FOUND !! ";

			for (int i=0 ; i <(sizeof k) ;i++){
				LCD_data(k[i]);
				__delay_ms(t);
			}

			LCD_ini(0xC0);                  //Start at 2nd row.

			RB7=0;				//LED blinking
			unsigned  char n[]="  Calling ............. !! ";

			for (int i=0 ; i <(sizeof n) ;i++){
				LCD_data(n[i]);
				__delay_ms(t);
			}

			if(relay<=2){
				RB6=1;			// Relay switch.
				relay++;
				__delay_ms(50*t);
				RB6=0;			// Relay switch.
			}
			if(count==40)	{
			relay=1;
			count=1;
			}
			count++;
		}
	}
}

void LCD_ini(unsigned  char com){

		LCD=com;
		en=1;
		rs=0;
		//rw=0;
		__delay_ms(t);
		en=0;
		__delay_ms(t);
	}

void LCD_data(unsigned  char cha){

		LCD=cha;
		en=1;
		rs=1;
		//rw=0;
		__delay_ms(t);
		en=0;
		__delay_ms(t);
		rs=0;
	}

Main CKT:



Use CODE tags when posting your code.
 
Last edited by a moderator:

You get angry ,
but please don't you use those type of words .
it might may your programer fault check it ?
 

In Protues ISIS its work awesome. But in practical LCD doesn't display anything...i am really getting Upset :roll:.

When you indicate, "LCD doesn't display anything," does this indicate literally nothing or are there black boxes?

What is the exact model of LCD you are using in your physical hardware design? Do you have a datasheet for the device?

Issues concerning LCDs performing as expected in simulation versus not performing as expected with physical hardware are often due to improper initialization and timing delays.

Just glancing at your code there appears to be an insufficient delay to allow the LCD power up to ready state before issuing the initialization commands. All LCD controllers require a certain time period upon receiving power to initialize themselves internally to a known ready state before any commands are issued to them. The specific time delay varies between controller chipsets, manufactures and other factors. The required startup delay usually ranges from 50ms to 150ms, with a longer than needed delay having no ill effect.

I would suggest placing a 150ms delay in your code before issuing the first command to the LCD. Also you are using a set 10ms delay for all commands in both the LCD_ini() and LCD_data() routines, this maybe too short a delay for the initialization commands and longer than needed for the operational commands. In most LCDs the monitoring of the Busy Flag is the preferred method rather than a fixed delay when issuing operational commands.

Once you have identified the exact model of the LCD in your design, more specific delay requirements can be suggested.

BigDog
 

Most Common Mistake People do...
i real world is Connection Mistake..
First Check Your Connection Properly.


To convert it in 4-Bit mode..
Just have a look in your Samples Folder where Hi-Tech C Installation occurs.
It will have a samples Folder in which you will find LCDDemo..
That uses 4-Bit Mode
 

I would strongly recommend that you debug the LCD interface in 8-bit mode, before attempting to convert the design to 4-bit mode.

BigDog
 

I'm having the same problem with LCD interfacing with pic16f690. Its ok in simulation. Also other programs are working well in real circuit but only there is no output in the LCD display. I triple checked the connections. connections are all ok. but no output in the LCD. what may be the problem?

- - - Updated - - -

Its ok, I found the problem. The LCD along was faulty. All ok...
 

Is it possible to have this code in assembly language (PIC) please.
If any one can help i will be grateful.
Thank you in advance.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top