-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlcd1602.c
115 lines (112 loc) · 2.05 KB
/
lcd1602.c
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
#include "lcd1602.h"
static void lcd1602_delay(uint16 p_time)
{
while(p_time--);
}
static void lcd1602_write_cmd(uint8 p_cmd)
{
lcd1602_delay(100);
LCD1602_E=0;
lcd1602_delay(10);
LCD1602_RS=0;
lcd1602_delay(10);
LCD1602_RW=0;
lcd1602_delay(10);
LCD1602_PORT=p_cmd;
lcd1602_delay(10);
LCD1602_E=1;
lcd1602_delay(50);
LCD1602_E=0;
}
static void lcd1602_write_data(uint8 p_data)
{
lcd1602_delay(100);
LCD1602_E=0;
lcd1602_delay(10);
LCD1602_RS=1;
lcd1602_delay(10);
LCD1602_RW=0;
lcd1602_delay(10);
LCD1602_PORT=p_data;
lcd1602_delay(10);
LCD1602_E=1;
lcd1602_delay(50);
LCD1602_E=0;
}
void lcd1602_init()
{
uint8 t_cmd=0x38;
lcd1602_write_cmd(t_cmd);
t_cmd=0x06;
lcd1602_write_cmd(t_cmd);
}
void lcd1602_display_switch(bool p_show_char,bool p_show_cursor,bool p_flash_cursor)
{
uint8 t_cmd=0x08;
if(p_show_char)
{
t_cmd|=0x04;
}
if(p_show_cursor)
{
t_cmd|=0x02;
}
if(p_flash_cursor)
{
t_cmd|=0x01;
}
lcd1602_write_cmd(t_cmd);
}
/*
void lcd1602_cursor_shift(bool p_right)
{
uint8 t_cmd;
if(p_right)
{
t_cmd=0x14;
}
else
{
t_cmd=0x10;
}
lcd1602_write_cmd(t_cmd);
}
*/
void lcd1602_clear()
{
uint8 t_cmd=0x01;
lcd1602_write_cmd(t_cmd);
}
/*
void lcd1602_cursor_return()
{
uint8 t_cmd=0x02;
lcd1602_write_cmd(t_cmd);
}
*/
void lcd1602_char_set(uint8 p_x,uint8 p_y,char p_char)
{
uint8 t_cmd=0x80;
p_x&=0x0f;
p_y&=0x01;
t_cmd|=p_x;
if(p_y)
{
t_cmd|=0x40;
}
lcd1602_write_cmd(t_cmd);
lcd1602_write_data(p_char);
}
void lcd1602_string_set(uint8 p_x,uint8 p_y,const char* p_string)
{
uint8 t_x,t_y;
p_x&=0x0f;
p_y&=0x01;
for(t_y=p_y;t_y<2;t_y++)
{
for(t_x=p_x;t_x<16&&(*p_string)!=0;t_x++)
{
lcd1602_char_set(t_x,t_y,*(p_string++));
}
}
}