-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.c
286 lines (235 loc) · 7.1 KB
/
main.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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*
Arduino LiquidCrystal, Print, and Wiring_Digital classes/functions
modified slightly to work with a Microchip PIC18F25K22.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma config FOSC = INTIO67, FCMEN = OFF, IESO = OFF, PLLCFG = OFF //CONFIG1H
#pragma config PWRTEN = OFF, BOREN = OFF, BORV = 250 //CONFIG2L
#pragma config WDTEN = OFF, WDTPS = 32768 //CONFIG2H
#pragma config MCLRE = EXTMCLR, PBADEN = OFF, HFOFST = OFF //CONFIG3H
#pragma config STVREN = ON, LVP = OFF, XINST = OFF //CONFIG4L
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF //CONFIG5L
#pragma config CPB = OFF, CPD = OFF //CONFIG5H
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF //CONFIG6L
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF //CONFIG6H
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF //CONFIG7L
#pragma config EBTRB = OFF //CONFIG7H
#include <xc.h>
#include "plib/delays.h"
#include "LCDhd44780.h"
void twoSecDelay() {
for (int x = 0; x < 200; x++) {
__delay_ms(10);
}
}
void main(void) {
int x;
double y;
uint8_t diamond[8] = {
0b00000,
0b00100,
0b01010,
0b10001,
0b10001,
0b01010,
0b00100,
0b00000
};
uint8_t square[8] = {
0b00000,
0b11111,
0b10001,
0b10001,
0b10001,
0b11111,
0b00000,
0b00000
};
OSCCON = 0x70; //1MHz Internal Oscillator
OSCTUNEbits.PLLEN = 1; //4x PLL
lcdBegin();
while (1) {
//print simple string
lcdClear();
lcdHome();
lcdPrintStr("Print String");
lcdSetCursor(0, 1);
lcdPrintStr("Hello World");
twoSecDelay();
//print simple string
lcdClear();
lcdHome();
lcdPrintStr("Print Char[]");
lcdSetCursor(0, 1);
char str1[] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'};
lcdPrintStr(str1);
twoSecDelay();
//print simple string
lcdClear();
lcdHome();
lcdPrintStr("Print nul Char[]");
lcdSetCursor(0, 1);
char str2[] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '\0'};
lcdPrintStr(str2);
twoSecDelay();
//print simple string
lcdClear();
lcdHome();
lcdPrintStr("Print 1 Char 'W'");
lcdSetCursor(0, 1);
lcdPrintChr('W');
twoSecDelay();
//Cursor
lcdClear();
lcdHome();
lcdPrintStr("Display Cursor");
lcdSetCursor(0, 1);
lcdCursor();
twoSecDelay();
//Cursor
lcdClear();
lcdHome();
lcdPrintStr("Blink Cursor");
lcdSetCursor(0, 1);
lcdBlink();
twoSecDelay();
//Cursor
lcdClear();
lcdHome();
lcdPrintStr("No Blink ");
lcdSetCursor(0, 1);
lcdNoBlink();
twoSecDelay();
//Cursor
lcdClear();
lcdHome();
lcdPrintStr("No Cursor ");
lcdSetCursor(0, 1);
lcdNoCursor();
twoSecDelay();
//print int as decimal
lcdClear();
lcdHome();
lcdPrintStr("Print 123 as DEC");
x = 123;
lcdSetCursor(0, 1);
lcdPrintInt(x, DEC);
twoSecDelay();
//print int as hex
lcdClear();
lcdHome();
lcdPrintStr("Print 123 as HEX");
x = 123;
lcdSetCursor(0, 1);
lcdPrintInt(x, HEX);
twoSecDelay();
//print int as oct
lcdClear();
lcdHome();
lcdPrintStr("Print as 123 OCT");
x = 123;
lcdSetCursor(0, 1);
lcdPrintInt(x, OCT);
twoSecDelay();
//print int as bin
lcdClear();
lcdHome();
lcdPrintStr("Print 123 as BIN");
x = 123;
lcdSetCursor(0, 1);
lcdPrintInt(x, BIN);
twoSecDelay();
//print double with 3 decimal places
lcdClear();
lcdHome();
lcdPrintStr("Prt Dbl 123.456");
y = 123.456;
lcdSetCursor(0, 1);
lcdPrintDbl(y, 3);
lcdPrintStr(" 3 places");
twoSecDelay();
//print double with 2 decimal places
lcdClear();
lcdHome();
lcdPrintStr("Prt Dbl 123.456");
y = 123.456;
lcdSetCursor(0, 1);
lcdPrintDbl(y, 2);
lcdPrintStr(" 2 places");
twoSecDelay();
//print double with 1 decimal places
lcdClear();
lcdHome();
lcdPrintStr("Prt Dbl 123.456");
y = 123.456;
lcdSetCursor(0, 1);
lcdPrintDbl(y, 1);
lcdPrintStr(" 1 places");
twoSecDelay();
//print double with 1 decimal places
lcdClear();
lcdHome();
lcdPrintStr("Prt Dbl -654.321");
y = -654.321;
lcdSetCursor(0, 1);
lcdPrintDbl(y, 3);
twoSecDelay();
//scrolling example
lcdClear();
lcdHome();
lcdPrintStr("Scrolling");
//1sec delay
for (x = 0; x < 100; x++) {
__delay_ms(10);
}
// scroll 16 positions to the right to move it offscreen right:
for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
// scroll one position right:
lcdScrollDisplayRight();
// wait a bit:
for (x = 0; x < 20; x++) {
__delay_ms(10);
}
}
// scroll 16 positions (display length + string length) to the left
// to move it back to center:
for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
// scroll one position left:
lcdScrollDisplayLeft();
// wait a bit:
for (x = 0; x < 20; x++) {
__delay_ms(10);
}
}
twoSecDelay();
//Create Char example
lcdClear();
lcdHome();
lcdPrintStr("Create Chars");
lcdCreateChar(0, diamond);
lcdCreateChar(1, square);
lcdSetCursor(0, 1);
lcdWrite(0);
lcdSetCursor(3, 1);
lcdWrite(1);
lcdSetCursor(6, 1);
lcdWrite(0);
lcdSetCursor(9, 1);
lcdWrite(1);
lcdSetCursor(12, 1);
lcdWrite(0);
lcdSetCursor(15, 1);
lcdWrite(1);
twoSecDelay();
}
}