[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Writing to a 16x2 LCD in 4-bit Mode C code

Posted on 2004-08-23
2
Medium Priority
?
1,480 Views
Last Modified: 2008-01-09
Hi I need to use an LCD (16x2) in 4-bit mode. I have found this assembly code and I need to translated to C. This is only to write to the LCD. Below this code I have posted the C code I have translated but it is not working...can anyone help me re-writing this?
DATA is the port use to send data and commands.
///////////////////////////////////////////////////
machine code

WRITE_2_NIBBLES:
 PUSH  ACC           ;Save A for low nibble
 ORL   DATA,#0F0h    ;Bits 4..7 <- 1
 ORL   A,#0Fh        ;Don't affect bits 0-3
 ANL   DATA,A        ;High nibble to display
 SETB  EN
 CLR   EN
 POP   ACC           ;Prepare to send
 SWAP  A             ;...second nibble
 ORL   DATA,#0F0h    ; Bits 4...7 <- 1
 ORL   A,#0Fh       ; Don't affect bits 0...3
 ANL   DATA,A        ;Low nibble to display
 SETB  EN
 CLR   EN
 RET
///////////////////////////////////////////////////////
C Code
static void WriteInstrReg (unsigned char Instr)
{
Ena = 0;                      
RS = 0;              // select instruction register
R_W= 0;            // write operation
Ena = 1;                // give operation start signal
_nop_ (); _nop_ ();        // wait
nibble = 0;
nibble |= Instr;
nibble &= 0xF0;
P2 = nibble;
Ena = 0;
delay1(64000);      // wait for LCD...is busy
nibble = 0;
Ena = 1;
Instr <<= (0x04);
nibble |= Instr;
nibble &= 0xF0;
P2 = nibble;
Ena = 0;
delay1(64000);    // wait for LCD...is busy
}
nibble is an unsigned char.
0
Comment
Question by:caleno
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 150 total points
ID: 11875429
You have not specified what microcontroller you are working on, so I will assume it is 8051 based.
You can search for a ready-made library written in C, take a look to this:
http://www.8051.co.kr/html/development/pdf/cpu_application_note/AtmelWM/ANM069.PDF
It is designed for an Atmel processor with a 4 bit display interface (brand doesn't matters).
Good luck,
Jaime.
0
 

Author Comment

by:caleno
ID: 11884745
Jaime, your assumption is right. The micro is from 8051 family. The Link you posted is very good. It helped a lot

Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question