Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit af4ff2c

Browse files
committed
Added test for 4x16 LCD
1 parent c0262c6 commit af4ff2c

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lcd/lcd_api.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ def move_to(self, cursor_x, cursor_y):
128128
addr = cursor_x & 0x3f
129129
if cursor_y & 1:
130130
addr += 0x40 # Lines 1 & 3 add 0x40
131-
if cursor_y & 2 and self.num_columns == 16:
132-
addr += 0x10 # Lines 3 & 4 add 0x10 for 16 cols and 0x14 for 20 cols
133-
if cursor_y & 2 and self.num_columns == 20:
134-
addr += 0x14
131+
if cursor_y & 2:
132+
if self.num_columns == 16:
133+
addr += 0x10 # Lines 3 & 4 add 0x10 for 16 cols and 0x14 for 20 cols
134+
else:
135+
addr += 0x14
135136
self.hal_write_command(self.LCD_DDRAM | addr)
136137

137138
def putchar(self, char):

test_lcd.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ def test_full_line2(self):
158158
b'Line 4 - 01234567890',
159159
])
160160

161+
def test_simple_4x16(self):
162+
lcd = LcdSim(4, 16)
163+
lcd.putstr('Line 1\n')
164+
lcd.putstr('Line 2\n')
165+
lcd.putstr('Line 3\n')
166+
lcd.putstr('Line 4\n')
167+
self.assertEqual(lcd.display_lines(), [
168+
b'Line 1 ',
169+
b'Line 2 ',
170+
b'Line 3 ',
171+
b'Line 4 ',
172+
])
173+
161174

162175
if __name__ == '__main__':
163176
unittest.main()

0 commit comments

Comments
 (0)