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.

Sample Code for a 16x2 LCD for a PIC18F452

Status
Not open for further replies.

siddhesh19

Newbie level 4
Newbie level 4
Joined
Dec 14, 2010
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,339
Hi, can anyone pls post a simple LCD code for me? I just need to know how to show a word in a 2x16 LCD.
BTW, I'm using Microchip PIC18F452!
My Data Pins go to PortB and the command ports of Enable (E) and Register Select (RS) goes to PortD
So,
E = RD7
Rs = RD6

Preferably in Hi-tech PIC C language!

I try the routine provided by them but still doesnt work.

I'hv totally no idea on programming LCD yet.
I need help urgently. Please guys.

Thanks for help anyway!
 

Hi,
I have managed to do my LCD code and the code is as follows :


#include <p18f452.h> /* for TRISB and PORTB declarations */
#include <xlcd.h>
#include <delays.h>

/* Set configuration bits for use with ICD2 / PICDEM2 PLUS Demo Board:
* - set HS oscillator
* - disable watchdog timer
* - disable low voltage programming
*/

#pragma config OSC = XT
#pragma config WDT = OFF
#pragma config LVP = OFF

//void sendCmd(unsigned char Cmd);//write command to lcd
void sendData(unsigned char Ch, unsigned char rs);//write text to lcd
void initializeLCD(void);
void main(void);
void lcddata(char);


//PORTC RC7 RC6 RC5 RC4 RC3 RC2 RC1 RC0 *
//Data Bus D7 D6 D5 D4 D3 D2 D1 D0 *

//PORTD RD6 GROUNDED RD7 *
//controls RS RW E *
//**********************************************************************

#define RS PORTDbits.RD6
#define E PORTDbits.RD7


void sendData(unsigned char Ch,unsigned char rs)

{
LATC = Ch; //send 8-bit data
RS = rs; //control RS
E = 1; //pulse E
Delay10TCYx (5); //wait 50 us
E = 0;
Delay10TCYx (5); //wait 50 us
return;
}

void initializeLCD(void)

{
Delay1KTCYx (40); //wait 6 ms
sendData (0x30, 0); //send 0x30
Delay1KTCYx (10); //wait 6 ms
sendData (0x30, 0); //send 0x30
Delay1KTCYx (10); //wait 6 ms
sendData (0x30, 0); //send 0x30
Delay1KTCYx (10); //wait 6 ms
sendData (0x38, 0); //send 0x38
Delay10TCYx (8); //wait 50 us
sendData (0x01, 0); //send 0x01
Delay1KTCYx (5); //wait 2 ms
sendData (0x0C, 0); //send 0x0C
Delay10TCYx (8); //wait 50 us
sendData (0x06, 0); //send 0x06
Delay10TCYx (8); //wait 50 us
return;


}
void main()
{
// CMCON=0x07;//RA),1,2,as input/output
unsigned char a=0;
TRISDbits.TRISD6=0;//set output;
TRISDbits.TRISD7=0;//set output;
TRISC=0;

initializeLCD();
sendData('C',1);
sendData('O',1);
sendData('R',1);
sendData('R',1);
sendData('E',1);
sendData('L',1);
sendData('A',1);
sendData('T',1);
sendData('I',1);
sendData('O',1);
sendData('N',1);
sendData(' ',1);
sendData('I',1);
sendData('S',1);
sendData(' ',1);
while(1);
}

But now I'm stuck at a stage where I need 2 do CORRELATION of 2 sample waves and show the value of Time Delay on the LCD.
I have done the CORRELATION code in separate and it works properly but I'm facing problems when I add my Correlation code in the LCD code. :(
That's my Correlation Code:
#include<p18f452f.h>
#include<mathf.h>
#include<stdio.h>
#include<stdlib.h>
#include<xlcd2.h>
#include<delays.h>
#include<usart.h>

void DelayFor18TCY(void)
{
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
}
void DelayPORXLCD (void)
{
Delay1KTCYx(40);
return;
}
void DelayXLCD(void)
{
Delay1KTCYx(10);
return;
}


void main(void)
{

unsigned char x[]={0,0,0,0,0,0,0,0,0,1,2,3,0,0};
unsigned char y[28]={0,0,0,0,0,0,0,2,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned char Rxy[13];
unsigned char n[13];
unsigned char i,j,k,l;
for(i=0;i<=12;i++)
{ Rxy=0;
for(j=0;j<=13;j++)
{Rxy=Rxy+x[j]*y[i+j];
}
}


for(k=0;k<=6;k++)
{Rxy[k]=l;
Rxy[k]=Rxy[12-k];
Rxy[12-k]=l;
}

OpenXLCD(EIGHT_BIT & LINES_5X7);
putrsXLCD( "CORRELATION IS" );



while( BusyXLCD() );
SetDDRamAddr( 0x12 );

for (i=0;k<=12;k++)
{
WriteDataXLCD(Rxy);
//WriteCmdXLCD(SHIFT_DISP_RIGHT);
}
}

Please can you let me know if you can help ?
PLEASE I NEED HELP ASAP.... :(
 

Basically I need to add the Correlation In my LCD Code:
I need to carry out the following procedure in my LCD code which would then show the Correlation Value on the LCD:
{

unsigned char x[]={0,0,0,0,0,0,0,0,0,1,2,3,0,0};
unsigned char y[28]={0,0,0,0,0,0,0,2,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0};
unsigned char Rxy[13];
unsigned char n[13];
unsigned char i,j,k,l;
for(i=0;i<=12;i++)
{ Rxy=0;
for(j=0;j<=13;j++)
{Rxy=Rxy+x[j]*y[i+j];
}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top