-
Notifications
You must be signed in to change notification settings - Fork 0
/
clcd.c
82 lines (64 loc) · 1.84 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
72
73
74
75
76
77
78
79
80
81
82
/*
* File: clcd.c
* Author: shummu
*
* Created on 24 September, 2023, 5:53 PM
*/
#include <xc.h>
#include "clcd.h"
void clcd_write(unsigned char byte, unsigned char mode)
{ // 0x33 RS = 0
CLCD_RS = (__bit)mode; // RE2
CLCD_DATA_PORT = byte & 0xF0; // PORTD = 0x33
CLCD_EN = HI;
__delay_us(100);
CLCD_EN = LOW;
CLCD_DATA_PORT=(unsigned char)((byte & 0x0F) << 4);
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); // 4100usec = 4.1msec
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) //'A'
{
clcd_write(addr, INST_MODE);
clcd_write(data, DATA_MODE);
}
void clcd_print(const char *str, unsigned char addr)// Hello
{
clcd_write(addr, INST_MODE); //0xC0
while (*str != '\0')
{
clcd_write(*str, DATA_MODE); // H e l l 0
str++;
}
}