LCD without LiquidCrystal library

I’m trying to use the LCD1602 Module without the standard liquid crystal library, just sending instructions and data from my UNO board. Here’s the code and the schematic i made.

/*
   Using HD44780 Character LCD Display without LiquidCrystal Library

   Connection List
   HD44780<--> Arduino
   RS     <-->9
   RW     <-->GND
   E      <-->8
   D7     <-->7
   D6     <-->6
   D5     <-->5
   D4     <-->4

   Port D -> Digital pins 0 to 7 ARDUINO
   Port B -> Digital pins 8 to 13 ARDUINO

   DDRD   -> Register that fixes which pins are Inputs or Outputs.
   PORTD  -> Register that sets the value to each Output pin.
*/

#define UC unsigned char
void send_nibble(UC RS, UC DATA);

void setup() {
  DDRD = 0b11110000; //Sets the used pins as OUTPUT
  DDRB = 0b000011;
  delay(15);
  
  send_nibble(0,0b0010); //Sets to 4-bit operation. (Function set)
  delay(5);
  
  send_nibble(0,0b0010);//4-bit operation & 2 lines (Function set)
  send_nibble(0,0b1000);
  
  send_nibble(0,0b0000);//Display on/off control
  send_nibble(0,0b1111);// blink, cursor & display ON
  
  send_nibble(0,0b0000);//Entry mode set
  send_nibble(0,0b0110);//Increment cursor & No display shift
  
  send_nibble(1,0b0100);//H
  send_nibble(1,0b0001);
  delay(500);
  
  send_nibble(1,0b0110);//e
  send_nibble(1,0b0101);
  delay(500);
}

void loop() {}

void send_nibble(UC RS, UC DATA) {
  PORTD = 0b00000000 | (DATA << 4); 
  delay(1);
  PORTB = 0b000000|(RS<<1);   //Set RS
  delay(1);
  PORTB= 0b000001|(RS<<1);    //Sets Enable High to send instruction
  delay(1);
  PORTB = 0b000000|(RS<<1);  //Sets Enable LOW
  delay(1);
  }

I don’t know why, but the screen isn’t displaying anything well. I guess that maybe its because of the sleep() times that I’m introducing maybe some kind of bouncing effects?
I attach here some datasheet and a tutorial that may help:
In the pg.24 of the datasheet you can find the instruction set, and in the pg. 40 some examples:
http://https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwji6-KGpcfuAhWm3eAKHVkqBIoQFjACegQIAxAC&url=https%3A%2F%2Fwww.sparkfun.com%2Fdatasheets%2FLCD%2FHD44780.pdf&usg=AOvVaw076YT-P88DM3oFFvTDUv43
http://http://www.microcontrollerboard.com/lcd.html#LCDsteps

Thanks for the help!

aarch06:
I'm trying to use the LCD1602 Module without the standard liquid crystal library, just sending instructions and data from my UNO board.

So - why? :roll_eyes:


Incidental: Get rid of the connection (wire shown red) between the potentiometer and 5 V - it is a stupid design blunder perpetuated over many years. Removing the connection will make contrast setting easier.

This is just a silly mistake that has become ingrained in hobby (and no doubt, some professional) designs since the "early days". Not connecting it makes contrast setting twice as easy! Using a 1k pot makes it even easier. If using a 10k pot, you can connect both ends to ground.

@Paul__B,

Actually he is using the pot as a variable resistor.
But it is between VO and 5V and not between VO and GND.

So - why? :roll_eyes:

A mystery.

@aarch06,

However it is a perfectly good academic exercise to run proven library code on a proven schematic.

Then attempt to write your own library code as an academic exercise.
You can test each stage of your code against the earlier working code to verify its behaviour.

I guarantee that you can improve upon the Arduino LiquidCrystal code for size and performance.
Which will give you satisfaction.

But you won't get anywhere until you get the hardware schematic correct.

David.

david_prentice:
Actually he is using the pot as a variable resistor.
But it is between VO and 5V and not between VO and GND.

Good pick!

I think you meant to say "it is between 5V and 5V and not between 5V and GND". If indeed, the Fritzing accurately depicts what he is doing.

Have you tested with the LiquidCrystal library to verify that there isn't a wiring issue?

--- bill

Connecting both ends of the contrast potentiometer to 5V would certainly be a wiring issue. :grinning:

Let's see what the next posting brings ...

This topic was automatically closed after 120 days. New replies are no longer allowed.