-
Notifications
You must be signed in to change notification settings - Fork 0
/
lcd.c
91 lines (79 loc) · 1.87 KB
/
lcd.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
/*
* File: lcd.c
* Author: True Administrator
*
* Created on July 18, 2016, 12:11 PM
*/
#include <xc.h>
#include "configBits.h"
#include <stdio.h>
#include "lcd.h"
#include "constants.h"
void initLCD(void) {
__delay_ms(15);
lcdInst(0b00110011); //Force into 8bit mode
lcdInst(0b00110011); //Should require only three commands, but
lcdInst(0b00110010); //Seems to be demanding five in this case.
lcdInst(0b00101000);
lcdInst(0b00001100);
lcdInst(0b00000110);
lcdInst(0b00000001);
__delay_ms(15);
}
/*
void initLCD(void) {
__delay_ms(15);
lcdInst(0b00110011); //Force into 8bit mode
lcdInst(0b00110011); //Should require only three commands, but
lcdInst(0b00110010); //Seems to be demanding five in this case.
lcdInst(0b00101000);
lcdInst(0b00001100);
lcdInst(0b00000110);
lcdInst(0b00000001);
__delay_ms(15);
}*/
void lcdInst(char data) {
RS = 0;
lcdNibble(data);
}
void putch(char data){
RS = 1;
lcdNibble(data);
}
void lcdNibble(char data){
// Send of 4 most sig bits, then the 4 least sig bits (MSD,LSD)
char temp = data & 0xF0;
LATD = LATD & 0x0F;
LATD = temp | LATD;
E = 0;
__delay_us(LCD_DELAY);
E = 1;
__delay_us(LCD_DELAY);
data = data << 4;
temp = data & 0xF0;
LATD = LATD & 0x0F;
LATD = temp | LATD;
E = 0;
__delay_us(LCD_DELAY);
E = 1;
__delay_us(LCD_DELAY);
}
/*
void lcdNibble(char data){
// Send of 4 most sig bits, then the 4 least sig bits (MSD,LSD)
char temp = data & 0xF0;
LATD = LATD & 0x0F;
LATD = temp | LATD;
E = 0;
__delay_ms(100);
E = 1;
__delay_ms(200);
data = data << 4;
temp = data & 0xF0;
LATD = LATD & 0x0F;
LATD = temp | LATD;
E = 0;
__delay_ms(100);
E = 1;
__delay_ms(200);
}*/