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.

facing problem in reading data from LCD using LPC2138

Status
Not open for further replies.

abhishekdixit

Full Member level 2
Joined
Dec 30, 2011
Messages
124
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
India
Activity points
2,182
hello,
i am using LPC2138 for interfacing with LCD & i want to read data from LCD. so i am facing problem to take data from data pins in a variableb if anyboady has any example of a reading data from LCD then please help me..
Thanks
with regards,
Abhishek Dixit
 

witch kind of LCD are you using? Are you talking about sniff the lcd data bus pins?
 
Last edited:

hi mgate,
i am using 16X2 alphanumeric LCD. in which i want to read data from the LCD data pins. I have also made the program for making data pins as a input. but the problem is that now i am unable to read the data from that input pins...please help me.
 

Are you using an HD44780 compatible controller?

I've madded a few test on sniffing a HD44780 compatible controller with arduino, I've used ATmega328P because of the 5V ttl ... I've managed to sniff the characters, but I never had opportunity to finish the project... My code is also for a 16X2 characters lcd...

My code is for 8bit write mode, and I'm only monitoring cursor positions change to beginning of first line and of second line, and I'm only refreshing the uart messages on the end of the first and the second line...

Keep in mind that this controller process commands on EN High to Low transition, so you have to attach an interrupt on this pin negative transition to be able to read the respective bus...




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
/******************************************************************************
*
*   Name:   HD44780 Sniffer
*
*   Desc:   HD44780's LCD Packet Sniffer
*
*   Version 0.05
******************************************************************************/
/*****************************************************************************      
*   8-Bit Write Sequence
*   - Make Sure "EN" is 0 or low
*   - Set "R/S" to 0 for a command, or 1 for data/characters
*   - Put the data/command on D7-0
*   - Set "EN" (EN= 1 or High)
*   - Wait At Least 450 ns!!!
*   - Clear "EN" (EN= 0 or Low) // the LCD reads the data on this falling edge
*   - Wait 5ms for command writes, and 200us for data writes.
******************************************************************************/
 
// Define LCD Pins HD44780 -- Note: Respect this Pinout
 
#define PIN_EN  2
 
#define PIN_RS  4
#define PIN_RW  5
 
#define PIN_DB0 6
#define PIN_DB1 7
#define PIN_DB2 8
#define PIN_DB3 9
#define PIN_DB4 10
#define PIN_DB5 11
#define PIN_DB6 12
#define PIN_DB7 13
 
// Define Messages
#define MSG_GO_LINE1    0x80
#define MSG_GO_LINE2    0xC0
#define END_CHAR    0x0D    //ASCII for Carriage RETURN CR
#define SPACE_CHAR  0x20    //ASCII for SPACE
 
// Define Operations
#define IR_Write    0x00    //RW=0 RS=0  -> IR write as an internal operation (display clear, etc.)
#define DR_Write    0x01    //RW=0 RS=1  -> DR write as an internal operation (DR to DDRAM or CGRAM)
#define BUSY_Read   0x02    //RW=1 RS=0  -> Read busy flag (DB7) and address counter (DB0 to DB6)
#define DR_Read     0x03    //RW=1 RS=1  -> DR read as an internal operation (DDRAM or CGRAM to DR)
 
// Declare Global Variables
volatile byte flag_SEND = LOW; // when using shared variables betwin the main routine and ISR routine, must be used volatile variables
 
volatile int CurrPosition = 0;
volatile byte strScreenText[34]; // 32 + '\r' +'\0'
 
 
// Function Prototypes
//void Handle_Char();
//void ISR_EN();
 
// HIGH = 1, LOW = 0
 
void setup()
{
    // Set Pins
    DDRD = B00000010;   // sets Arduino pins (0 and 2 to 7) as inputs, and pin 1 as output
    DDRB = B00000000;   // sets Arduino pins 8 to 13 as inputs
    
    for(int i=0; i<sizeof(strScreenText); i++)
          strScreenText[i] = SPACE_CHAR;        //reset message memory to spaces
    strScreenText[32] =  END_CHAR;              //set end of telegram char
    strScreenText[33] =  0;                 //set end of string null char
 
    Serial.begin(9600); // set up Serial library at 9600 bps
    
    attachInterrupt(0, ISR_EN, FALLING);  // interrupt 0 digital pin 2 connected EN,  The HD44780 latches data on the falling edge on the EN line. Here's a timing diagram from an HD44780 datasheet:
}
 
 
// Main LOOP
void loop()
{
    if (flag_SEND)
    {
        Serial.print((char*)strScreenText);
        
        flag_SEND = LOW; // clear flag
    } 
} // end loop
 
 
 
// EN Interrupt Sub Routine
void ISR_EN()// can't use delay(x) in IRQ routine
{
    byte bPacket = (((PINB & B00111111 ) << 2) | ((PIND & B11000000 ) >> 6));  // Capture Packet
    byte bOperation = ((PIND & B00110000 ) >> 4);                               // Capture Operation
 
    switch(bOperation)  // Hop betwin operations
    {
    case DR_Write:  // -------------------Message is a character write---------------------  RW=0 RS=1
        //bPacket is a character//
 
        if((CurrPosition >= 0) && (CurrPosition < 32))
        {
            strScreenText[CurrPosition] = bPacket; // Store Character;
            CurrPosition++; // Increment position
 
            if( (CurrPosition == 16) || (CurrPosition == 32) ) // Message is complete or refreshed
            {
                flag_SEND = HIGH;
            }
        }
 
        if(CurrPosition > 31) // Message is complete
        {
            CurrPosition = 32;  // avoid memory violation
        }
        break; // --- End of character processing
 
 
    case IR_Write:  // -------------------Message is a write command-----------------------  RW=0 RS=0
        //bPacket is a command//
 
        switch(bPacket) //grab only start of line position set commands
        {
        case MSG_GO_LINE1:
            CurrPosition = 0;
            break;
 
        case MSG_GO_LINE2:
            CurrPosition = 16;
            break;
        default: //Discard Command
            break;
        }
        break; // --- End of command processing
 
 
    case DR_Read:   // -------------------Message is a read request -----------------------  RW=1 RS=1
        break;
 
 
    case BUSY_Read: // -------------------Message is a busy polling -----------------------  RW=1 RS=0
        break;
 
 
    default:        // -------------------This case must never be reached ----------------------------
        break;
    }
}



For dealing with the I/O levels you probably will want to use a bidirectional level shifter or a 5V tolerant buffer
 
Last edited:

hello magte ,
i have shown your code.but after reading this code i am still confusing in reading data from LCD. actually i have made code for reading data from the LCD but my problem is how should i take data from my data pins i want to store to my data in a variable but i am unable to understanding that how should i do that.
please help me
thanks,
 

I see where you are getting... I use bitwise operations to store the full byte into a char variable... You can get a preview on https://en.wikipedia.org/wiki/Bitwise_operation


Code C - [expand]
1
byte bPacket = (((PINB & B00111111 ) << 2) | ((PIND & B11000000 ) >> 6));



If you can post a scheme of the lcd interfacing I can give you a help on this.

Is this the problem?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top