1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
| #include <reg51.h>
//Declaring all the control pins
sbit cs1 = P2^0;
sbit cs2 = P2^1;
sbit DI = P2^2; //In some glcds it is known as rs
sbit RW = P2^3;
sbit E = P2^4;
sbit RST = P2^5;
//Declaring variables and functions
unsigned int xcoordinate;
unsigned int ycoordinate;
void Delay(unsigned int itime);
void lcd_initialize();
void lcdcmd(unsigned char bytes);
void lcddata(unsigned char bytes);
void setcursorX(unsigned int position);
void setcursorY(unsigned int position);
void snakemaker(unsigned char *ptrs);
unsigned char initial_snake[15]={0x14, 0x08, 0x3e, 0x08, 0x14,0x14, 0x08, 0x3e, 0x08, 0x14,0x14, 0x08, 0x3e, 0x08, 0x14};
void main()
{
lcd_initialize();
cs1=1;cs2=0;
xcoordinate=0;
ycoordinate=0;
setcursorX(xcoordinate);
setcursorY(ycoordinate);
snakemaker(initial_snake);
Delay(1000000000);
while(1);
}
//Initializes the LCD
void lcd_initialize()
{
cs1=0;
cs2=0;
RST=1;
lcdcmd(0x3E);
lcdcmd(0xB8);
lcdcmd(0x40);
lcdcmd(0xc0);
lcdcmd(0x3F);
}
void lcdcmd(unsigned char bytes)
{
P1=0x00;
DI=0;
RW=0;
P1=bytes;
E=1;
Delay(100);
E=0;
}
void lcddata(unsigned char bytes)
{
P1=0x00;
DI=1;
RW=0;
P1=bytes;
E=1;
Delay(5);
E=0;
}
void snakemaker(unsigned char *ptrs)
{
unsigned int i;
for(i=0;i<15;i++)
{
lcddata(ptrs[i]);
}
}
void setcursorX(unsigned int position)
{
lcdcmd(0xB8+position);
}
void setcursorY(unsigned int position)
{
if(position<64)
{
cs1=1;cs2=0;
lcdcmd(0x40+position);
}
else
{
cs1=0;cs2=1;
position=position-63;
setcursorX(xcoordinate);
lcdcmd(0x40+position);
}
}
void Delay(unsigned int itime)
{
int i;
for(i=0;i<itime;i++)
{
}
} |