Failing to bit-bang parallel mode on an ST7920 (U8g2 works!)

I thought I'd try to manually bit-bang parallel mode on an ST7920 controller with my Arduino Uno because I'm planning to try and set it up with a Z80 microcomputer. Alas, after two evenings I am no closer to working out why my quite simple code doesn't work! Here's the code:

#define RS 0
#define EN 1
#define D0 2

void setup() {

  // Prepare pins for output
  pinMode(RS, OUTPUT);
  pinMode(EN, OUTPUT);
  for (int pin = D0; pin < D0 + 8; pin +=1) {
    pinMode(pin, OUTPUT);
  digitalWrite(EN, LOW);

  // Send some characters
  lcd_send(0, 0x93);
  lcd_send(1, 'A');
  lcd_send(1, ' ');

void lcd_init() {
  lcd_send(0, 0b00110000);  // Basic function set
  lcd_send(0, 0b00110000);  // Basic function set
  lcd_send(0, 0b00001111);  // Set display (display on, cursor on, blink on)
  lcd_send(0, 0b00000001);  // Clear display (wait >1.6 ms after)
  lcd_send(0, 0b00000110);  // Set entry mode
  Serial.println("Done init");

void lcd_send(int lcd_mode, byte data) {
  digitalWrite(RS, lcd_mode);

  for (int pin = D0; pin < D0 + 8; pin +=1) {
    digitalWrite(pin, data & 1);
    data = data >> 1;

  digitalWrite(EN, HIGH);
  digitalWrite(EN, LOW);

Nothing appears on the LCD when I run this code, not even the cursor.

I feel like I must be missing something simple, because the display works perfectly with identical wiring, on the same board, with the following U8g2 code:

#include <U8g2lib.h>

U8G2_ST7920_128X64_1_8080 u8g2(
  /* Rotation */ U8G2_R2,
  /*D0 - D7*/ 2, 3, 4, 5, 6, 7, 8, 9,
  /*EN*/ 1,
  /*CS*/ U8X8_PIN_NONE,
  /*RS*/ 0);

void setup() {

  do {
    u8g2.drawStr(0,20,"Hello World!");
  } while ( u8g2.nextPage() );

I'd appreciate any help - I feel like I've scoured every line of my code, and the datasheet, countless times.

Your "simple code" has no loop() function.

I would avoid digital #0, #1 because they are used by Serial. e.g. wire RS, EN on 10, 11 and test with U8g2 first. EDIT. changed from 9, 10 to avoid data bus pins.

Your code looks about right but I have not tested it.

Oh, you have chosen a very sensible "development" strategy. i.e. start with known library and known wiring.

Life is considerably easier with ST7920 in SPI mode. Less wires !


David, that was it! Moving EN and RS to 12 and 13 made the display work immediately. I suppose the call to Serial.begin and the print statements were disturbing the display's mojo - especially I imagine EN was getting spurious hits.

Rightly noted - I took it out for the forum post, sorry.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.