-
Notifications
You must be signed in to change notification settings - Fork 0
/
HAL_LCD_I2C_Ctrl.c
140 lines (102 loc) · 2.71 KB
/
HAL_LCD_I2C_Ctrl.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
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
/**
* ---------------------------------------------------------------+
* @desc LCD HD44780 8-bit I/O I2C
* ---------------------------------------------------------------+
*
* @author Filipe Goncalves Bernardo
* @datum 25.02.2024
* @file lcd.h
* @tested not yet
*
* ---------------------------------------------------------------+
*/
#include "lcdlib/util.h"
#include "HAL_LCD_I2C_Ctrl.h"
#include "HAL/HAL_I2C.h"
#include "driverlib/sysctl.h"
void LCDinit(char addr)
{
LCDcommand(addr, LCD_4BIT_MODE | LCD_2_LINES | LCD_FONT_5x10);
LCDdisplayOff(addr);
LCDclear(addr);
SysCtlDelay(SysCtlClockGet() / (5000 * 3)); // Delai d'attente
LCDcommand(addr, LCD_ENTRY_MODE);
LCDdisplayOn(addr);
};
void LCDenablePulse(char addr, char data)
{
I2CWrite(addr, data | LCD_PIN_E);
//delay >450ns, 200us
SysCtlDelay(SysCtlClockGet() / (5000 * 3));
I2CWrite(addr, data & ~LCD_PIN_E);
//delay >450ns
SysCtlDelay(SysCtlClockGet() / (5000 * 3));
};
void LCDcommand(char addr, char cmd)
{
char up_bites = (cmd & 0xF0) & ~LCD_PIN_RS | LCD_PIN_P3;
char low_bites = (cmd << 4) & ~LCD_PIN_RS | LCD_PIN_P3;
I2CWrite(addr, up_bites);
LCDenablePulse(addr, up_bites);
I2CWrite(addr, low_bites);
LCDenablePulse(addr, low_bites);
};
void LCDdata(char addr, char data)
{
char up_bites = (data & 0xF0) |LCD_PIN_RS | LCD_PIN_P3;
char low_bites = (data << 4) |LCD_PIN_RS | LCD_PIN_P3;
I2CWrite(addr, up_bites);
LCDenablePulse(addr, up_bites);
I2CWrite(addr, low_bites);
LCDenablePulse(addr, low_bites);
};
void LCDsetCursor(char addr, char line, char col)
{
char address;
if (line == 0)
address = LCD_LINE_1;
else if (line==1)
address = LCD_LINE_2;
else if (line==2)
address = LCD_LINE_3;
else if (line==3)
address = LCD_LINE_4;
else
address = LCD_LINE_1;
address |= col;
LCDcommand(addr, 0x80 | address);
};
void LCDclear(char addr)
{
LCDcommand(addr, LCD_DISP_CLEAR);
LCDhome(addr);
};
void LCDhome(char addr)
{
LCDcommand(addr, LCD_RETURN_HOME);
};
void LCDcursorBlink(char addr)
{
LCDcommand(addr, LCD_CURSOR_BLINK);
};
void LCDcursorOff(char addr)
{
LCDcommand(addr, LCD_DISP_ON);
};
void LCDcursorOn(char addr)
{
LCDcommand(addr, LCD_CURSOR_ON);
};
void LCDdisplayOff(char addr)
{
LCDcommand(addr, LCD_DISP_OFF);
};
void LCDdisplayOn(char addr)
{
LCDcommand(addr, LCD_DISP_ON);
};
void LCDprint(char addr, char *text) {
while (*text) {
LCDdata(addr, *text++);
}
}