Try this with 4 MHz clock. Turn off code optimization. maybe optimization is removing the delay code.
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
| #include<htc.h>
#define _xtal_freq 4000000;
__CONFIG(FOSC_XT & WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON
& LVP_OFF & DEBUG_OFF);
#define ldata PORTD
#define rs RB0
#define rw RB1
#define en RB2
void MSDelay(unsigned int itime);
void lcdcmd(unsigned char value);
void lcddata(unsigned char value);
void main()
{
TRISD = 0x00;
TRISB = 0x00;
MSDelay(250);
lcdcmd(0x38);
MSDelay(250);
lcdcmd(0x0E);
MSDelay(15);
lcdcmd(0x01);
MSDelay(25);
lcdcmd(0x06);
MSDelay(25);
lcdcmd(0x86);
MSDelay(25);
lcddata('M');
MSDelay(25);
lcddata('D');
MSDelay(250);
lcddata('E');
while(1);
}
void lcdcmd(unsigned char value)
{
ldata = value;
rs=0;
rw=0;
en=1;
MSDelay(1);
en=0;
}
void lcddata(unsigned char value)
{
ldata = value;
rs=1;
rw=0;
en=1;
MSDelay(1);
en=0;
}
void MSDelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<72;j++)
} |