LCD library

Help!!!!

I wanted to make a simple sketch to drive the LCD 2x16. I just wanted to move the cursor or make any ASCII command to print character without including the library? I other words I don't want to use the library I want to make my own a very simple one... Anyone please give me something to start to... Thanks a lot in advance!

Open up the library files and strip out the un-needed stuff, or remove the bits you need and implement your own function.
Would be easier to improve/modify the library to your own needs.
Or download the datasheet for the LCD and you can see what you need to control it.
If you have no LCD experience, read the data sheet and match what is going on in the library.

I wanted to make a simple sketch to drive the LCD 2x16. I just wanted to move the cursor or make any ASCII command to print character without including the library? I other words I don't want to use the library I want to make my own a very simple one... Anyone please give me something to start to... Thanks a lot in advance!

pYro_65 has outlined the options pretty well. How you proceed depends on your programming experience and your familiarity with the LCD controller. Don't overlook the fact that you can implement your own functions while still using the library to do the hard part, the initialization. After you have your own functions working you will be in a better position to implement your plan to replace the entire library.

Don

I'm totally new to this Arduino. My only experience in programming was when I took the introduction to C++ last year. I do have Arduino UNO and LCD and I have tested it already. I used the LCD library, and my LCD is working properly with the 4bits. I kinda understand what the library is doing. My problem is how to initialize the LCD without including the .h. Can I do this?

int d7Pin = 7;
int d6Pin = 6;
int d5Pin = 5;
int d4Pin = 4;
int enPin = 3;
int rsPin = 2;

void setup()
{
pinMode(d7Pin, OUTPUT);
pinMode(d6Pin, OUTPUT);
pinMode(d5Pin, OUTPUT);
pinMode(d4Pin, OUTPUT);
pinMode(enPin, OUTPUT);
pinMode(rsPin, OUTPUT);

}

I kinda understand what the library is doing.

I don't think so....

The 'code' that you have shown is dealing with setting up the I/O pins of the Arduino, it does nothing to or for the LCD.

You might want to follow the LCD Initialization link at http://web.alfredstate.edu/weimandn. The information there outlines what has to be done to initialize the LCD module regardless of the processor or programming language that is used to accomplish that initialization.

Don

yes you can.
the datasheet for the LCD controller will contain the available operations and their bit patterns you have to send.

I have just finished my first library for a 128x64 LCD so I'll tell you this now, if you haven't used an LCD before and understand the concepts, creating a library from the datasheet is very challenging and time consuming. I recommend using the library you have, then when you have more experience, create your own.

On the other hand, if you have the time, strong coffee, and the datasheet go for it.

to pyro_65

My goal for today is to initialize the LCD and print just a character or move cursor. I am reading the datasheet. I compare it to the library
what are these?

define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08

What is this numbe? 0x01

to pyro_65

Sorry, I'm not pYro_65 so you don't have to read any further if you think I don't know what I am talking about.

I am reading the datasheet.

Which datasheet? If it is the more or less official Hitachi datasheet dated 99.9 on the first page and 1998 on the last page then you want to look at Table 6 on page 24. If you have a different datasheet then search around for the 'Instructions'.

Look at the first instruction 'Clear Display' then look at the binary numbers DB7 --- DB0 and you will find 0 0 0 0 0 0 0 1 which is 0x01
The other values in your list are determined the same way.

Don

floresta is on the money with the hex values representing the bit patterns.
to make things easier for me to compare with the data sheet I used the B macros to expose the bits.

I defined the instructions like this code below. Very easy to match with datasheet instruction tables.
My display is in 8 bit mode so each bit is a different pin of the set DB0-DB7 ( right to left )

  #define ST7920_CMD_CLEAR       B00000001  //   0x01 - Clear Display
  
  #define ST7920_CMD_HOME        B00000010  //   0x02 - Move Cursor Home
  
  #define ST7920_CMD_EM          B00000100  //   0x04 - Entry Mode Base
  #define ST7920_CMD_EM_INCRR    B00000010  //   0x02 - Increment Cursor Right
  #define ST7920_CMD_EM_INCRL    B00000000  //   0x00 - Increment Cursor Left
  #define ST7920_CMD_EM_SHFTR    B00000011  //   0x03 - Shift Display Right
  #define ST7920_CMD_EM_SHFTL    B00000001  //   0x01 - Shift Display Left

And the 0x1 is a number in base 16 rather than decimal ( base 10 )

0x specifies a hexadecimal number

I understand this concept a bit now :slight_smile: at Table 6 on page 24 Hitachi datasheet.
@ floresta
I know the code really did nothing i already test it.
I am reading this site http://web.alfredstate.edu/weimandn.
I hope this will make sense to a newbie like me :slight_smile:

Is there a very simple code to initialize the LCD?

PLS HEPL!

Is there anyone has the code to initialize LCD at 4bit?

Is there anyone has the code to initialize LCD at 4bit?

It's right there inside the LiquidCrystal library. All you have to do is copy the code from there and then see how it relates to the information at the link I posted earlier. It doesn't correlate exactly but it is very close.

Don