Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix the virtual memory of the HD44780 part
In HD44780, the DDRAM has 0x80 bytes (with lines starting at 0x00,
0x40, 0x20, 0x60), while CGRAM has 0x40 bytes. So, the vram should
have 0x80+0x40 bytes with the CGRAM starting at 0x80.
  • Loading branch information
akosthekiss committed Oct 6, 2020
1 parent 5c2ad82 commit 0c445ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions examples/parts/hd44780.c
Expand Up @@ -55,7 +55,7 @@ static void
_hd44780_clear_screen(
hd44780_t *b)
{
memset(b->vram, ' ', 80);
memset(b->vram, ' ', 0x80);
hd44780_set_flag(b, HD44780_FLAG_DIRTY, 1);
avr_raise_irq(b->irq + IRQ_HD44780_ADDR, b->cursor);
}
Expand Down Expand Up @@ -84,14 +84,14 @@ hd44780_kick_cursor(
hd44780_t *b)
{
if (hd44780_get_flag(b, HD44780_FLAG_I_D)) {
if (b->cursor < 79)
if (b->cursor < 0x80-1)
b->cursor++;
else if (b->cursor < 80+64-1)
else if (b->cursor < 0x80+0x40-1)
b->cursor++;
} else {
if (b->cursor < 80 && b->cursor)
if (b->cursor < 0x80 && b->cursor)
b->cursor--;
else if (b->cursor > 80)
else if (b->cursor > 0x80)
b->cursor--;
hd44780_set_flag(b, HD44780_FLAG_DIRTY, 1);
avr_raise_irq(b->irq + IRQ_HD44780_ADDR, b->cursor);
Expand Down Expand Up @@ -139,7 +139,7 @@ hd44780_write_command(
break;
// Set CGRAM address
case 6: // 0 1 ADD ADD ADD ADD ADD ADD ADD
b->cursor = 64 + (b->datapins & 0x3f);
b->cursor = 0x80 + (b->datapins & 0x3f);
break;
// Function set
case 5: { // 0 0 1 DL N F x x
Expand Down Expand Up @@ -246,7 +246,7 @@ hd44780_process_read(
delay = 0; // no raising busy when reading busy !

// low bits are the current cursor
b->readpins = b->cursor < 80 ? b->cursor : b->cursor-64;
b->readpins = b->cursor < 0x80 ? b->cursor : b->cursor-0x80;
int busy = hd44780_get_flag(b, HD44780_FLAG_BUSY);
b->readpins |= busy ? 0x80 : 0;

Expand Down Expand Up @@ -391,4 +391,3 @@ hd44780_init(
printf("LCD: %duS is %d cycles for your AVR\n",
1, (int)avr_usec_to_cycles(avr, 1));
}

4 changes: 2 additions & 2 deletions examples/parts/hd44780.h
Expand Up @@ -98,7 +98,7 @@ typedef struct hd44780_t
int w, h; // width and height of the LCD

uint16_t cursor; // offset in vram
uint8_t vram[80 + 64];
uint8_t vram[0x80 + 0x40];

uint16_t pinstate; // 'actual' LCd data pins (IRQ bit field)
// uint16_t oldstate; /// previous pins
Expand Down Expand Up @@ -134,4 +134,4 @@ hd44780_get_flag(
return (b->flags & (1 << bit)) != 0;
}

#endif
#endif

0 comments on commit 0c445ea

Please sign in to comment.