Here is the code for pic18f4580
Code C - [expand] |
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
| #include <stdio.h>
#include <stdlib.h>
#include<pic18f4580.h>
/*
#define RS RB6
#define EN RB7
#define D0 RC0
#define D1 RC1
#define D2 RC2
#define D3 RC3
#define D4 RC4
#define D5 RC5
#define D6 RC6
#define D7 RC7
*/
#include "lcdtest2.h"
void main()
{
int i;
//char str;
TRISB = 0x00;
TRISC = 0x00;
Lcd8_Init();
while(1)
{
Lcd8_Set_Cursor(1,1);
//str="ecosense";
//Lcd8_Write_String(str);
Lcd8_Write_String("ecosense");
for(i=0;i<15;i++)
{
MSDelay(100);
Lcd8_Shift_Left();
}
for(i=0;i<15;i++)
{
MSDelay(100);
Lcd8_Shift_Right();
}
Lcd8_Clear();
Lcd8_Set_Cursor(2,1);
Lcd8_Write_Char('e');
Lcd8_Write_Char('S');
MSDelay(2000);
}
}
here is the header file:
#ifndef LCDTEST2_H
#define LCDTEST2_H
#include<string.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* LCDTEST2_H */
#ifndef D0
#define D0 PORTBbits.RB0
#define D1 PORTBbits.RB1
#define D2 PORTBbits.RB2
#define D3 PORTBbits.RB3
#define D4 PORTBbits.RB4
#define D5 PORTBbits.RB5
#define D6 PORTBbits.RB6
#define D7 PORTBbits.RB7
#endif
#define RS PORTCbits.RC0
#define EN PORTCbits.RC1
//LCD 8 Bit Interfacing Functions
void MSDelay(unsigned int itime)
{
int i,j;
for(i=0;i<itime;i++)
for(j=0;j<165;j++);
}
void Lcd8_Port(char a)
{
if(a & 1)
D0= 1;
else
D0= 0;
if(a & 2)
D1= 1;
else
D1= 0;
if(a & 4)
D2= 1;
else
D2= 0;
if(a & 8)
D3= 1;
else
D3= 0;
if(a & 16)
D4= 1;
else
D4= 0;
if(a & 32)
D5= 1;
else
D5= 0;
if(a & 64)
D6= 1;
else
D6= 0;
if(a & 128)
D7= 1;
else
D7= 0;
}
void Lcd8_Cmd(char a)
{
RS= 0; // => RS = 0
Lcd8_Port(a); //Data transfer
EN = 1; // => E = 1
MSDelay(5);
EN = 0; // => E = 0
}
Lcd8_Clear()
{
Lcd8_Cmd(1);
}
void Lcd8_Set_Cursor(char a, char b)
{
if(a == 1)
Lcd8_Cmd(0x80 + b);
else if(a == 2)
Lcd8_Cmd(0xC0 + b);
}
void Lcd8_Init()
{
Lcd8_Port(0x00);
RS = 0;
MSDelay(25);
///////////// Reset process from datasheet /////////
Lcd8_Cmd(0x30);
MSDelay(5);
Lcd8_Cmd(0x30);
MSDelay(15);
Lcd8_Cmd(0x30);
/////////////////////////////////////////////////////
Lcd8_Cmd(0x38); //function set
Lcd8_Cmd(0x0C); //display on,cursor off,blink off
Lcd8_Cmd(0x01); //clear display
Lcd8_Cmd(0x06); //entry mode, set increment
}
void Lcd8_Write_Char(char a)
{
RS= 1; // => RS = 1
Lcd8_Port(a); //Data transfer
EN = 1; // => E = 1
MSDelay(4);
EN = 0; // => E = 04
}
void Lcd8_Write_String(char *a)
{
int i;
for(i=0;a[i]!='\0';i++)
Lcd8_Write_Char(a[i]);
}
void Lcd8_Shift_Right()
{
Lcd8_Cmd(0x1C);
}
void Lcd8_Shift_Left()
{
Lcd8_Cmd(0x18);
}
//End LCD 8 Bit Interfacing Functions |
Warning:
lcdtest2.c:42: warning: (359) illegal conversion between pointer types
Last edited by a moderator: