/**********************************************************************************************
|========================================================|
|RS RW D7 D6 D5 D4 D3 D2 D1 D0 |
|========================================================|
Clear Display |0 0 0 0 0 0 0 0 0 1 |
Home |0 0 0 0 0 0 0 0 1 * |
Entery Mode Set |0 0 0 0 0 0 0 1 I/D S |I/D=1 Increment; S=1 Display Shift;
Display On/Off |0 0 0 0 0 0 1 D C B |D=1 Display On; C=1 Cursor On; B=1 Cursor Blink
Cursor/Display Shift |0 0 0 0 0 1 S/C R/L * * |S/C=1 Shift Display; S/C=0 Move Cursor; R/L=1 Shift Right
Functoin Set |0 0 0 0 1 DL N F * * |DL=1 8-Bit; N=1 2-lines; F=1 5*10 Dots;
Set CGRAM Add |0 0 0 1 CG5 CG4 CG3 CG2 CG1 CG0 |
Set DDRAM Add |0 0 1 DD6 DD5 DD4 DD3 DD2 DD1 DD0 |
Read Busy Flag |0 1 BF AC6 AC5 AC4 AC3 AC2 AC1 AC0 |BF=1 Internal Operation Going
Write |1 0 ***** W R I T E D A T A********|
Read |1 1 ********* R E A D D A T A***********|
|========================================================|
38H Function set (8-bit interface, 2 lines, 5*7 Pixels)
3CH Function set (8-bit interface, 2 lines, 5*10 Pixels)
30H Function set (8-bit interface, 1 line, 5*7 Pixels)
28H Function set (4-bit interface, 2 lines, 5*7 Pixels)
20H Function set (4-bit interface, 1 line, 5*7 Pixels)
04H Entry mode set(Decrement AC, Display Shift Off)
05H Entry mode set(Decrement AC, Display Shift On)
06H Entry mode set(Increment AC, Display Shift Off)
07H Entry mode set(Increment AC, Display Shift On)
1EH Scroll display one character right (all lines)
18H Scroll display one character left (all lines)
10H Move cursor one character left
14H Move cursor one character right
0EH Turn on visible underline cursor
0FH Turn on visible blinking-block cursor
0CH Make cursor invisible
08H Blank the display (without clearing)
0CH Restore the display (with cursor hidden)
01H Clear Screen
02H Home (move cursor to top/left character position)
80H +Address Set cursor position (DDRAM address)
40H +Address Set pointer in character-generator RAM (CG RAM address)
**********************************************************************************************/
#include<reg51.h>
#include<intrins.h>
#include<stdlib.h>
#include "Delay.h"
#define LCD P0
#define Putc WriteData
#define ROWS 4
#define COLUMNS 20
#define CGRAM_ADDR 0x40
sbit BKLT = P1^0;
sbit RS = P1^1;//P3^6;
sbit RW = P1^2;
sbit ELCD = P1^3;
int Delay;
int StrCntr;
void CustomName(void);
void asc_2_dec(long);
/****************************************/
void WriteControl(unsigned char d)
{
RS = 0;
RW = 0;
ELCD = 0;
_nop_();//Added Sajjad
LCD = d;
ELCD = 1;
_nop_();//Added Sajjad
for(Delay=0; Delay<500; Delay++);//Added Sajjad
ELCD = 0;
RW = 1;
//for(Delay=0; Delay<500; Delay++);//200
}
void WriteData (unsigned char d)
{
RS = 1;
ELCD = 0;
_nop_();//Added Sajjad
RW = 0;
LCD = d;
ELCD = 1;
_nop_();//Added Sajjad
for(Delay=0; Delay<500; Delay++);//Added Sajjad
ELCD = 0;
RW = 1;
//for(Delay=0; Delay<200; Delay++); //60
}
void InitDisp()
{
WriteControl(0x38); //(8-bit interface, 2 lines, 5*7 Pixels)
WriteControl(0x38);
WriteControl(0x38);
WriteControl(0x06); //(Increment AC, Display Shift Off)
WriteControl(0x0C); //Make cursor invisible
}
void LCDClear (void)
{
WriteControl(0x01);
}
void LCDCursor (char r, char c)
{
switch (r)
{
case 1: WriteControl(0x80 + c - 1); break;
case 2: WriteControl(0xc0 + c - 1); break;
case 3: WriteControl(0x94 + c - 1); break;
case 4: WriteControl(0xd4 + c - 1); break;
default: break;
}
}
void PutStr (char *s)
{
StrCntr = 0;
while (s[StrCntr])
WriteData(s[StrCntr++]);
}
void ClearLine(int LineNumber)
{
int p;
for (p=1; p<=COLUMNS; p++) {
LCDCursor(LineNumber,p);
Putc(' ');
}
}
void ClearColumn(int ColumnNumber) {
int p;
for (p=1; p<=ROWS; p++) {
LCDCursor(p,ColumnNumber);
Putc(' ');
}
}
/*****************************************************************************
*
* lcd_move_right()
*
*****************************************************************************/
static void lcd_move_right(char *s, int LineNo)
{
unsigned char column;
for(column = 1; column <= 20; column++)
{
LCDCursor(LineNo,column-1);
Putc(' ');
LCDCursor(LineNo,column);
PutStr(s);
delay_ms(100);
}
}
/*****************************************************************************
*
* lcd_move_left()
*
*****************************************************************************/
static void lcd_move_left(char *s, int LineNo)
{
unsigned char column;
for(column = 20; column>=1; column--)
{
LCDCursor(LineNo,column+7);//6=length
Putc(' ');
LCDCursor(LineNo,column);
PutStr(s);
delay_ms(100);//Added
}
}
void main(void)
{
InitDisp();
LCDClear();
PutStr("Sajjad Hussain");
LCDCursor(2,1);
PutStr("ICCC");
P2 = 0x55;
P3 = 0x55;
while(1);
}
/*
void main(void)
{
unsigned char tl0;
unsigned char th0;
unsigned int r;
unsigned char *ptr;
unsigned char buff[10];
unsigned char buffer[10];
//long tot_count;
unsigned char msg[] = {"Hello!"};
unsigned char *s;
unsigned char *d;
tl0 = 65;
th0 = 66;
r = 50;
InitDisp();
LCDClear();
//tot_count = r*65536 + th0*256 + tl0;
//asc_2_dec(tot_count);
buff[0] = 'S';
ptr = 0x0000;
*ptr = 'a';
ptr++;
*ptr = 'b';
ptr++;
*ptr = 'c';
ptr++;
*ptr = 'd';
ptr++;
*ptr = 'e';
Putc(*ptr);
ptr--;
Putc(*ptr);
ptr--;
Putc(*ptr);
ptr--;
Putc(*ptr);
ptr--;
Putc(*ptr);
while(1);
}
*/
void asc_2_dec(long num)
{
char R,i;
char Buffer[10];
unsigned char Index;
long Q;
Q = num;
Index = 0;
while(Q>0)
{
Q = num / 10;
R = num % 10;
Buffer[Index++] = R;
num = Q;
}
for(i=(Index-1);i>=0;i--)
Putc(Buffer[i]+48);
}
void CustomName(void)
{
//1
WriteControl(0x40); //Set CGRAM Address
WriteData(0x00); //Patter R0W1
WriteData(0x01); //Patter R0W2
WriteData(0x00); //Patter R0W3
WriteData(0x00); //Patter R0W4
WriteData(0x00); //Patter R0W5
WriteData(0x00); //Patter R0W6
WriteData(0x07); //Patter R0W7
WriteData(0x00); //Patter R0W8
LCDCursor(2,10); //Gotoxy Set DDRAM Address
WriteData(0x00); //Display the Custom Character No 0
//2
WriteControl(0x48); //Set CGRAM Address
WriteData(0x00); //Patter R0W1
WriteData(0x00); //Patter R0W2
WriteData(0x18); //Patter R0W3
WriteData(0x04); //Patter R0W4
WriteData(0x04); //Patter R0W5
WriteData(0x04); //Patter R0W6
WriteData(0x18); //Patter R0W7
WriteData(0x00); //Patter R0W8
LCDCursor(2,11); //Gotoxy Set DDRAM Address
WriteData(0x01); //Display the Custom Character No 2
//3
WriteControl(0x50); //Set CGRAM Address
WriteData(0x04); //Patter R0W1
WriteData(0x04); //Patter R0W2
WriteData(0x04); //Patter R0W3
WriteData(0x04); //Patter R0W4
WriteData(0x04); //Patter R0W5
WriteData(0x04); //Patter R0W6
WriteData(0x03); //Patter R0W7
WriteData(0x00); //Patter R0W8
LCDCursor(2,12); //Set DDRAM Address
WriteData(0x02); //Display the Custom Character No 3
//4
WriteControl(0x58); //Set CGRAM Address
WriteData(0x00); //Patter R0W1
WriteData(0x00); //Patter R0W2
WriteData(0x00); //Patter R0W3
WriteData(0x01); //Patter R0W4
WriteData(0x03); //Patter R0W