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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
| /*----------------------------------------
File: 1602cd.c
Date:Loser007 May 6, 2018 11:11
----------------------------------------*/
#include <AT89X52.h>
#include "LCD1602.h"
unsigned char code str1[] = "I love 51hei";
unsigned char code str2[] = "www.51hei.com/bbs/";
void main(void)
{
unsigned char l, r;
LCD_Init();
LCD_XY_Show(0, 0, str1);
LCD_XY_Show(1, 0, str2);
while(1)
{
for(l = 0; l < 10; l++)
{
LCD_Flash_Left();
Delay(500);
}
for (r = 0; r < 10; r++)
{
LCD_Flash_Right();
Delay(500);
}
Delay(2000);
}
}
/*----------------------------------------
File: LCD1602.H
Date:Loser007 May 6, 2018 10:40
----------------------------------------*/
#ifndef __LCD1602_H__
#define __LCD1602_H__
#pragma SAVE
#pragma REGPARMS
sbit RS = P2 ^ 7;
sbit RW = P2 ^ 6;
sbit EN = P2 ^ 5;
extern void LCD_Delay();
extern void LCD_W_C(); //Wirte Command IOI
extern void LCD_W_D(); //Wirte Data IO
extern void LCD_EN(); //LCD Enable
extern void LCD_DATA_IO(); //DAta
extern void LCD_Write_Command(); //Wirte Command
extern void LCD_Write_DATA(); //Wirte Data
extern void LCD_Write_Custom(); //Custom Character
extern void LCD_Set_XY (); //Set Cursor
extern void LCD_Custom_Show(); //to Show Custom Character
extern void LCD_Clear(); //Clear screen
extern void LCD_Init(); //init
extern void LCD_Flash(); //
extern void Delay(); //old
extern void LCD_Flash_Right(); // >>
extern void LCD_Flash_Left(); // <<
void Delay(unsigned int n) //old
{
unsigned int i, j;
for (i = n; i > 0; i--)
for (j = 114; j > 0; j--);
}
void LCD_Delay()
{
unsigned int i, j;
for (i = 50; i > 0; i--)
for (j = 114; j > 0; j--);
}
void LCD_W_C()
{
RS = 0;
RW = 0;
}
void LCD_W_D()
{
RS = 1;
RW = 0;
}
void LCD_EN()
{
EN = 1;
LCD_Delay();
EN = 0;
LCD_Delay();
EN = 1;
}
void LCD_DATA_IO(unsigned char DATA_IO)
{
P0 = DATA_IO;
}
void LCD_Write_Command(unsigned char CMD)
{
LCD_W_C();
LCD_DATA_IO(CMD);
LCD_EN();
}
void LCD_Write_DATA(unsigned char DATA)
{
LCD_W_D();
LCD_DATA_IO(DATA);
LCD_EN();
}
void LCD_Write_Custom(unsigned int M, unsigned char S[])
{
char m = 0;
LCD_Write_Command(0x40 + M * 0x08);
for (m = 0; m < 8; m++)
{
LCD_Write_DATA(S[m]);
}
}
void LCD_Set_XY(unsigned int X, unsigned int Y)
{
unsigned char Address;
if (X == 0)
{
Address = 0x80 + Y;
}
if (X == 1)
{
Address = 0xC0 + Y;
}
LCD_Write_Command(Address);
}
void LCD_Custom_Show(unsigned int X, unsigned int Y, unsigned int M)
{
LCD_Set_XY(X, Y);
LCD_Write_DATA(M);
}
void LCD_XY_Show(unsigned X, unsigned Y, unsigned char *Str)
{
LCD_Set_XY(X, Y);
while(*Str)
{
LCD_Write_DATA(*Str);
Str++;
}
}
void LCD_Show(unsigned char *Str)
{
while(*Str)
{
LCD_Write_DATA(*Str);
Str++;
}
}
void LCD_Clear()
{
LCD_Write_Command(0x01);
}
void LCD_Flash_Left()
{
LCD_Write_Command(0x18);
}
void LCD_Flash_Right()
{
LCD_Write_Command(0x1C);
}
void LCD_Init()
{
LCD_Write_Command(0x38);
LCD_Write_Command(0x08);
LCD_Write_Command(0x01);
LCD_Write_Command(0x06);
LCD_Write_Command(0x0c);
}
#endif
|