-
Notifications
You must be signed in to change notification settings - Fork 0
/
12.LCD.c
156 lines (132 loc) · 3.04 KB
/
12.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
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
/*
12. To interface LCD with ARM processor-- ARM7TDMI/LPC2148. Write and execute
programs in C language for displaying text messages and numbers on LCD.
*/
#include <lpc214x.h>
#include <stdio.h>
//Function prototypes
void lcd_init(void);
void wr_cn(void);
void clr_disp(void);
void delay(unsigned int);
void lcd_com(void);
void wr_dn(void);
void lcd_data(void);
unsigned char temp1;
unsigned long int temp, r = 0;
unsigned char *ptr, disp[] = "ALS,R&D SECTION,", disp1[] = "BENGALURU-58";
int main()
{
IO0DIR = 0x000000FC; //configure o/p lines for lcd
IO0PIN = 0X00000000;
delay(3200); //delay
lcd_init(); //lcd intialisation
delay(3200); //delay
clr_disp(); //clear display
delay(3200); //delay
//........LCD DISPLAY TEST.........//
temp1 = 0x80; //Display starting address of first line 1 th pos
lcd_com();
ptr = disp;
while (*ptr != '\0')
{
temp1 = *ptr;
lcd_data();
ptr++;
}
temp1 = 0xC0; // Display starting address of second line 4 th pos
lcd_com();
ptr = disp1;
while (*ptr != '\0')
{
temp1 = *ptr;
lcd_data();
ptr++;
}
while (1)
;
} //end of main()
// lcd initialisation routine.
void lcd_init(void)
{
temp = 0x30;
wr_cn();
delay(3200);
temp = 0x30;
wr_cn();
delay(3200);
temp = 0x30;
wr_cn();
delay(3200);
temp = 0x20; // change to 4 bit mode from default 8 bit mode
wr_cn();
delay(3200);
// load command for lcd function setting with lcd in 4 bit mode,
// 2 line and 5x7 matrix display
temp1 = 0x28;
lcd_com();
delay(3200);
// load a command for display on, cursor on and blinking off
temp1 = 0x0C;
lcd_com();
delay(800);
// command for cursor increment after data dump
temp1 = 0x06;
lcd_com();
delay(800);
temp1 = 0x80; // set the cursor to beginning of line 1
lcd_com();
delay(800);
}
void lcd_com(void)
{
temp = temp1 & 0xf0;
wr_cn();
temp = temp1 & 0x0f;
temp = temp << 4;
wr_cn();
delay(500);
}
// command nibble o/p routine
void wr_cn(void) //write command reg
{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp; // Assign the value to the PORT lines
IO0CLR = 0x00000004; // clear bit RS = 0
IO0SET = 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008;
}
// data nibble o/p routine
void wr_dn(void) ////write data reg
{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp; // Assign the value to the PORT lines
IO0SET = 0x00000004; // set bit RS = 1
IO0SET = 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008;
}
// data o/p routine which also outputs high nibble first
// and lower nibble next
void lcd_data(void)
{
temp = temp1 & 0xf0;
wr_dn();
temp = temp1 & 0x0f;
temp = temp << 4;
wr_dn();
delay(100);
}
void clr_disp(void)
{
// command to clear lcd display
temp1 = 0x01;
lcd_com();
delay(500);
}
void delay(unsigned int r1)
{
for (r = 0; r < r1; r++)
;
}