-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCD.c
More file actions
143 lines (136 loc) · 2.91 KB
/
Copy pathLCD.c
File metadata and controls
143 lines (136 loc) · 2.91 KB
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
/*
* LCD.c
*
* Created on: Jan 17, 2022
* Author: Liam Kain
*/
#include <func.h>
#include <string.h>
#include <stdlib.h>
void writePin(int n, int state){
if(n == 0)
HAL_GPIO_WritePin(GPIOB, D0_Pin, state);
if(n == 1)
HAL_GPIO_WritePin(GPIOB, D1_Pin, state);
if(n == 2)
HAL_GPIO_WritePin(GPIOB, D2_Pin, state);
if(n == 3)
HAL_GPIO_WritePin(GPIOB, D3_Pin, state);
if(n == 4)
HAL_GPIO_WritePin(GPIOB, D4_Pin, state);
if(n == 5)
HAL_GPIO_WritePin(GPIOB, D5_Pin, state);
if(n == 6)
HAL_GPIO_WritePin(GPIOB, D6_Pin, state);
if(n == 7)
HAL_GPIO_WritePin(GPIOB, D7_Pin, state);
if(n == 8)
HAL_GPIO_WritePin(RS_GPIO_Port,RS_Pin,state);
if(n == 9)
HAL_GPIO_WritePin(RW_GPIO_Port,RW_Pin,state);
if(n == 10)
HAL_GPIO_WritePin(E_GPIO_Port,E_Pin,state);
}
void pinSet(int first, int last, int state){
for(int i = first; i <=last; i++){
writePin(i,state);
}
}
void home(){
pinSet(2,10,0);
writePin(1,1);
enable();
}
void enable(){
writePin(10,1);
HAL_Delay(100);
writePin(10,0);
}
void functionSet(int DL,int N,int F){
pinSet(8,11,0);
writePin(7,1);
writePin(4,DL);
writePin(3,N);
writePin(2,F);
enable();
}
void writeByte(uint8_t data){
for(int i = 0; i <=7; i++){
int c = data % 2;
data = data >> 1;
writePin(i,c);
}
enable();
}
void showCursor(int disp, int curs, int blink){
writePin(8,0);
writePin(9,0);
pinSet(4,7,0);
writePin(3,1);
writePin(2,disp);
writePin(1,curs);
writePin(0,blink);
enable();
}
//if curseDir == 1, cursor moves right, if 0, cursor moves left
//if disMove == 1, display moves according to curseDir, if 0, display doesn't move
void setDir(int curseDir, int disMove){
writePin(8,0);
writePin(9,0);
pinSet(3,7,0);
writePin(2,1);
writePin(1,curseDir);
writePin(0,disMove);
enable();
}
void shiftCursor(int isRight){
pinSet(5,9,0);
writePin(4,1);
writePin(3,0);
writePin(2,isRight);
enable();
}
//if DL is 1, 8-bit mode. 0 is 4-bit mode
//if N is 1, 2-line mode. 0 is 1-line mode
//if F is 1, 5x11 dots, 0 is 5x8 dots mode
void clearDisp(){
writePin(8,0);
writePin(9,0);
pinSet(1,9
,0);
writePin(0,1);
enable();
}
void setChar(char c){
writePin(8,1);
writePin(9,0);
writeByte(c);
}
void writeString(const char* s){
int length = strlen(s);
for(int i = 0; i < length; i++){
setChar(s[i]);
}
}
void writeNum(int n){
char out[100];
int length;
int i = 0;
if(n < 0){
out[0] = '-';
i = 1;
}
while(n > 0){
out[i] = (char)(n%10) + '0';
n /= 10;
i++;
length = i;
}
char out2[100];
for(int i = 0;i < length;i++ ){
out2[i] = out[length - i - 1];
}
out2[length] = '\0';
writeString(out2);
}
#include <string.h>