-
Notifications
You must be signed in to change notification settings - Fork 0
/
clcd.c
71 lines (58 loc) · 1.68 KB
/
clcd.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
#include <xc.h>
#include "clcd.h"
void clcd_write(unsigned char byte, unsigned char mode) // byte -> 'A', 1
{
CLCD_RS = (__bit)mode;
CLCD_DATA_PORT = byte & 0xF0; // 0x41 & 0xF0 : 0x40 : 0100 0000 (RD7 to RD4)
CLCD_EN = HI;
__delay_us(100);
CLCD_EN = LOW;
CLCD_DATA_PORT = (unsigned char)((byte & 0x0F) << 4); // 0x41 & 0x0F : 0000 0001 << 4 = PORTD
CLCD_EN = HI;
__delay_us(100);
CLCD_EN = LOW;
__delay_us(4100); // 4.1msec
}
static void init_display_controller(void)
{
/* Startup Time for the CLCD controller */
__delay_ms(30);
/* The CLCD Startup Sequence */
clcd_write(EIGHT_BIT_MODE, INST_MODE);
__delay_us(4100);
clcd_write(EIGHT_BIT_MODE, INST_MODE);
__delay_us(100);
clcd_write(EIGHT_BIT_MODE, INST_MODE);
__delay_us(1);
clcd_write(FOUR_BIT_MODE, INST_MODE);
__delay_us(100);
clcd_write(TWO_LINES_5x8_4_BIT_MODE, INST_MODE);
__delay_us(100);
clcd_write(CLEAR_DISP_SCREEN, INST_MODE);
__delay_us(500);
clcd_write(DISP_ON_AND_CURSOR_OFF, INST_MODE);
__delay_us(100);
}
void init_clcd(void)
{
/* Setting the CLCD Data Port as Output */
CLCD_DATA_PORT_DDR = 0x00;
/* Setting the RS and EN lines as Output */
CLCD_RS_DDR = 0;
CLCD_EN_DDR = 0;
init_display_controller();
}
void clcd_putch(const char data, unsigned char addr)
{
clcd_write(addr, INST_MODE);
clcd_write(data, DATA_MODE);
}
void clcd_print(const char *str, unsigned char addr)
{
clcd_write(addr, INST_MODE);
while (*str != '\0')
{
clcd_write(*str, DATA_MODE);
str++;
}
}