-
Notifications
You must be signed in to change notification settings - Fork 2
/
HD44780.c
executable file
·110 lines (97 loc) · 1.83 KB
/
HD44780.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
/*
* HD44780.c - Source file of HD44780 library
* Written by Ercan Ersoy.
*/
#include <xc.h>
#include "HD44780.h"
void lcd_wait(void)
{
__delay_ms(200);
}
void lcd_send_command(unsigned char command)
{
RW = 0;
RS = 0;
ENABLE = 1;
LCD_PORT = command & 0XF0;
ENABLE = 0;
lcd_wait();
ENABLE = 1;
LCD_PORT = (command & 0X0F) << 4;
ENABLE = 0;
lcd_wait();
}
void lcd_send_data(unsigned char data)
{
RW = 0;
RS = 1;
ENABLE = 1;
LCD_PORT = data & 0XF0;
ENABLE = 0;
lcd_wait();
ENABLE = 1;
LCD_PORT = (data & 0X0F) << 4;
ENABLE = 0;
lcd_wait();
}
void lcd_on_off_screen(void)
{
lcd_send_command(OnOffScreen);
}
void lcd_clear(void)
{
lcd_send_command(ClearLCD);
}
void lcd_print(const char *s)
{
lcd_wait();
while(*s)
{
lcd_send_data(*s++);
}
}
void lcd_goto_xy(unsigned char x, unsigned char y)
{
#if ROWS == 2
if (x == 0)
{
lcd_send_command(FirstLine + (y % COLUMNS));
}
else if(x == 1)
{
lcd_send_command(SecondLine + (y % COLUMNS));
}
#elif ROWS == 4
if (x == 0)
{
lcd_send_command(FirstLine + (y % COLUMNS));
}
else if(x == 1)
{
lcd_send_command(SecondLine + (y % COLUMNS));
}
else if(x == 2)
{
lcd_send_command(ThirdLine + (y % COLUMNS));
}
else if(x == 3)
{
lcd_send_command(FourthLine + (y % COLUMNS));
}
#endif
}
void lcd_prepare()
{
RS = 0;
RW = 0;
ENABLE = 0;
__delay_ms(15);
ENABLE = 1;
lcd_send_command(0X02);
__delay_ms(2);
lcd_send_command(DoubleLine);
lcd_send_command(WriteLeft);
lcd_send_command(HideCursor);
lcd_clear();
lcd_send_command(FirstLine);
}