;********************************************************************** ;** Midi Exiter Library 0.15 ** ;********************************************************************** ; ; This file contains the more or less stable subroutines of the ; MIDI Exiter (midiexiter.asm). Files copyrighted by F.J. Kraan ; unless indicated otherwise. When all foreign routines are replaced, ; the set will be released under GPL. ; ;** LCD routines .cseg LCD_EPULSE: ; Create a pulse. Data is transferred sbi LCD_CTRL, LCD_E ; on the descending slope. rcall DELAY5US cbi LCD_CTRL, LCD_E rcall DELAY5US ret LCD_DTWR: ; Initiate a data write sbi LCD_CTRL, LCD_RS rcall LCD_WRITE ; Leave the main part to LCD_WRITE rcall DELAY5MS ret LCD_CMDWR: ; Initiate a command write cbi LCD_CTRL, LCD_RS rcall LCD_WRITE ; Leave the main part to LCD_WRITE sbi LCD_CTRL, LCD_RS rcall DELAY5MS ret LCD_WRITE: ; Perform the transfer cbi LCD_CTRL, LCD_RW ;Set write mode mov nibstore, temp ;Store it for later use andi temp, LCD_DTMSK; Mask of upper nibble out LCD_DATA, temp rcall LCD_EPULSE mov temp, nibstore ;Retrieve the stored value swap temp ;Get the right part andi temp, LCD_DTMSK out LCD_DATA, temp rcall LCD_EPULSE sbi LCD_CTRL, LCD_RW ;Restore to read mode ret LCD_HOME: ldi temp, 0b00000010 ; Set address to 00 rcall LCD_CMDWR ldi temp, 0b00001100 ; Display on, cursor & blink off rcall LCD_CMDWR ret LCD_PRINTAT: ; assumes cursor position is in cursor rcall LCD_HOME ; the second line starts at address 40h mov temp, cursor ori temp, 0x80 ; set the DDRAM command bit rcall LCD_CMDWR ret ; The delay routines are adapted from (c)andreas-s@web.de ;Pause nach jeder Übertragung DELAY5US: ;50us Pause ldi sdelcnt, $84 DELAY5US_: dec sdelcnt brne DELAY5US_ ret ;wieder zurück ;Längere Pause für manche Befehle DELAY5MS: ;5ms Pause ldi ldelcnt, $42 WGLOOP0: ldi sdelcnt, $C9 WGLOOP1: dec sdelcnt brne WGLOOP1 dec ldelcnt brne WGLOOP0 ret ;wieder zurück LCD_INIT: ldi temp, 100 POWERUPWAIT: rcall DELAY5MS ; Step 1 wait dec temp brne POWERUPWAIT ldi temp, 0b00100000 ; Step 2 setting 4-bit operation cbi LCD_CTRL, LCD_RS ; this transfer is cbi LCD_CTRL, LCD_RW ; in 8-bit mode. out LCD_DATA, temp rcall LCD_EPULSE sbi LCD_CTRL, LCD_RW sbi LCD_CTRL, LCD_RS rcall DELAY5MS ldi temp, 0b00101000 ; Step 3 setting 4-bit operation, rcall LCD_CMDWR ; 2-lines, 5x8 dot chars. ldi temp, 0b00001100 ; Step 4 display on, cursor & blink off rcall LCD_CMDWR ldi temp, 0b00000110 ; Step 5 Entry mode set rcall LCD_CMDWR rcall CG_BSDEF rcall CG_COPYDEF ; ldi temp, 'H' ; rcall LCD_DTWR ; ldi temp, 'i' ; rcall LCD_DTWR ret CG_BSDEF: ldi temp, CG_CHAR0 rcall LCD_CMDWR ldi temp, CG_BS0 rcall LCD_DTWR ldi temp, CG_BS1 rcall LCD_DTWR ldi temp, CG_BS2 rcall LCD_DTWR ldi temp, CG_BS3 rcall LCD_DTWR ldi temp, CG_BS4 rcall LCD_DTWR ldi temp, CG_BS5 rcall LCD_DTWR ldi temp, CG_BS6 rcall LCD_DTWR ldi temp, CG_BS7 rcall LCD_DTWR ret CG_COPYDEF: ldi temp, CG_CHAR1 rcall LCD_CMDWR ldi temp, CG_COPY0 rcall LCD_DTWR ldi temp, CG_COPY1 rcall LCD_DTWR ldi temp, CG_COPY2 rcall LCD_DTWR ldi temp, CG_COPY3 rcall LCD_DTWR ldi temp, CG_COPY4 rcall LCD_DTWR ldi temp, CG_COPY5 rcall LCD_DTWR ldi temp, CG_COPY6 rcall LCD_DTWR ldi temp, CG_COPY7 rcall LCD_DTWR ret DISPTXT: out EEAR, txtadr ; Retrieve it sbi EECR, EERE ; from EEPROM in temp, EEDR tst temp ; Check for end of string breq ENDOFTXT ; Goto exit if we're finished rcall LCD_DTWR ; Get it on the display inc txtadr ; Point to next address rjmp DISPTXT ; Again for next char ENDOFTXT: ret BIN2HASC: ; converts a byte value to ASCII hex nop mov nibstore, temp ; converts byte to two ASCII characters rcall NIB2HASC mov hexlsn, temp mov temp, nibstore swap temp rcall NIB2HASC mov hexmsn, temp ret NIB2HASC: ; converts nibble to Ascii value ldi temp2, 0x09 andi temp, 0x0F sub temp2, temp brpl ADD30 ADD37: ; add 37h for values A-F ldi temp2, 0x37 add temp, temp2 ret ADD30: ; add 30h for values 0-9 ldi temp2, 0x30 add temp, temp2 ret ;** Keyboard routine READBUTTON: cbi ButCol, NavCol ; Enable navigation buttons sbi ButCol, FncCol ; Disable function buttons rcall DELAY5US in temp, ButRows ; Read value andi temp, ButMask ; Mask off non button bits mov scanbut,temp ; Store this part swap scanbut ; Swap it to other nibble cbi ButCol, FncCol ; Enable function buttons sbi ButCol, NavCol ; Disable navigation buttons rcall DELAY5US in temp, ButRows ; Read value andi temp, ButMask ; Mask off non button bits or scanbut,temp ; Add it to stored value sbi ButCol, FncCol ; Disable function buttons sbi ButCol, NavCol ; Disable navigation buttons ret ;** Animation on display ;** (not very useful, just visual feedback to keep the audience happy) BUSYCHAR: mov temp, busych subi temp, busych0 breq TOCH1 mov temp, busych subi temp, busych1 breq TOCH2 mov temp, busych subi temp, busych2 breq TOCH3 rjmp TOCH0 TOCH1: ldi busych, busych1 rjmp BUSYPRINT TOCH2: ldi busych, busych2 rjmp BUSYPRINT TOCH3: ldi busych, busych3 rjmp BUSYPRINT TOCH0: ldi busych, busych0 rjmp BUSYPRINT BUSYPRINT: ldi cursor, BUSYPOS rcall LCD_PRINTAT mov temp, busych rcall LCD_DTWR ret