#include<p18f97J60.h>// Include files and definitions for the Processor
#include<xlcd.h>// Include function definitions for the External LCD Library library
#include<delays.h>// Include function definitions for built in Delay routines
/*oi pio kato bibliothikes mporei na sou fanoun xrisimes pio meta ston kodika sou*/
//#include <stdio.h>
//#include <timers.h>
//#include <adc.h>
//#include <math.h>
//#include <stdlib.h> /**********tin aferesa epeidi ekane problima sto itoa. Kanonika auti einai bibliothiki poy exei to idoa mesa tin ebala otan ebla ton ADC kodika Den ipirxe prin. Douleue sosta xvris ayti*/
/*Dilosi Configuration Bits*/
#pragma config WDT=OFF//
#pragma config DEBUG = ON
#pragma config XINST= OFF
#pragma config FOSC=HS
#define DATALCD PORTE
#define dirDATA TRISE
void LCDdata (unsigned char);
void LCDDelay( void );
void lcdcmd(unsigned char);
void stringtoLCD(unsigned char *m);
unsigned char *itoa (unsigned int value) ; //itoa (unsigned int value, unsigned char * string)
//unsigned char dataString[10];
void DelaySTRING(void);
void main(void)
{
unsigned char *biginin;
int i,z,t;
overlay char data[]="HEllOGEO ";
static const char data1[]="18F";
overlay char start[]=" PIC";
unsigned char start1[]="LCD";
unsigned char start2[]="GEO";
unsigned char newlineadd=0x40; // Line 2 addresses are 40h to 4Fh
//OSCCON=0x60;//Internal 4MHZ Oscillator
// ADCON1=0X7F;//Make all ports Digital
OpenXLCD( EIGHT_BIT & LINES_5X7 );// Use 8 bit Data, 5x7 pixel Matrix per character
while( BusyXLCD());// Wait till LCD finishes executing command
WriteCmdXLCD( CURSOR_ON);// Turn cursor ON
WriteCmdXLCD(0x80); // Force curson to the begining of 1st line
while( BusyXLCD() );// Wait till LCD finishes executing command
WriteCmdXLCD( SHIFT_DISP_LEFT );//Shift Cursor Display Left
while( BusyXLCD());// Wait till LCD finishes executing command
putsXLCD(data);// Write the String data to the LCD
WriteCmdXLCD(0b0000110); // 0b0011111
while( BusyXLCD() );
WriteCmdXLCD( 0xC0);// Force curson to the begining of 2nd line
//SetDDRamAddr( newlineadd );
while( BusyXLCD() );
putsXLCD(data1);// Write the String data to the LCD
DelaySTRING();
/*********************Apofasi gia address RAM*****************************/
while( BusyXLCD());// Wait till LCD finishes executing command
WriteCmdXLCD(0b00000001);// Clear Display
while( BusyXLCD() );// Wait till LCD finishes executing command
WriteCmdXLCD( SHIFT_DISP_LEFT );//Shift Cursor Display Left
while( BusyXLCD());// Wait till LCD finishes executing command
putsXLCD(start);// Write the String data to the LCD
while( BusyXLCD() );
//SetDDRamAddr( newlineadd );
while( BusyXLCD() );
putsXLCD(start1);// Write the String data to the LCD
DelaySTRING();
while( BusyXLCD());// Wait till LCD finishes executing command
WriteCmdXLCD(0b00000001);// Clear Display
while( BusyXLCD() );// Wait till LCD finishes executing command
WriteCmdXLCD( SHIFT_DISP_LEFT );//Shift Cursor Display Left
while( BusyXLCD());// Wait till LCD finishes executing command
putsXLCD(start2);// Write the String data to the LCD
DelaySTRING();
while( BusyXLCD() );
/*********************************************/
// SetDDRamAddr( newlineadd );
while( BusyXLCD() );
while(1);// Wait here
}
// As indicated in the C18 libraries manual
// These delays are required for LCD operation
/****************************************************************/
// DelayFor18TCY =18 cycles.
/****************************************************************/
void LCDdata (unsigned char value)
{
BusyXLCD();//busylcd();
TRISE = 0;
DATALCD = value;
RS_PIN=1;
RW_PIN=0;
E_PIN=1;
LCDDelay();
E_PIN=0;
}
void LCDDelay(void)
{
int i=0;
for (i=0;i<250;i++);
}
void stringtoLCD(unsigned char *m)
{
unsigned char i;
i = 0;
while(m[i] != 0)
{
LCDdata(m[i]);
i++;
}
}
void DelayFor18TCY(void)
{
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
}
/****************************************************************/
// DelayPORXLCD =15 ms.
/****************************************************************/
void DelayPORXLCD(void)
{
Delay1KTCYx(15);
}
/****************************************************************/
// DelayXLCD =5 ms.
/****************************************************************/
void DelayXLCD(void)
{
Delay1KTCYx(5);
}
/****************************************************************/
// DelayString =250 ms.
/****************************************************************/
void DelaySTRING(void)
{
Delay1KTCYx(450);
}