; sample2.asm ; OUT ports #define PORT_CONTROL $E ; 1110 - bit 0 is low #define PORT_LCD $D ; 1101 - bit 1 is low ; Bit flags in LCDCONTROL port #define LCD_REG_COMMAND $0 #define LCD_REG_DATA $2 ; memory locations #define LCD_NIBBLE_COUNT $00A #define LCD_CONTROL_STATE $00E #define RETURN_ADDRESS $00F next0: ; ===== Text Output: 8 letters, 16 nibbles ===== ; === Incremental size: 91 bytes of program space for every 16 nibbles sent ==== ; === Assuming a DJZ instruction existed, it could reduce the incremental size to 76 bytes of program space for every 16 nibbles sent ==== ; prepare to send LCD character data lit #LCD_REG_DATA st LCD_CONTROL_STATE ; remember where to return lit #1 st RETURN_ADDRESS ; initialize the nibble count lit #0 st LCD_NIBBLE_COUNT out1: svc #<'N',lcd_write_nibble svc #>'N',lcd_write_nibble svc #<'i',lcd_write_nibble svc #>'i',lcd_write_nibble svc #<'b',lcd_write_nibble svc #>'b',lcd_write_nibble svc #<'b',lcd_write_nibble svc #>'b',lcd_write_nibble svc #<'l',lcd_write_nibble svc #>'l',lcd_write_nibble svc #<'e',lcd_write_nibble svc #>'e',lcd_write_nibble svc #<'r',lcd_write_nibble svc #>'r',lcd_write_nibble svc #<'!',lcd_write_nibble svc #>'!',lcd_write_nibble next1: ; increment the nibble count ld LCD_NIBBLE_COUNT addi #1 st LCD_NIBBLE_COUNT ; do the next nibble addi #-1 jz out1+2 addi #-1 jz out1+4 addi #-1 jz out1+6 addi #-1 jz out1+8 addi #-1 jz out1+10 addi #-1 jz out1+12 addi #-1 jz out1+14 addi #-1 jz out1+16 addi #-1 jz out1+18 addi #-1 jz out1+20 addi #-1 jz out1+22 addi #-1 jz out1+24 addi #-1 jz out1+26 addi #-1 jz out1+28 addi #-1 jz out1+30 ; program continues here... next2: next3: next4: next5: next6: next7: next8: next9: next10: next11: next12: next13: next14: next15: ; ===== LCD Routines ===== ; === Fixed size: 63 bytes of program space === lcd_write_nibble: out #PORT_LCD ld LCD_CONTROL_STATE out #PORT_CONTROL ; setup RS _ori #1 ; set bit 1 (E) out #PORT_CONTROL _andi #$E ; clear bit 1 (E) out #PORT_CONTROL ; wait at least 37 us for the LCD lit #12 ; each loop iteration is 6 clocks = 3 us at 2 MHz. Initial count of 12 = 13 iterations = 39 us. - addi #0 addi #-1 jc - ; carry will be clear when result goes negative ; determine the return address + ld RETURN_ADDRESS jz next0 cmpi #1 jz next1 cmpi #2 jz next2 cmpi #3 jz next3 cmpi #4 jz next4 cmpi #5 jz next5 cmpi #6 jz next6 cmpi #7 jz next7 cmpi #8 jz next8 cmpi #9 jz next9 cmpi #10 jz next10 cmpi #11 jz next11 cmpi #12 jz next12 cmpi #13 jz next13 cmpi #14 jz next14 jmp next15