========================================================== Tomas Pribyl, Apr 19 1999 14:16:05, Prague, Czech Republic LCD display on your C64 IDE2.1 ========================================================== This is description how to connect LCD display to new C64 IDE V2.1 IO bus (SHORT BUS). We will make full support for LCDs into IDE software on your IDE2.1 controller in the future. Use this information at your own risc, incorrectly connected LCD can damage your C64 or IDE2.1 controller or your LCD. If you have any doubt, please refer LCD manual or email to: dundera@volny.cz This description is valid only for LCD displays with HD44780 controller from HITACHI. I have LCD display L1634 from SEIKO (16 chars/4 rows) with LED subillumination, but similar displays can be connected this way too. For example: ------------ From SHARP LM16A21 - 16 x 2, STN LM16X21A - 16 x 2, STN, LED From PICVUE PVC160101BTN - 16 x 1, TN PVC160203BGN - 16 x 2, STN PVC160401AGN - 16 x 4, STN From ???? MC1601 - 16 x 1 MC1602 - 16 x 2 MC1604 - 16 x 4 If you want connect LCD to IDE2.1 controller, you need: - IDE2.1 controller - LCD display based on HD44780 controller from HITACHI - flat cabel, 34 wires - connector for ShortBus - regulated resistor 5kOhm - for subillumination LCDs resistor 100Ohm (see note 2) All LCDs has very simple interface. Pin on LCD Connect to ShortBus description ============================================================================ 1 - GND 1, 34 - GND Ground 2 - Vcc 2, 33 - Vcc +5V 3 - Vo see note 1 Contrast voltage 4 - RS 32 - A0 Adress bit0 5 - R/W 5 - R/W Read/Write signal from processor 6 - E 6 - CS1 Chip select signal, active High 7 - DB0 31 - D0 Data bus, bit 0 8 - DB1 29 - D1 Data bus, bit 1 9 - DB2 27 - D2 Data bus, bit 2 10 - DB3 25 - D3 Data bus, bit 3 11 - DB4 23 - D4 Data bus, bit 4 12 - DB5 21 - D5 Data bus, bit 5 13 - DB6 19 - D6 Data bus, bit 6 14 - DB7 17 - D7 Data bus, bit 7 15 - LED + see note 2 Subillumination + 16 - LED - see note 2 Subillumination - Note 1 Contrast voltage 0 - 5V. Resistor between this pin and GND can drive contrast. | Vo - contrast (pin 3 on LCD) | \ / \<- 5kOhm / | \ | |__| | | GND (pin 1 on LCD) Note 2 Only subilluminated LDCs has this pins. Connect LED - to GND Connect LED with resistor (100 ohm) and this resistor connect to Vcc. Value of resistor depends on LED current, please refer LCD manual. GND Vcc | | | | | \ | / | \ Resistor 100 Ohm (see Note 2) | / | \ | | | | LED - LED + How to program LCDs, connected to IDE2.1 controller: =================================================== LCD registers are on $de44 and $de45 adress location. $de44 ----- write - command register access read - status register $de45 ----- write - store data read - read data Here is list of instructions of my LCD display: Write - $de44 Instruction D7 D6 D5 D4 D3 D2 D1 D0 ============================================== Display clear 0 0 0 0 0 0 0 1 Cursor home 0 0 0 0 0 0 1 * Entry Mode Set 0 0 0 0 0 1 I/D S Display On/Off 0 0 0 0 1 D C B Curs/Disp shift 0 0 0 1 S/C R/L * * Function Set 0 0 1 DL N F * * CG RAM adr set 0 1 ---------Acg--------- DD RAM adr set 1 -------------Add--------- Read - $de44 Instruction D7 D6 D5 D4 D3 D2 D1 D0 ============================================== BF/Adress read BF -------------AC----------- Write - $de45 Instruction D7 D6 D5 D4 D3 D2 D1 D0 ============================================== Write data ------------DATA-------------- Read - $de45 Instruction D7 D6 D5 D4 D3 D2 D1 D0 ============================================== Read data -------------DATA------------- Meaning: * - nonvalid bit Acg - CG RAM adress (CHARACTER GENERATOR) Add - DD RAM adress (DATA DISPLAY) AC - adress counter I/D - 1-increment, 0-decrement S - 1-display shift, 0-no display shift D - 1-display ON, 0-display OFF C - 1-cursor ON, 0-cursor OFF B - 1-blink ON, 0-blink OFF S/C - 1-display shift, 0-cursor movement R/L - 1-right shift, 0-left shift DL - 1-8 bits data transfer, 0-4 bits data transfer N - 1-1/16 duty, 0-1/8 or 1/11 duty F - 1-5x10 dot matrix, 0-5x7 dot matrix BF - 1-internal operation in progress, 0-display ready DISPLAY CLEAR - clears all display and returns cursor to home position (adress 0). Space code ($20) is written into all the adresses of DD RAM, and DD RAM adress 0 is set to the AC. If shifted, the display returns to the original position. After execution of the Display Clear instruction, the entry mode is incremented. Execution time about 1.64ms CURSOR HOME - returns cursor to home position (adress 0). DD RAM adress 0 is set to the AC. The cursor returns to the home position. If shifted, the display returns to the original position. The DD RAM contens do not change. If the cursor or blinking is ON, it returns to the left side. Execution time about 1.64ms ENTRY MODE SET - sets the direction of cursor movement and whether display will be shifted. I/D: The DD RAM adress is incremented or decremented by one when a chracter code is written into or read from DD RAM. This is also true for writting into or reading from CG RAM. I/D = 1, the adress is incremented by one and the cursor or blink moves to the right. I/D = 0, the adress is decremented by one and the cursor or blink moves to the left. S = 1, the entire display is shifted either to the right or left for writing into DD RAM. The cursor position does not change, only display moves. There is no display shift for reading from DD RAM. When S=1 and I/D=1, the display shifts to the left. When S=1 and I/D=0, the display shifts to the right. S = 0, the display does not shift. DISPLAY ON/OFF CONTROL - turn the total display and the cursor ON and OFF, and makes the cursor position start blinking. Cursor ON/OFF and blinikng is done at the column indicated bz the specified DD RAM adress by the AC. D: D = 1, the display is turned ON. D = 0, the display is turned OFF. If D=0 is used, display data remains in DD RAM. Change 0 to 1 to display data. C: C = 1, the cursor is displayed. C = 0, the cursor is not displayed. The cursor is displayed in the dot line below the character fonts. B: B = 1, the character at the cursor position starts blinking. B = 0, it does not blink. CURSOR/DISPLAY SHIFT - moves the cursor and shifts the display without changing the DD RAM contents. The cursor position and the AC contents match. This instruction is available for display correction and retrieval because the cursor position or display can be shifted without writing or reading display data. Since the DD RAM capacity is 40-character by two lines, the cursor is shifted from digit 40 (DD RAM adress $27) of line 1 to digit 1 of line 2. Displays of lines 1,2,3 and 4 are shisted at the same time. The display pattern of line 1 or 3 is not shifted to line 2 or 4, and that of line 2 or 4 is not shifted to line 1 or 3. S/C R/L Operation 0 0 The cursor position is shifted to the left (AC decrements one) 0 1 The cursor position is shifted to the right (AC increments one) 1 0 The entire display is shifted to the left with the cursor 1 1 The entire display is shifted to the right wit the cursor (In my opinion, this is valid only for my LCD, on others may be different). FUNCTION SET - sets the interface data length, the duty ratio, and the character font. DL: Interface data length DL = 1, the data length is set at 8 bits (D7 - D0) DL = 0, the data length is set at 4 bits (D7 - D4) The upper four bits are transferred first, then the lower four bits follow. N: Duty ratio N = 1, the duty ratio is set to 1/16. N = 0, the duty ratio is set ot 1/8 or 1/11. (For my L1634 set N to 1.) F: Character font F = 1, the character font is set to 5x10 dot matrix. F = 0, the character font is set to 5x7 dot matrix. The FUNCTION SET instruction must be executed prior to all other instructions except for Busy Flag/Adress Read. If another instruction is executed first, no function instruction except changing the interface data length can be executed. DD RAM adress on my display --------------------------- ---------left shift \ | ------no shift DD RAM adress at left side on LCD | | --right shift / | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Line 1 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F Line 2 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F Line 3 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F Line 4 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F =============================================================================== Here is simple source code for printing to LCD display. Text is prited on LCD and C64 screen. Pressed keys will be printed. It is code for my LCD, 4 x 16. If you have different size, you must change rawMAX, columnMAX and LINETAB. *=$1000 ;simple source code for LCD L1634 by Tomas Pribyl, 1999 getin = $ffe4 chrout = $ffd2 lcd_base = $de44 lcd_ir = lcd_base lcd_dr = lcd_base+1 rawMAX = 4 columnMAX = 16 LCDcolumn = $fc LCDraw = $fd ;--------------------------------------------------------------------------- ; WORST CASE INICILALISATION ; If automatic initialization is not executed because the above power supply ; conditions are not satisfied, you must execute FUNCTION SET repeat 3times. ; lda #$00 sta LCDraw sta LCDcolumn ;my cursor position (cursor HOME) lda #%00110000 ;function set, 8 bits data transfer sta lcd_ir jsr wait ;wait for 4.1ms or more lda #%00110000 ;function set, 8 bits data transfer sta lcd_ir jsr wait ;wait for 100us or more lda #%00110000 ;function set, 8 bits data transfer sta lcd_ir jsr wait ;------------------------------------------------------------------------ lda #%00111000 ;function set, 8 bits, duty ratio 16,font sta lcd_ir jsr wait lda #%00001111 ;display on, cursor on, blinking on sta lcd_ir jsr wait_busy ;check busy flag lda #%00000001 ;display clear sta lcd_ir jsr set_cursor ;set cursor position ldy #$00 prt lda text,y beq wait4key jsr print ;print data on LCD iny jmp prt wait4key jsr getin ;get key beq wait4key ;no key pressed pha ;store keycode jsr chrout ;print to C64 screen pla ;restore keycode jsr print ;print to LCD jmp wait4key ;wait for next key ;------------------------------------------------ ; wait routine wait ldy #$05 wait2 ldx #$00 wait1 dex bne wait1 dey bne wait2 rts ;------------------------------------------------- ; checks busy flag wait_busy pha ;store AC wait_busy1 lda lcd_ir ;read instruction register and #%10000000 ;check busy bit bne wait_busy1 pla ;restore AC rts ;-------------------------------------- ; x-LCD raw from 0 to 3 ; y-LCD column from $00 to $0f print cmp #$0d ;check NEW LINE beq next_line jsr wait_busy ;wait for display ready sta lcd_dr ;store data inc LCDcolumn ;next column lda LCDcolumn ;check end of column cmp #columnMAX bne set_cursor next_line lda #$00 ;set to begin of line sta LCDcolumn inc LCDraw ;next raw lda LCDraw cmp #rawMAX ;check last raw bne set_cursor lda #$00 ;cursor HOME sta LCDraw set_cursor jsr wait_busy ;check busy flag ldx LCDraw ;read RAW lda LCDcolumn ;read COLUMN ora linetab,x ;convert to instruction sta lcd_ir ;set adress position rts text .text "THIS IS LCD TEST",$0d,0 linetab .byte %10000000,%11000000,%10010000,%11010000