The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: colormyworld on December 27, 2011, 12:27:25 PM

Title: Connect a LCD display to the parallel port of PC
Post by: colormyworld on December 27, 2011, 12:27:25 PM
Hello!

I've just started to learn a few things about assembling and microprocessors, and now I'm working at a bigger project(for me, because I'm sure that for experienced members it's really easy), and I want to connect a LCD display to the parallel port of PC in order to display a value of 1 digit(0....9).

Any kind of information will be very useful, that can help me to understand how an LCD receives data, and how actually I can write my assembling progr.

Merry Christmas! :)
Title: Re: Connect a LCD display to the parallel port of PC
Post by: qWord on December 27, 2011, 01:11:01 PM
Quote from: colormyworld on December 27, 2011, 12:27:25 PMAny kind of information will be very useful
Your question is vague.
Title: Re: Connect a LCD display to the parallel port of PC
Post by: colormyworld on December 27, 2011, 01:30:03 PM
I need to write a program in assembly language in order to Connect a LCD display to the parallel port of PC in order to display a value of 1 digit.
This is my goal. But in order to do this, I need to document myself, to see how it works an LCD.

Title: Re: Connect a LCD display to the parallel port of PC
Post by: BogdanOntanu on December 27, 2011, 01:45:54 PM
Quote from: colormyworld on December 27, 2011, 01:30:03 PM
I need to write a program in assembly language in order to Connect a LCD display to the parallel port of PC in order to display a value of 1 digit.
This is my goal. But in order to do this, I need to document myself, to see how it works an LCD.


This is not exclusively a question of programming. It is also (half or even more of it) a question of hardware interfaces. You can not really write an program for this until you do not show/have some schematics and do not make your homework about the requirements (speed, signal levels, timings, real time constraints).

Please show us that you understand the hardware requirements in details and the schematics.
What work and understanding of the problem at hand have you done until now?

A few hints:

1) Do you understand the hardware requirements  and protocol differences in between VGA, DVI and HDMI interfaces to an monitor?
2) Do you understand the limitations of the speed of an parallel port that is normally located on an simulated ISA bus inside an today PC?
3) Do you understand the electrical signals that you need to generate (syncro H/V, blanking, and pixel clock) for your case?
4) We might help you with the ASM program (when you reach this point... if ever) BUT normally we do not make you homework here...
it is YOU that must write and understand and test 99% of it... we help the ones that show good will.
5) Do you understand that modern Win7 might not allow you to directly write to the parallel port and even if it does it might no reach the real time constraints?
Again, show us what research you did until now ;)

Oh, and please DO NOT post the same question in multiple sub forums :D
Title: Re: Connect a LCD display to the parallel port of PC
Post by: colormyworld on December 27, 2011, 01:55:00 PM
Hello!

First of all thank you for the questions, is a good starting point for me. This is why I sad that ANY kind of information is useful. Yes, I need and also I want to learn more in detali about the hardware, but is a little bit hard to get information focused.

Like I sad, I'm a very new, and till now I've only wrote short programs summing, moving the contents of memory and so on, and this is a complex program.

Have a great day!
Title: Re: Connect a LCD display to the parallel port of PC
Post by: BogdanOntanu on December 27, 2011, 02:01:57 PM
From my experience your best chance of doing this kind of project is to use an fast micro controller (AVR or something)

Using an PC and x86 ASM will be relatively hard (but not impossible).

There is a reason why today PC's use an video board: the CPU can not generate the required signals fast enough and efficiently ;)

Also HDMI monitors will NOT allow you to do this :D

Your best chance is to find an old VGA monitor somewhere.
Title: Re: Connect a LCD display to the parallel port of PC
Post by: qWord on December 27, 2011, 02:14:29 PM
You may better go to a forum for electronics, microcontrollers and FPGAs.
Title: Re: Connect a LCD display to the parallel port of PC
Post by: FORTRANS on December 27, 2011, 02:25:01 PM
Hi,

   I hooked up an LCD display to a parallel port.  Got a 16
character by two row panel from Radio Shack (a long time
ago, last I checked they said they did not have them anymore).
But, I think I cooked it before getting it to work.  What
type of LCD do you have?

Regards,

Steve N.
Title: Re: Connect a LCD display to the parallel port of PC
Post by: dedndave on December 27, 2011, 03:38:00 PM
does your LCD display have a driver chip ?
or are you driving the display directly ?
it would be helpful if we had the documentation for the specific display you are using
we can probably find it online, but we need a manufacturer and model number
any info on the driver chip may also be useful
Title: Re: Connect a LCD display to the parallel port of PC
Post by: colormyworld on December 27, 2011, 04:04:36 PM
A 16 Character x 2 Line LCD Module
Title: Re: Connect a LCD display to the parallel port of PC
Post by: dedndave on December 27, 2011, 04:34:01 PM
well - that will greatly simplify things, in some ways

still - if you are writing 32-bit code, you have to get the OS to let you have permission to talk to the parallel port
i think the you can do that with DeviceIoCtl...
http://msdn.microsoft.com/en-us/library/aa363216.aspx

if you are writing 16-bit code, you can do this a little easier, although, it won't run under 64-bit operating systems

the parallel port does not provide power output pins
so, you'll have to provide your own power
i doubt you can run a display with a backlight from a signal pin   :P
also - you won't have an analogue signal to drive the contrast input
you will have to provide a pot on the display board for that

otherwise - the parallel port data pins can be connected to the data lines DB0-DB7
the register select, read/write, and enable pins can be driven using some of the parallel port hand-shaking lines
this link has some useful info...
http://www.beyondlogic.org/parlcd/parlcd.htm
Title: Re: Connect a LCD display to the parallel port of PC
Post by: FORTRANS on December 27, 2011, 05:50:59 PM
Hi Dave,

   Here are a couple pictures.  DB-25 connector, soldered wires,
a potentiometer, and power connecter.  I can look for the
datasheet, but it's been a few years since I last saw it.

Regards,

Steve N.
Title: Re: Connect a LCD display to the parallel port of PC
Post by: colormyworld on January 08, 2012, 03:38:02 PM
Hey Fortrans,

Do you still have also the code in assembly? This would be very useful.

Title: Re: Connect a LCD display to the parallel port of PC
Post by: FORTRANS on January 08, 2012, 04:43:57 PM
Quote from: colormyworld on January 08, 2012, 03:38:02 PM
Hey Fortrans,

Do you still have also the code in assembly? This would be very useful.

Hi,

   No, not really.  I cooked the panel before I got it working.
Here is a part of the code I have left.  Was "working" in DOS.
Windows does not support the Int 15H BIOS functions.  I
will post the non-working LCD panel code I have.  Not sure
how it can help, but good luck.

Regards,

Steve N.


        PAGE ,132
        TITLE LCD panel driver.
        NAME LCD
COMMENT *
    Display stuff on a small LCD screen.
LCD, December 2000, SRN
*
; Note:  Most of the non-panel code deleted!  Jan 2012.
; Note:  Not working code follows...

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Set up the code definitions the operating system wants.  Data segment:
DATASG  SEGMENT PUBLIC
        ASSUME  DS:DATASG, SS:STCKSG

; - - - - DELAYER - - - -
DelayT  DW      0       ; ~ Hundredths of seconds

; - - - - Display Routine Global Data - - - -
DispWidth       DW      16
DispHeight      DW      2

; - - - - LPT Port Definitions - - - -
LPTBase         EQU     0378H   ; LPT1
LPTData         EQU     LPTBase + 0
LPTStatus       EQU     LPTBase + 1
LPTControl      EQU     LPTBase + 2

DATASG  ENDS
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Set up the code definitions the operating system wants.  Code segment:
CODE    SEGMENT PUBLIC
START   PROC

; Code deleted.

START2: ; Initialize panel
        CALL PInit
        jmp startx2

START3: ; loop point
        MOV     AH,'H'
        CALL OutChLCD
        MOV     AH,'e'
        CALL OutChLCD
        MOV     AH,'l'
        CALL OutChLCD
        MOV     AH,'l'
        CALL OutChLCD
        MOV     AH,'o'
        CALL OutChLCD
        MOV     AH,' '
        CALL OutChLCD
        MOV     AH,'w'
        CALL OutChLCD
        MOV     AH,'o'
        CALL OutChLCD
        MOV     AH,'r'
        CALL OutChLCD
        MOV     AH,'l'
        CALL OutChLCD
        MOV     AH,'d'
        CALL OutChLCD
        MOV     AH,'!'
        CALL OutChLCD

STARTX: ; exit processing
        jmp startx2
STARTX2:
        MOV     AL,0
        SCALL   EXIT    ; .EXE exit  (Macro to exit via 4CH.)
START   ENDP
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LDelay  MACRO   ; Long delay for panel

        XOR     CX,CX
        MOV     DX,1600 ; 1.64 ms - 40 µs
        MOV     AH,086H ; AT Services Delay Function 86H
        INT     15H

        ENDM
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SDelay  MACRO   ; Short delay for panel

        XOR     CX,CX
        MOV     DX,20   ; 1/2 of 40 µs
        MOV     AH,086H ; AT Services Delay Function 86H
        INT     15H

        ENDM
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Output command byte and toggle strobe for panel
; December 2000 Input AH = command byte
OutLCD:
        MOV     DX,LPTControl
        IN      AL,DX
        AND     AL,0DFH ; ensure data forward
        OR      AL,080H ; select printer for command
        OUT     DX,AL

        MOV     AL,AH
        MOV     DX,LPTData
        OUT     DX,AL   ; output command

        MOV     DX,LPTControl
        IN      AL,DX
        OR      AL,01H  ; Set Strobe
        OUT     DX,AL

        SDelay  ; uses AX, CX, DX

        MOV     DX,LPTControl
        IN      AL,DX
        AND     AL,0FEH ; Reset Strobe
        OUT     DX,AL

        SDelay

        RET
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Output text character to panel
; 5 December 2000 Input AH = text byte
OutChLCD:
        MOV     DX,LPTControl
        IN      AL,DX
        AND     AL,0D7H ; ensure data forward, reset select printer for text
        OUT     DX,AL

        MOV     AL,AH
        MOV     DX,LPTData
        OUT     DX,AL   ; output byte

        MOV     DX,LPTControl
        IN      AL,DX
        OR      AL,01H  ; Set Strobe
        OUT     DX,AL

        SDelay

        MOV     DX,LPTControl
        IN      AL,DX
        AND     AL,0FEH ; Reset Strobe
        OUT     DX,AL

        SDelay

        RET
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PInit:  ; Initialize LPT port and LCD panel
        ; First the LPT port (moved to output routines)

; then the panel
        MOV     AH,01H  ; Clear Display
        CALL OutLCD
        LDelay

        MOV     AH,38H  ; Noted: first 3 commands to ensure proper power on
        CALL OutLCD     ; H'38' = function set, 8 bit, 2 lines
        MOV     AH,38H  ; AH is destroyed
        CALL OutLCD
        MOV     AH,38H
        CALL OutLCD

        MOV     AH,0FH  ; Init? Display on/off control
        CALL OutLCD     ; H'0F' = display on, cursor on, Blink on

        RET

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CODE    ENDS
        END     START
Title: Re: Connect a LCD display to the parallel port of PC
Post by: colormyworld on January 08, 2012, 05:31:13 PM
@BogdanOntanu: The time was passing an also I was studying a little bit a about this subject.
So I will try to answer to your questions by what I was finding so far:
DVI and HDMI were introduced to carry information in digital formats. HDMI (High-Definition Multimedia Interface) is a compact audio/video interface for transmitting encrypted uncompressed digital data. It is a digital alternative to consumer analog standards such as VGA.
The CEC allows HDMI devices to control each other when necessary and allows the user to operate multiple devices with one remote control handset.Because HDMI is electrically compatible with the CEA-861 signals used by digital visual interface (DVI), no signal conversion is necessary, nor is there a loss of video quality when a DVI-to-HDMI adapter is used. As an uncompressed CEA-861 connection, HDMI is independent of the various digital television standards used by individual device.
VGA is an older standard that transforms the digital video output from the computer into an analog signal (in a CRT) and back to a digital signal (in an LCD).
DVI is newer and more intuitive for newer LCD monitors. It is capable of sending the digital signal straight from the computer to an LCD display without having to waste time transforming the signal to analog and back. All CRT monitors are analog displays.

When we use the parallel ports in bidirectional
mode, by setting the direction bit of the control register (C5 = 1), the outputs of the data register can be set
to the high-impedance state, these outputs being electrically disconnected from the connector pins. This
allows to read into the data register any external TTL signals applied to the corresponding pins. The values
written into the data register are stored, but they are not sent to the pins. Parallel ports that operate in
this manner are referred to as bidirectional or PS/2 ports.



Thank you FORTRANS
Title: Re: Connect a LCD display to the parallel port of PC
Post by: dedndave on January 08, 2012, 06:43:57 PM
colormyworld,

the basic first questions is:
is the program to be 16-bit or 32-bit

if you want to write 32 bit code, the I/O ports are not directly available to you
although, i think it can be done, in the case of parallel or serial ports

if you want to write 16-bit code (such as that posted by Steve), the port is directly accessible
however, the software will not run under 64-bit operating systems without some virtual environment like DosBox
Title: Re: Connect a LCD display to the parallel port of PC
Post by: colormyworld on January 08, 2012, 06:57:31 PM
The program is to be 16 bit
Title: Re: Connect a LCD display to the parallel port of PC
Post by: dedndave on January 08, 2012, 07:21:34 PM
that makes things pretty simple, then   :P
Title: Re: Connect a LCD display to the parallel port of PC
Post by: dedndave on January 08, 2012, 07:24:51 PM
i see that the link i previously posted was moved...
http://retired.beyondlogic.org/parlcd/parlcd.htm

the I/O port base addresses are in the BIOS data (segment at 40h)
the first parallel port is at offset 8 - the others follow at 0Ah, 0Ch
if the value is 0, the port does not exist
once you have the port base address, it is a pretty simple interface
Title: Re: Connect a LCD display to the parallel port of PC
Post by: dedndave on January 08, 2012, 07:41:54 PM
that site has a couple other goodies that might interest you....

http://retired.beyondlogic.org/spp/parallel.htm
http://retired.beyondlogic.org/pardebug/pdebug.htm
Title: Re: Connect a LCD display to the parallel port of PC
Post by: jj2007 on January 08, 2012, 10:20:22 PM
For 32-bit code, the InpOut32 freeware dll is available at Logix4U (http://www.logix4u.net/index.php?option=com_content&view=article&id=16:inpout32dll-for-windows-982000ntxp&catid=14:parallel-port).

Other options include writing a driver for rep outsb, plus StartDocPrinter and WriteFile...
Title: Re: Connect a LCD display to the parallel port of PC
Post by: dedndave on January 08, 2012, 11:29:54 PM
that's a cool option - and i see they have a 64-bit version, as well
but - i was under the impression that you could enable I/O with DeviceIoCtl
not that i've tried it or had any success with it   :P
Title: Re: Connect a LCD display to the parallel port of PC
Post by: jj2007 on January 08, 2012, 11:43:10 PM
Check also http://msdn.microsoft.com/en-us/library/windows/hardware/ff544230%28v=VS.85%29.aspx
Title: Re: Connect a LCD display to the parallel port of PC
Post by: NoCforMe on January 10, 2012, 07:12:45 AM
Don't know how much it'll help you, but I can post some working code that drives a small LCD (16 X 2) from a microcontroller (SX-28). It could be pretty easily done in '86 assembly language. Anyway, here it is:


;********  LCD stuff:  ********
LCD_CMD_FUNC_SET EQU $28 ;4 bit mode/2 lines/5x7 font
LCD_CMD_ENTRY_MODE EQU 6 ;Increment cursor/no shift
LCD_CMD_DISPLAY_ON EQU $0C ;Display on/cursor off/no blink
LCD_CMD_DISPLAY_CLR EQU 1 ;Wipe that display!

;********  LCD initialization:  ********

; Wait for 15 ms:
MOV W, #DELAY_15mS_H
MOV TimerHigh, W
MOV W, #DELAY_15mS_L
MOV TimerLow, W
CALL LongDelay

; Send "Function Set" command:
MOV W, #LCD_CMD_FUNC_SET
CALL WriteLCD_CMD

; Send "Function Set" command again:
MOV W, #LCD_CMD_FUNC_SET
CALL WriteLCD_CMD

; Send "Function Set" command yet again:
MOV W, #LCD_CMD_FUNC_SET
CALL WriteLCD_CMD

; Send "Function Set" command yet again:
MOV W, #LCD_CMD_FUNC_SET
CALL WriteLCD_CMD

; Send "Entry Mode Set" command:
MOV W, #LCD_CMD_ENTRY_MODE
CALL WriteLCD_CMD

; Send "Display On/Off" command:
MOV W, #LCD_CMD_DISPLAY_ON
CALL WriteLCD_CMD

; Send "Display Clear" command:
MOV W, #LCD_CMD_DISPLAY_CLR
CALL WriteLCD_CMD


;*******************************************************
; Write to LCD routines
;
; WriteLCD_CMD & WriteLCD_Data do the respective thangs.
; (Only difference is the initial setting of the register
; select [RS] line.)
;
; On entry:
; Data/command byte is in W
;*******************************************************

WriteLCD_CMD
CLRB LCD_RS ;RS = CMD
JMP WriteLCD

WriteLCD_Data
SETB LCD_RS ;RS = data

WriteLCD
MOV Temp, W ;Save a copy of data/command byte.
MOV W, <>Temp ;Swap high <--> low nybbles & get them.
AND W, #$0F ;Mask off low (actually high) nybble.

;*** Output 1st nybble: ***
MOV LCD_DATA_PORT, W ;Write data/command byte
; Set write mode, then strobe enable line:
CLRB LCD_RW ;RW = write
SETB LCD_E ;Strobe E: first high,
NOP ; (grace period)
CLRB LCD_E ; then back low

;*** Output 2nd nybble: ***
MOV W, Temp ;Get original byte back.
AND W, #$0F ;Mask off low nybble
MOV LCD_DATA_PORT, W
; Strobe enable line:
SETB LCD_E ;Strobe E: first high,
NOP ; (grace period)
CLRB LCD_E ; then back low

;Both nybbles written: set up to read busy flag.
; First, set LCD data port (RC) as input on SX28:
MODE M_DIR ;Set I/O direction for port C
MOV W, #C_READ_BITS ;Set port as input
MOV !RC, W
busy1 SETB LCD_RW ;RW = read
CLRB LCD_RS ;RS = CMD
SETB LCD_E ;Strobe E again
NOP
MOV W, LCD_DATA_PORT ;Read LCD data (only need bit 7)
CLRB LCD_E

SETB LCD_E ;Pulse E again
NOP ;to read the other 4 bits out
CLRB LCD_E ;and just throw them away.

; Read busy flag & check it until it ain't busy:
AND W, #$8 ;Check bit 7 (of the LCD; bit 3 of the port)
SZ ;We're looking for it to be low
JMP busy1 ;Still busy

MODE M_DIR ;Set LCD port back to output
MOV W, #C_DIR_BITS
MOV !RC, W
CLRB LCD_RW ;LCD back to write mode.
RET


Notice the sequence of commands being written to the LCD at the top. I found that some of these commands have to be sent several times in order to "stick". Seems pretty dumb, but it works.

Also notice the item at the top that sets 4-bit mode. Turns out there are two ways to drive these little LCDs: you can send data (characters) 4 or 8 bits at a time. I opted for 4 bits, since it meant less wiring on the hardware side, but a little more code, since you have to send each character as 2 4-bit nybbles. Just something else you need to know about LCD programming.
Title: Re: Connect a LCD display to the parallel port of PC
Post by: farrier on January 10, 2012, 08:01:51 AM
These links are for parallel and serial communications--works with all win32 versions:

Assembly code using standard SDK calls, no extra .dll's or drivers needed:

http://www.masm32.com/board/index.php?topic=12488.msg96491#msg96491
works with Win 7 also

http://www.masm32.com/board/index.php?topic=4464.msg33340#msg33340

Serial port communications:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp


hth,

farrier
Title: Re: Connect a LCD display to the parallel port of PC
Post by: jj2007 on January 10, 2012, 08:17:31 AM
Quote from: farrier on January 10, 2012, 08:01:51 AM
These links are for parallel and serial communications--works with all win32 versions:

Assembly code using standard SDK calls, no extra .dll's or drivers needed:

http://www.masm32.com/board/index.php?topic=12488.msg96491#msg96491
works with Win 7 also

Quote from: jj2007 on January 08, 2012, 10:20:22 PM
Other options include writing a driver for rep outsb, plus StartDocPrinter and WriteFile...

Hi farrier,
WriteFile to LPT1 sounds good indeed but I've read somewhere the problem is to keep signals "on" for a defined time, i.e. it's not just write & forget. Perhaps colormyworld could simply test if it works?
Title: Re: Connect a LCD display to the parallel port of PC
Post by: farrier on January 10, 2012, 11:06:43 AM
jj2007,

I'm not sure what you mean by, 'to keep signals "on" for a defined time'.  The routines I included, run everyday in many businesses.  Very few problems over many years.

farrier
Title: Re: Connect a LCD display to the parallel port of PC
Post by: jj2007 on January 10, 2012, 11:20:13 AM
Hi farrier,
It might work perfectly, if the receiving interface allows it. But apparently that is not always the case, try googling "parallel port" signal level writefile...
:thumbu
Title: Re: Connect a LCD display to the parallel port of PC
Post by: dedndave on January 10, 2012, 12:57:45 PM
yah - for this type of thing, you need to be able to have absolute power over all the control lines

fortunately, this is an output device
for input devices, you may want to write an INT handler
i dunno how that might be done in 32-bit, but i suspect it would require a KMD, at least

some day, i'll have to figure it out, too
more than once, i have done that type of thing in 16-bit to run some client's "gadget"   :P
i used to use the serial port handshake lines for input all the time
because they can be set up to generate an INT and are easy to connect
Title: Re: Connect a LCD display to the parallel port of PC
Post by: dedndave on January 14, 2012, 06:20:45 PM
well - there are all kinds of things wrong with that code
don't feel bad, we all had to start someplace   :U

i was looking at the datasheet for the display
it has absolutely no description or "theory of operation" section
but, it does mention one thing that helps (other than the pinout)
that is that it uses a Samsung KS0066 or equiv controller

i managed to find a reasonable description for the controller...
http://www.4shared.com/zip/UzcW6DNo/KS0066.html
scroll down to the section named "FUNCTION DESCRIPTION"

you will also want this PDF...
http://retired.beyondlogic.org/spp/parallel.pdf

do you have it hooked up like this ????
(http://retired.beyondlogic.org/parlcd/parlcd.gif)
Title: Re: Connect a LCD display to the parallel port of PC
Post by: dedndave on January 15, 2012, 05:55:31 PM
colormyworld,

i am working on some code to drive the display
i was following this example written in C

http://retired.beyondlogic.org/parlcd/parlcd.htm

i notice that he has a different display
the connection seems to be pretty much the same, but the code is a little different
we could add some functionality by connecting one of the control lines to the R/W pin, however
for now, we can leave it as is
i need to review the initialization code, then i will post it for you   :U