examples: hd44780 responds on falling edge of E pin
[simavr] / examples / parts / hd44780.c
index 3955050..8fe194c 100644 (file)
@@ -23,7 +23,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "sim_cycle_timers.h"
+#include "sim_time.h"
 
 #include "hd44780.h"
 
@@ -198,7 +198,7 @@ hd44780_process_write(
                if (comp)
                        b->datapins = (b->datapins & 0xf0) | ((b->pinstate >>  IRQ_HD44780_D4) & 0xf);
                else
-                       b->datapins = (b->datapins & 0xf) | ((b->pinstate >>  IRQ_HD44780_D4-4) & 0xf0);
+                       b->datapins = (b->datapins & 0xf) | ((b->pinstate >>  (IRQ_HD44780_D4-4)) & 0xf0);
                write = comp;
                b->flags ^= (1 << HD44780_FLAG_LOWNIBBLE);
        } else {        // 8 bits
@@ -340,8 +340,8 @@ hd44780_pin_changed_hook(
        b->pinstate = (b->pinstate & ~(1 << irq->irq)) | (value << irq->irq);
        int eo = old & (1 << IRQ_HD44780_E);
        int e = b->pinstate & (1 << IRQ_HD44780_E);
-       // on the E pin rising edge, do stuff otherwise just exit
-       if (!eo && e)
+       // on the E pin falling edge, do stuff otherwise just exit
+       if (eo && !e)
                avr_cycle_timer_register(b->avr, 1, _hd44780_process_e_pinchange, b);
 }