PDA

View Full Version : Error: Hi-Tech C program for LCD interface with PIC 16F877A



nitinmathew2007
05-29-2011, 08:55 PM
Hi,
I have written a code to interface the LCD to PIC16F877A using Hi-Tech C compiler in MP LAB IDE. There are no errors in the program when I Build it. But when I simulate the program using PROTEUS or PIC Simulator I don't get the output.

Please correct my program and notify the mistake I did. Pl help me..

DETAILS:
I use PIC16F877A, MP LAB IDE, PROTEUS, Hi-Tech C Compiler.

OTHER DETAILS:
LCD 4 bit Interface,
RS = PORT E,0
RW = PORT E,1
EN = PORT E,2

DATA = PORT A,(0-3) [4bit-Interface]

__________________________________________________ ______________________
CODE:

#include<htc.h>

#define RS RE0
#define RW RE1
#define EN RE2

void LCD_delay(void)
{
long t;
for(t=0;t<250;t++);
}

void LCD_delay2(void)
{
long a;
for(a=0;a<10000;a++);
}

void LCD_command(unsigned char command)
{
unsigned char temp;
RS = 0;

// To send LSB part of command
temp = command & 0x0f; //Mask only upper data in byte
PORTA &= 0x30;
PORTA |= temp;
EN = 1;
for(temp=0;temp<10;temp++);
EN = 0;
LCD_delay();

// To send MSB part of command
temp =(command & 0xf0)<<4;
PORTA &= 0x30;
PORTA |= temp;
EN = 1;
for(temp=0;temp<10;temp++);
EN = 0;
LCD_delay();
}

void LCD_data(unsigned char data)
{
unsigned char temp2;
RS=1;
temp2 = data & 0x0f;
PORTA &= 0x30;
PORTA |= temp2;
EN = 1;
for(temp2=0;temp2<10;temp2++);
EN = 0;
LCD_delay();

temp2 =(data & 0xf0)<<4;
PORTA &= 0x30;
PORTA |= temp2;
EN = 1;
for(temp2=0;temp2<10;temp2++);
EN = 0;
LCD_delay();
}

void initialise_LCD(void)
{
ADCON0 = 0x00;//Disable ADC ports
ADCON1 = 0x06;//Disable ADC ports

TRISA = 0x00;
PORTA = 0x00; //DATA i/p to LCD

TRISE = 0x00;
PORTE = 0x00; //CONTROL i/p to LCD

LCD_command(0x02);//Command return the cursor to home
LCD_delay2();
LCD_command(0x07);//increment, disp shift
LCD_delay2();
LCD_command(0x0c);//off cursor, display on
LCD_delay2();
LCD_command(0x18);//Display shift,shift to left
LCD_command(0x28); //4bit interface, 2line, 5x8 dots
LCD_delay2();
}

void clear_LCD()
{
LCD_command(0x01);
LCD_delay2();
}

void display_LCD(char line_number,char position, const char *message)
{
int a;
if(line_number==1)
{
a = 0x80 + position;
RS = 0;
LCD_command(a);
}
else
{
a = 0xC0 + position;
RS = 0;
LCD_command(a);
}
while(*message!=0)
{
RS = 1;
LCD_data(*message);
message++;
}
}

void main(void)
{
__CONFIG(0x193A);
initialise_LCD();
RW=0;
while(1)
{
clear_LCD();
display_LCD(1,1,"WELCOME");
display_LCD(2,4,"welcome");
LCD_delay();
}
}

__________________________________________________ ______________________

Circuit is attached:
327

__________________________________________________ ______________________

Kindly help me... This will be useful to others too.. Thanks in advance..:)

shobhitkukreti
05-31-2011, 07:54 AM
Shouldn't it be MSB first and then LSB to be sent to the LCD ?

nitinmathew2007
05-31-2011, 10:46 AM
Yeah U r correct. Thanks.

So the program should be corrected as:

void LCD_command(unsigned char command)
{
unsigned char temp;
RS = 0;

// To send MSB part of command
temp = (command & 0xf0)<<4;
PORTA &= 0x30;
PORTA |= temp;
EN = 1;
for(temp=0;temp<10;temp++);
EN = 0;
LCD_delay();

// After sending MSB, To send LSB part of command
temp =command & 0x0f;
PORTA &= 0x30;
PORTA |= temp;
EN = 1;
for(temp=0;temp<10;temp++);
EN = 0;
LCD_delay();
}

And same thing should be done for sending data.

Am i right?? Also pl recheck nd tel if der r stil some errors. Thanks again..:)

shobhitkukreti
05-31-2011, 01:03 PM
Nitin, there are plenty of examples on the internet for this. Just make sure you have sufficient delay, and the initialization sequence is correct. Check the datasheet for the correct sequence to initialize. The 0x03 0x03, 0x02 and then 0x28 should be first in sequence. I do not remember exactly.Correlate with the datasheet

nitinmathew2007
05-31-2011, 01:09 PM
Ya ok tanX anyway..:)

As u said i modified and tried but still i din get output. So am concentrating on delay and initialization sequence. once i get it right i ll paste my coding here for future use...

Thanks once again..:)

--Nitin

shobhitkukreti
05-31-2011, 04:29 PM
I can give you the code for MSP430. You can port it to PIC

nitinmathew2007
05-31-2011, 04:33 PM
Ya k fine! Meanwhile I am trying to correct my code.

shobhitkukreti
05-31-2011, 10:11 PM
Try this sequence:

P2OUT |= 0x30; //
delay(295);
enable();
delay(195);
P2OUT |= 0x30;
delay(195);
enable();
delay(145);
P2OUT |= 0x30;
delay(195);
enable();
delay(195);
P2OUT |= 0x20; // 4bit mode, completes in single cycle
delay(195);
enable();
lcd_send_cmd(0x28); // 4 bit mode
delay(195);;
lcd_send_cmd(0x06); // Entry Mode
delay(195);
lcd_send_cmd(0x08);
delay(195);
lcd_send_cmd(0x0E); // Display On, Cursor On, Blink Off/On
delay(195);
lcd_send_cmd(0x14); // Display shift/Increment
delay(195);
lcd_send_cmd(0x02);// Return to Home Position
delay(280);
lcd_send_cmd(0x01); // Clear Display
delay(195);
}

nitinmathew2007
06-01-2011, 10:52 AM
Now after incorporating all your corrections and suggestions, my new program is as follows. I tried 2-3 methods still I am unable to get the output. I shall BOLD the corrections made from the first prog.

#include<htc.h>

#define RS RE0
#define RW RE1
#define EN RE2

void LCD_delay(void)
{
int t;
for(t=0;t<250;t++);
}

void LCD_delay2(void)
{
long a;
for(a=0;a<8000;a++);
}

void LCD_command(unsigned char command)
{
unsigned char temp;
RS = 0;

// To send MSB part of command
temp = (command & 0xf0)>>4; //PL note here the operator should be ">>" right??
PORTA &= 0x30;
PORTA |= temp;
EN = 1;
for(temp=0;temp<10;temp++);
EN = 0;
LCD_delay();

// After sending MSB, To send LSB part of command
temp =command & 0x0f;
PORTA &= 0x30;
PORTA |= temp;
EN = 1;
for(temp=0;temp<10;temp++);
EN = 0;
LCD_delay();
LCD_delay();
}

void LCD_data(unsigned char data)
{
unsigned char temp;
RS=1;
temp =(data & 0xf0)>>4;
PORTA &= 0x30;
PORTA |= temp;
EN = 1;
for(temp=0;temp<10;temp++);
EN = 0;
LCD_delay();

temp = data & 0x0f;
PORTA &= 0x30;
PORTA |= temp;
EN = 1;
for(temp=0;temp<10;temp++);
EN = 0;
LCD_delay();
LCD_delay();
}

void initialise_LCD(void)
{
ADCON0 = 0x00;//Disable ADC ports
ADCON1 = 0x06;//Disable ADC ports

TRISA = 0x00;
PORTA = 0x00; //DATA or COMMAND i/p to LCD

TRISE = 0x00;
PORTE = 0x00; //CONTROL i/p to LCD

LCD_delay2();
LCD_command(0x30);
LCD_delay2();
LCD_command(0x30);
LCD_delay();
LCD_command(0x30);
LCD_delay();
LCD_command(0x20);
LCD_delay2();

/* //I TRIED THE FOLLOWING TOO BUT DIN WORK, So THE FOLL CODES R COMMENTED
PORTA=0x03;
for(i=0;i<25;i++); //I use this cuz i use 4 bit interface if i send 0x30 I ll get oly 0 in porta. So i send MSB 1st then LSB! (made my own try :P)
PORTA=0x30;
LCD_delay2();
EN=1;
PORTA=0x03;
for(i=0;i<25;i++);
PORTA=0x30;
LCD_delay2();
EN=1;
PORTA=0x03;
for(i=0;i<25;i++);
PORTA=0x30;
LCD_delay();
EN=1;
PORTA=0x02;
for(i=0;i<25;i++);
PORTA=0x20;
LCD_delay2();
EN=1;

*/

LCD_command(0x28); //4-bit interface, 2 lines, 5*8 dots
LCD_delay2();
LCD_command(0x07);//increment, disp shift
LCD_delay2();
LCD_command(0x0c);//off cursor, display on
LCD_delay2();
LCD_command(0x14);//Display shift,shift to left i.e. scroll
LCD_delay2();
LCD_command(0x02);//Command return the cursor to home
LCD_delay2();
LCD_command(0x01);
LCD_delay2();
}

void clear_LCD()
{
LCD_command(0x01);
LCD_delay2();
}

void display_LCD(char line_number,char position, const char *message)
{
int a;
if(line_number==1)
{
a = 0x80 + position;
RS = 0;
LCD_command(a);
}
else
{
a = 0xC0 + position;
RS = 0;
LCD_command(a);
}
while(*message!=0)
{
RS = 1;
LCD_data(*message);
message++;
}
}

void main(void)
{
__CONFIG(0x193A);
initialise_LCD();
RW=0;
while(1)
{
display_LCD(1,1,"WELCOME");
display_LCD(2,4,"welcome");
LCD_delay();
}
}


If u r free pl help help me in correcting the program. I guess only some mild error somewhere is causing the trouble! Pl help me...

Thanks...

nitinmathew2007
06-02-2011, 12:00 AM
I made few modifications and made it as 8bit interface on port B. Now i gt the output. Bt the same if i try using 4bit on same PORT B i don get output! Only code I added to 8 bit interface is the masking MSB& LSB and sending them to ports. :(

WORKING CODE FOR INTERFACING LCD in 8-bit MODE

#include<htc.h>

#define RS RE0
#define RW RE1
#define EN RE2

void LCD_delay(void)
{
int t;
for(t=0;t<250;t++);
}

void delay_ms(unsigned char delay)
{
unsigned int i,j;
for(i=0;i<=delay;i++)
{
for(j=0;j<=1000;j++);
}
}

void LCD_command(unsigned char command)
{
unsigned char temp;
RS = 0;

temp =command & 0xff;
PORTB &= 0x00;
PORTB |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
LCD_delay();
}

void LCD_data(unsigned char data)
{
unsigned char temp;
RS=1;

temp = data & 0xff;
PORTB &= 0x00;
PORTB |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
LCD_delay();
}

void initialise_LCD(void)
{
ADCON0 = 0x00;//Disable ADC ports
ADCON1 = 0x06;//Disable ADC ports

TRISB = 0x00;
PORTB = 0x00; //DATA or COMMAND i/p to LCD

TRISE = 0x00;
PORTE = 0x00; //CONTROL i/p to LCD

EN=0;
RW=0;

delay_ms(40);
LCD_command(0x38);
delay_ms(20);
LCD_command(0x38);
delay_ms(2);
LCD_command(0x38);
delay_ms(1);

LCD_command(0x07);//increment, disp shift
LCD_command(0x0c);//off cursor, display on
LCD_command(0x14);//Display shift,shift to left i.e. scroll
LCD_command(0x02);//Command return the cursor to home
LCD_command(0x01);//clear LCD
delay_ms(1);
}

void clear_LCD()
{
LCD_command(0x01);
delay_ms(1);
}

void display_LCD(char line_number,char position, const char *message)
{
int a;
if(line_number==1)
{
a=0x80+position;
LCD_command(a);
}
else if(line_number==2)
{
a=0xC0+position;
LCD_command(a);
}
while(*message!=0)
{
LCD_data(*message);
delay_ms(15);
message++;
}
}

void main(void)
{
__CONFIG(0x193A);
initialise_LCD();
while(1)
{
display_LCD(1,8,"WELCOME TO ALL OF YOU PEOPLE...");
display_LCD(2,4,"welcome");
delay_ms(1);
}
}

nitinmathew2007
06-02-2011, 01:21 PM
Now sme 1 pl help me in converting the abve prog to 4bit interface!! Atleast pl correct the following program! :( :(

#include<htc.h>

#define RS RE0
#define RW RE1
#define EN RE2

void LCD_delay(void)
{
int t;
for(t=0;t<250;t++);
}

void delay_ms(unsigned char delay)
{
unsigned int i,j;
for(i=0;i<=delay;i++)
{
for(j=0;j<=1000;j++);
}
}

void LCD_command(unsigned char command)
{
unsigned char temp;
RS = 0;

// To send MSB part of command
temp = ((command & 0xf0)>>4);
PORTB &= 0x00;
PORTB |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
LCD_delay();

temp = (command & 0x0f);
PORTB &= 0x00;
PORTB |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
delay_ms(1);
}

void LCD_data(unsigned char data)
{
unsigned char temp;
RS=1;

temp =((data & 0xf0)>>4);
PORTB &= 0x00;
PORTB |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
LCD_delay();

temp = (data & 0x0f);
PORTB &= 0x00;
PORTB |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
delay_ms(1);
}

void initialise_LCD(void)
{
ADCON0 = 0x00;//Disable ADC ports
ADCON1 = 0x06;//Disable ADC ports

TRISB = 0x00;
PORTB = 0x00; //DATA or COMMAND i/p to LCD

TRISE = 0x00;
PORTE = 0x00; //CONTROL i/p to LCD

EN=0;
RW=0;

delay_ms(40);
LCD_command(0x33);
delay_ms(20);
LCD_command(0x30);
delay_ms(20);
LCD_command(0x30);
delay_ms(2);
LCD_command(0x28);
delay_ms(1);
LCD_command(0x28);
delay_ms(1);

LCD_command(0x07);//increment, disp shift
LCD_command(0x0c);//off cursor, display on
LCD_command(0x14);//Display shift,shift to left i.e. scroll
LCD_command(0x02);//Command return the cursor to home
LCD_command(0x01);//clear LCD
delay_ms(1);
}

void clear_LCD()
{
LCD_command(0x01);
delay_ms(1);
}

void display_LCD(char line_number,char position, const char *message)
{
int a;
if(line_number==1)
{
a=0x80+position;
LCD_command(a);
}
else if(line_number==2)
{
a=0xC0+position;
LCD_command(a);
}
while(*message!=0)
{
LCD_data(*message);
delay_ms(15);
message++;
}
}

void main(void)
{
__CONFIG(0x193A);
initialise_LCD();
while(1)
{
display_LCD(1,8,"WELCOME TO ALL OF YOU PEOPLE...");
display_LCD(2,4,"welcome");
delay_ms(1);
}
}

shobhitkukreti
06-02-2011, 06:41 PM
// P2.0 = E
// P2.1 = RS
// P2.4 - P2.7 = D4-D7
// P6.0/A0 = LPG Sensor

#include <msp430x26x.h>
#include <intrinsics.h>

#define line_two 0xC0
int temp_array =0;
int temp, degc,i,lpg_d;
void lcd_init();
void delay(int m);
void lcd_send_cmd(int );
void lcd_send_chr(char );
void enable();
void inttostr(int );
void lcd_string(char * );
void adc_measure();

void lcd_line2()
{
// Go to Line 2 of LCD
P2OUT |= 0XC0;
delay(500);
enable();
P2OUT |= 0x00;
delay(500);
enable();
}


char str1[4]= "0000";

void main(void)
{

temp=0;
degc=0;

P2DIR = 0xFF; // Setting Port 2 as output
P2OUT = 0X00;


WDTCTL = WDTPW +WDTHOLD; // Stop Watchdog Timer
P1DIR |= 0xff;
P1OUT |= 0x01;
P4DIR |=0xff;
P4OUT = 0x00;
//P4OUT |= !BIT0;
// P1.0 output
IFG1 &= ~OFIFG; // clearing oscillator fault flag
__bis_SR_register(SCG1 + SCG0); // Stop DCO
BCSCTL1 =BIT7 + DIVA_3 ;
BCSCTL2 = BIT3 + DIVS_3 + SELM_3 + DIVM_3;; // DCO/8 = 2 Mhz, can be further reduced to VLO/8
BCSCTL3 = LFXT1S_2;
// Timer A0 is used to blink the green led periodically.
TACCTL0 = CCIE; // TACCR0 interrupt enabled
TACCR0 = 120;
TACTL = TASSEL_1 + MC_1 + ID_3 ; // ACLK = VLO/8, upmode

lcd_init(); // Initialize the LCD Module

lcd_string( "LPG Gas Sensor ");

while(1)
{

lcd_line2();
delay(9000);
lcd_string("Temp:");

adc_measure(); // Start Measuring the temperatue and LPG values
delay(9000);
inttostr(temp_array);
lcd_string("'C ");
inttostr(lpg_d);
if(lpg_d > 800 || degc > 80)
{
P4OUT |= 0x03; //BIT0 + BIT1; // Enabled Yellow Led + Buzzer
// Uncomment the next line, when interfacing a relay and a solenoid valve
//P4OUT = BIT3 + BIT4; //
}
//_BIS_SR(LPM0_bits + GIE);
__enable_interrupt();
}
}

// Timer_A0 Interrupt Vector
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A0(void)
{
P1OUT ^= 0x01;; // Toggle P1.0
}

// ADC 12 Interrupt Vector
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR()
{
temp = ADC12MEM0;
lpg_d = ADC12MEM1;
_BIC_SR_IRQ(CPUOFF);
}

void delay (int m)
{
int delay;
delay =m/2; // Change the delay factor based on the oscillator frequency
while(delay>0)
{
delay--;
}
}

void lcd_string(char * str)
{
while(*str)
{
lcd_send_chr(*str++);
}
}

// Converts Integer Value to string, and prints it on LCD
void inttostr(int d)
{
lcd_send_chr(((d/1000) + 48));
lcd_send_chr(((d/100)%10 + 48));
lcd_send_chr(((d/10)%10 + 48));
lcd_send_chr(((d%10) + 48));
}


void enable()
{
delay(160);
P2OUT = !BIT0;
delay(160);
P2OUT = BIT0;
}

// LCD is in 4bit mode, send higher nibble first and then the lower nibble
void lcd_send_chr(char ascii )
{
char d;

d= ascii;
P2OUT |= (d | 0x02);
delay(2265);
enable();
delay(265);
P2OUT |= ((d<<4) | 0x02);
delay(265);
enable();

}

// LCD is in 4bit mode, send higher nibble first and then the lower nibble
void lcd_send_cmd(int cmd)
{
P2OUT = 0x00;
int d;

d = cmd;

P2OUT |= (d & 0xF0);
delay(150);
enable();
P2OUT |= ((d<<4) & 0xF0);
delay(150);
enable();
}

// Initialize the LCD
void lcd_init()
{
delay(600); // Some delay
P2OUT |= 0x30; //
delay(295);
enable();
delay(195);
P2OUT |= 0x30;
delay(195);
enable();
delay(145);
P2OUT |= 0x30;
delay(195);
enable();
delay(195);
P2OUT |= 0x20; // 4bit mode, completes in single cycle
delay(195);
enable();
lcd_send_cmd(0x28); // 4 bit mode
delay(195);;
lcd_send_cmd(0x06); // Entry Mode
delay(195);
lcd_send_cmd(0x08);
delay(195);
lcd_send_cmd(0x0E); // Display On, Cursor On, Blink Off/On
delay(195);
lcd_send_cmd(0x14); // Display shift/Increment
delay(195);
lcd_send_cmd(0x02);// Return to Home Position
delay(280);
lcd_send_cmd(0x01); // Clear Display
delay(195);
}

void adc_measure()
{
ADC12CTL0 = SHT0_8 + REFON + ADC12ON + REF2_5V + MSC; // Internal ref = 2.5V
ADC12CTL1 = SHP + CONSEQ_1; // enable sample timer
ADC12MCTL0 = SREF_1 + INCH_10; // ADC i/p ch A10 = temp sense i/p
ADC12MCTL1 = SREF_1 +INCH_0 +EOS; // ref+=VREF, channel = A0
ADC12IE = 0X002; // ADC_IFG upon conv result-ADCMEMO
ADC12CTL0 |= ENC;
ADC12CTL0 |= ADC12SC; // Sampling and conversion start
i=0;
while(i<150)
{
degc = ((temp*0.6103)-986); // ((temp * (3300/4096))- 986)
degc = (degc / 3.55);

temp_array = temp_array + degc;
i++;
}
temp_array = temp_array/150;
}

nitinmathew2007
06-03-2011, 07:02 PM
Hi...! I don kno wats happening!! I added extra command to send only nibble.
void LCD_command_nibble(unsigned char command)
{
unsigned char temp;
RS = 0;

temp = (command & 0x0f);
PORTB &= 0x00;
PORTB |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
LCD_delay();
LCD_delay();
}

and later used it for initialization i.e,

delay_ms(40);
LCD_command_nibble(0x30);
delay_ms(20);
LCD_command_nibble(0x30);
delay_ms(10);
LCD_command_nibble(0x30);
delay_ms(20);
LCD_command_nibble(0x20);
delay_ms(2);
LCD_command(0x28);
delay_ms(2);
/*LCD_command(0x28);
delay_ms(1);
LCD_command(0x28);
delay_ms(1);*/
LCD_command(0x07);//increment, disp shift
LCD_command(0x0c);//off cursor, display on
LCD_command(0x14);//Display shift,shift to left i.e. scroll
LCD_command(0x02);//Command return the cursor to home
LCD_command(0x01);//clear LCD
delay_ms(1);

__________________________________________________ __________________________________________________ ___


Bt even after that I din get output. So I left the simulation as such without stopping later after some time I found the output running. So out of happiness I stopped it and re run! I din get the o/p again! :(

Later after digging the program and simulation I found that only if I press reset twice or thrice at the star up, I get the output! Can any 1 help me with a solution so that I can complete the program and put it here for future use!!

Thanks.....
Nitin

nitinmathew2007
06-03-2011, 07:18 PM
Sir, Thanks for your program..:)

Nitin

shobhitkukreti
06-03-2011, 09:14 PM
try increasing the delay between the enable 1 and 0

nitinmathew2007
06-03-2011, 09:35 PM
Wooow, I am really happy! I finally spotted the loop hole! Thanks a lot Shobhit sir...

I referred to Mr.BradC's reply on http://forums.parallax.com/showthread.php?103834-16x2-LCD-woes-solved
After referring that I took off the void LCD_command_nibble() function and replaced by add the following inside the initialization function:
PORTA=0x00;
RS=0;
EN=1;
PORTA=0b0010;
EN=0;
EN=1;
PORTA=0x00;
EN=0;
EN=1;
PORTA=0b0010;
EN=0;

delay_ms(3);
LCD_command(0x28);
delay_ms(2);

__________________________________________________ ____________

So now I get the output properly. I am pasting the code for 4bit interface below for reference:

#include<htc.h>

#define RS RE0
#define RW RE1
#define EN RE2

void LCD_delay(void)
{
int t;
for(t=0;t<250;t++);
}

void delay_ms(unsigned char delay)
{
unsigned int i,j;
for(i=0;i<=delay;i++)
{
for(j=0;j<=1000;j++);
}
}

void LCD_command_nibble(unsigned char command)
{
unsigned char temp;
RS = 0;

temp = (command & 0x0f);
PORTA &= 0x00;
PORTA |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
LCD_delay();
LCD_delay();
}

void LCD_command(unsigned char command)
{
unsigned char temp;
RS = 0;

// To send MSB part of command
temp = ((command & 0xf0)>>4); //[(0x38 & 0xf0)= 0x30>>4 ==> 0x03]
PORTA &= 0x00;
PORTA |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
LCD_delay();

temp = (command & 0x0f); //[(0x38 & 0x0f)= 0x08 ==> 0x08]
PORTA &= 0x00;
PORTA |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
delay_ms(1);
}

void LCD_data(unsigned char data)
{
unsigned char temp;
RS=1;

temp =((data & 0xf0)>>4);
PORTA &= 0x00;
PORTA |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
LCD_delay();

temp = (data & 0x0f);
PORTA &= 0x00;
PORTA |= temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN = 0;
delay_ms(1);
}

void initialise_LCD(void)
{
ADCON0 = 0x00;//Disable ADC ports
ADCON1 = 0x06;//Disable ADC ports

TRISA = 0x00;
PORTA = 0x00; //DATA or COMMAND i/p to LCD

TRISE = 0x00;
PORTE = 0x00; //CONTROL i/p to LCD

EN=0;
RW=0;

PORTA=0x00;
RS=0;
EN=1;
PORTA=0b0010;
EN=0;
EN=1;
PORTA=0x00;
EN=0;
EN=1;
PORTA=0b0010;
EN=0;

delay_ms(3);
LCD_command(0x28);
delay_ms(2);

LCD_command(0x07);//increment, disp shift
LCD_command(0x0c);//off cursor, display on
LCD_command(0x14);//Display shift,shift to left i.e. scroll
LCD_command(0x02);//Command return the cursor to home
LCD_command(0x01);//clear LCD
delay_ms(1);
}

void clear_LCD()
{
LCD_command(0x01);
delay_ms(1);
}

void display_LCD(char line_number,char position, const char *message)
{
int a;
if(line_number==1)
{
a=0x80+position;
LCD_command(a);
}
else if(line_number==2)
{
a=0xC0+position;
LCD_command(a);
}
while(*message!=0)
{
LCD_data(*message);
delay_ms(15);
message++;
}
}

void main(void)
{
__CONFIG(0x193A);
initialise_LCD();
while(1)
{
display_LCD(1,8,"haaai");
display_LCD(2,10,"NtN");
delay_ms(1);
}
}


__________________________________________________ __________________________________


Sir, I am planning to interface Ultrasonic Sensor And display the distance in meters continuously on LCD.. can u pl help me in it? I hav never used Ultra sonic sensor so far!!

thanks again...:)

---Nitin

shobhitkukreti
06-03-2011, 10:33 PM
There is always a first time for everything. Read the datasheet and get the transfer function from it to convert volts into distance

nitinmathew2007
06-03-2011, 10:39 PM
Ya ok I am starting my work soon. Is there any software to simulate and check sensors?? I don know if such a feature is available in Proteus!

nitinmathew2007
06-04-2011, 10:40 AM
Sir, I have posted my doubt regd sensor under the Sensor section! So pl help me by looking into the following link..!

http://www.roboticsindia.com/showthread.php/3908-Interfacing-ASCII-based-Ultrasonic-Sensor-With-PIC16F877A?p=20847#post20847

Thanks in advance again...:)
--Nitin