yea first time,,
Code:
//turns watch dog timer off, turn low voltage programming off
#pragma config WDT=OFF, LVP=OFF, DEBUG=ON, MCLRE = OFF
#pragma config OSC = LP
#define _XTAL_FREQ 4000000
#include <p18f4520.h>
#include <delays.h>
//LCD (PortD)
#define E LATDbits.LATD6
#define R_W LATDbits.LATD5
#define RS LATDbits.LATD4
#define LCDdata LATD
#define LCD_PWR LATDbit.LATD7
void command(unsigned char);
void write(unsigned char);
void Nybble(unsigned char);
void init(void);
void PutMessage(const rom char *);
void main()
{
ADCON1 = 0x0F; //make RA0 digital
//data direction registers all 0's mean that all pins are set to output
//all 1's means that all of the pins are set to operate as inputs
TRISA = 0x00;
TRISB = 0x00;
TRISD = 0x00;
init();
PutMessage(" Hello World!");
command(0xc0);
PutMessage(" WELCOME");
while(1);
}
//Write a string to the LCD
void PutMessage(const rom char *Message)
{
const rom char *Pos = Message;
while(*Pos!=0)
write(*Pos++);
}
/**********************************************************/
//4-bit methods for LCD
/**********************************************************/
void command(unsigned char i)
{
RS =0;
R_W =0; //R/W=LOW : Write
Nybble(i>>4); //Send upper 4 bits
Nybble(i); //Send lower 4 bits
Delay1KTCYx(2); //must wait at least 2mS (2*1000*4/1e6 = 8ms used)
}
void write(unsigned char i)
{
RS =1;
R_W =0; //R/W=LOW : Write
Nybble(i>>4); //Send upper 4 bits
Nybble(i); //Send lower 4 bits
Delay1KTCYx(2); //must wait 2mS
}
/**********************************************************/
void Nybble(unsigned char dat)
{
dat &= 0x0f; //clear top bits of dat
LCDdata &= 0xf0; //clear bottom bits of port (interested only in DB7-DB4)
LCDdata |= dat; //or the two and store at port
E = 1;
Delay1TCY(); //enable pulse width >= 300ns (used 4uS)
E = 0; //Clock enable: falling edge
}
/**********************************************************/