Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

4 Bit LCD interfacing to ARM lpc2148

Status
Not open for further replies.

A.Rashad

Member level 4
Joined
Jul 27, 2011
Messages
69
Helped
6
Reputation
10
Reaction score
5
Trophy points
1,288
Location
Pune
Activity points
1,792

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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*Program for LCD interfacing to ARM Microcontroller */ 
/*Robota Corporation*/  
/*************************************************************************************************/     
        
//Port 1.16-1.23 should be connected do Data pins of LCD(1.16=LSB)
//Port 0.16 should be connected to Rs pin of LCD.
//Port 0.17 should be connected to En pin of LCD.       
        
#include<lpc21xx.h>
#include "lcd.h"
 
 
 
 
 
 
 
/*----------   Initialization of LCD  ----------*/
 
 
  void lcdinit(void)
 
 {      
 
 
                                                     unsigned int j;
        unsigned char commands[]={0x30,0x30,0x30,0x20,0x28,0x08,0x01,0x06,0x0c},i=0;
        IODIR1=0x00ff0000;     //data pins
        IODIR0=0x00030000;      //rs=p0.16,en=p0.17
        IOCLR1=0x00ff0000;  
    
        
 
        while(i<9)
        {
            delay_lcd();
        lcdsendcommand(commands[i]);
    
        i++;
        }
 
 
  
 }
 
 
 
 
/*----------   Delay  for LCD function   ----------*/
 
 
void delay_lcd()
{
    unsigned    int i;
        for(i=0;i<1000;i++);
}
 
 
 
 
 
 
/*----------   Sending Command to LCD   -----------*/
 
void lcdsendcommand(unsigned int cm)
{
 
       cm=cm&&0xF0;            //High Nibble
       cm=cm<<16;
      IOCLR0|=0x00010000;   //RS =0   for Command.
      
 
      IOCLR1|=0x00ff0000;
      IOSET1|=cm;
 
 
      IOSET0|=0x00020000;
      delay_lcd();
      IOCLR0|=0x00020000;
      delay_lcd();
 
 
                                            // Low Nibble
       
       cm=cm&0x0F;
       cm=cm<<4;                            
       cm=cm<<16;
     //IOCLR0|=0x00010000;  //RS =0   for Command.
      
 
    IOCLR1|=0x00ff0000;         // check1 here
      IOSET1|=cm;
 
 
      IOSET0|=0x00020000;
      delay_lcd();
      IOCLR0|=0x00020000;
      delay_lcd();
 
 
 
 
 
 
 
 
 
}
 
 
 
 
 
 
/*----------  Sending character to LCD  ----------*/
 
 
void lcdsendchar(unsigned int ch)
{       
        ch=ch&0xF0;
        ch=ch<<16;
        
        IOSET0|=0x00010000; //RS=1        for Data
 
        IOCLR1|=0x00ff0000;
        IOSET1|=ch;
 
 
        IOSET0|=0x00020000;
        delay_lcd();
        IOCLR0|=0x00020000;
        delay_lcd();
 
 
        ch=ch&0x0F;
        ch=ch<<4;
        ch=ch<<16;
        
    //  IOSET0=0x00010000;  //RS=1        for Data
 
        IOCLR1|=0x00ff0000;
        IOSET1|=ch;
 
 
        IOSET0=0x00020000;
        delay_lcd();
        IOCLR0=0x00020000;
        delay_lcd();
 
 
 }
 
 
 
 
 
/*----------  Sending LCD String  ----------*/
 
 
 
 
void lcdsendstring(unsigned char *name)
{
        while(*name!='\0')
    {
        lcdsendchar(*name);
        name++;
 
    }
 
 
}
 
 
 
 
 
 
/*----------  Sending number to LCD  ----------*/    
 
extern void lcdsendnumber(unsigned int n)
{
     //conversion of HEX to ASCII---simple//
 
 
 
    
        unsigned char a,b,c,d;
        d=n%10;
        n=n/10;   
        c=n%10;                //converting Hex in decimal
        n=n/10;
        b=n%10;
        n=n/10;
        a=n%10;
 
        d+=0x30;
        c+=0x30;                //converting decimal in ASCII.
        b+=0x30;
        a+=0x30;
 
        lcdsendchar(a);
        delay_lcd();
        lcdsendchar(b);
        delay_lcd();
        lcdsendchar(c);
        delay_lcd();
        lcdsendchar(d);
        lcdsendchar(0x41);
 
  
 
}                       
 
 
 
  
/*---------- Setting position of LCD  ----------*/    
 
 void lcdposition(unsigned char LINE,unsigned char pos)
 {
        if(LINE==1)
 
        lcdsendcommand(0x80+pos);
 
        else if(LINE==2)
 
        lcdsendcommand(0xC0+pos);
 }
 
 
 /*---------- Clearing LCD Screen ----------*/
 void lcdclear(void)
 {
 
 
        lcdsendcommand(0x01);
 
 
 }





I need to interface 16x2 lcd to ARM LPC2148 , PLEASE SEE THE ABOVE CODE FUNCTION
lcdinit(); where I am sending commands 0x30,0x30,0x30,0x20,0x28,0x08,0x01,0x06,0x0c
, also check delay_lcd() function,
my LCD showing garbage characters in 4 bit mode , I have done parsing of upper nibble in lcdsendcommand(); and lcdsendchar(); functions...
please suggest..
 
Last edited by a moderator:

You have exactly the same issue like in this thread: https://www.edaboard.com/threads/243315/#post1048704

To solve that, use for first 4 commands (0x30,0x30,0x30,0x20) a different function instead of your lcdsendcommand:

Code:
/*----------   Sending Command to LCD   -----------*/
 
void lcdsend_Highcommand(unsigned int cm)
{
 
       cm=cm&&0xF0;            //High Nibble
       cm=cm<<16;
      IOCLR0|=0x00010000;   //RS =0   for Command.
      
 
      IOCLR1|=0x00ff0000;
      IOSET1|=cm;
 
 
      IOSET0|=0x00020000;
      delay_lcd();
      IOCLR0|=0x00020000;
      delay_lcd();
 
 
       // Low Nibble should not be sent for first 4 commands
}
 

You have exactly the same issue like in this thread: https://www.edaboard.com/threads/243315/#post1048704

To solve that, use for first 4 commands (0x30,0x30,0x30,0x20) a different function instead of your lcdsendcommand:

Code:
/*----------   Sending Command to LCD   -----------*/
 
void lcdsend_Highcommand(unsigned int cm)
{
 
       cm=cm&&0xF0;            //High Nibble
       cm=cm<<16;
      IOCLR0|=0x00010000;   //RS =0   for Command.
      
 
      IOCLR1|=0x00ff0000;
      IOSET1|=cm;
 
 
      IOSET0|=0x00020000;
      delay_lcd();
      IOCLR0|=0x00020000;
      delay_lcd();
 
 
       // Low Nibble should not be sent for first 4 commands
}
hello, i tried by sending first four commands in a different function exactly as you suggested but , it didnt work , i am getting LCD initialize and some data also but that is completely garbage characters.


please suggest
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top