Help Needed Urgent (Interfacing Parallel Port)

I have made this program, but Its not working mean LED's are not getting on. Can you tell me what can be the problem

.model small
.stack 100h
.data
opt1 db " 1 - Loop of lights $"
opt2 db 10,13," 2 - Selection of Light $"
sel db 10,13,10,13, " Enter your choice [1 or 2] : $"
msg3 db 10,13,10,13," Loop is going on....$"
msg4 db 10,13,10,13," It will be reapted upto 10 times$"
msg db 10,13,10,13,".......................Press Button to ON specific LED....................$"
msg1 db 10,13,10,13," 'R' for Red : 'G' for Green : 'Y' for Yellow : 'Q' for Quiting Program$"
msg5 db 10,13,10,13," ---------------------------------Good Bye--------------------------------$"
enterandlinefeeding db 10,13,10,13,"$"
msg2 db "..........................................................................$"

.code
main proc

;//////////////////// getting address of LPT1 prot ////////////

mov bx,0040h
mov ds,bx
mov al,0ffh
;mov di,08h ;can use it to get address from ram
mov cx,03bch ;then i used mov cx,[di]but that didnt work too
mov ax,@data
mov ds,ax

;////////////////////// getting option ////////////////////////

mov dx,offset opt1
mov ah,9
INT 21h
mov dx,offset opt2
INT 21h
mov dx,offset sel
INT 21h

getagain:
mov ah,01
INT 21h
cmp al,'1'
jz next
cmp al,'2'
jz next1
jmp getagain

next:
CALL lightloop

next1:
CALL Selection

;//////////////Quiting////////////////////////////////////

Quit: CALL back
Quit1:
mov dx,offset msg5
mov ah,9
INT 21h
mov ah,4ch
INT 21h
main endp

;/////////////////////// Slection proc /////////////////////////

selection proc

;///////////////////// displaying messages ////////////////////

mov dx,offset msg
mov ah,9
INT 21h
mov dx,offset msg1
INT 21h
mov dx,offset enterandlinefeeding
INT 21h
mov dx,offset msg2
INT 21h

;////////////////// getting input for Single Light/////////////////////////

mov ah,02
mov dl,13
INT 21h
again:
mov ah,07
INT 21h
; if red pressed
cmp al,'r'
jz ONred
; if green
cmp al,'g'
jz ONgreen
; if yellow
cmp al,'y'
jz ONyellow
cmp al,'q'
jz Quit1
CALL back
jmp again
;//////// Red ON///////////////

ONred:
CALL back
mov al,01
mov dx,cx
out dx,al
jmp again

;//////// Green ON///////////////

ONgreen:
CALL back
mov al,04
mov dx,cx
out dx,al
jmp again

;//////// Yellow ON///////////////

ONyellow:
CALL back
mov al,02
mov dx,cx
out dx,al
jmp again
ret
selection endp

;//////////////////////// Lightloop proc ///////////////////////

lightloop proc
mov dx,offset msg3
mov ah,09
INT 21h
mov bx,10
mov dx,offset msg4
INT 21h

loopp:
mov al,01
mov dx,cx
out dx,al
call delay
mov al,02
out dx,al
call delay
mov al,04
out dx,al
call delay
dec bx
cmp bx,0
jz gout
jmp loopp

gout:
jmp Quit1
ret
lightloop endp

;/////////////////////// back proc /////////////////////////////
; it is related with interface, it removes the charater print on the
; screen when user press key

back proc
mov ah,02
mov dl,13
INT 21h
mov dx,offset msg2
mov ah,9
INT 21h
mov ah,02
mov dl,13
INT 21h
ret
back endp

;////////////////////// delay proc //////////////////////////////

delay proc
push cx
push bx
mov cx,0300h
mov bx,0ffffh
re:
dec bx
cmp bx,0
jnz re
dec cx
cmp cx,0
jnz re
pop bx
pop cx
ret
delay endp

end main

Comments

  • Hey,

    i have one suggestion:

    try to use port 378h. you can interface here 8 LEDs from pin 2 - 9, just use "out" function. here is an example code:

    ;this code lights up your led for a second.
    mov dx,378h ;parallel port
    mov al,0ffh ;light all 8 leds
    out dx,al ;data out, causes the leds to light
    call delay ;delay for a second
    mov al,00 ;turn off data
    out dx,al ;causes the leds to turn off

    delay:

    ;include your delay routine here

    Simple isn't it. Just modify it.




  • You've got a real big whisle & bell code example,
    but the actual code that does the work wasn't checked first? Was it?
    Make a simple .COM asm and run some checks untill you get code that works, then make the complicated interface.

    You don't need an end of line character $ on the end of each line,
    It's only required at the end of each message.

    ;//////////////////// getting address of LPT1 prot ////////////
    mov bx,0040h
    mov ds,bx
    mov al,0ffh
    ;mov di,08h ;can use it to get address from ram
    mov cx,03bch ;then i used mov cx,[di]but that didnt work too
    mov ax,@data
    mov ds,ax

    This code doesn't actually get anything at DS from the BIOS segment.
    You might check MEMORY.LST from Ralf Browns interrupt list for the address.
    Moving a value into CX at the beginning of the program and expecting it to remain untouched at the end of the program, isn't the best way.
    Getting the port from bios and saveing it in a declaired byte or word
    is often how it's done, but since it's already in memory, it doesn't have to be moved. I like to use the seg reg GS
    MOV GS,0 ;at the beginning of your program, then
    XOR DH,DH
    MOV DL,[GS:0408h] ;will get DX the port number when you need it.
    (if 08h is it's bios adr, if it's a word size MOV DX,[GS:040??h])

    Your using function 1 & 7 to get key input.
    You might want to use one or the other.
    I always use function AH=8 INT 21h because I'm familuar with what it does.

    Different ports require different addressing routines because a port is actually access to hardware or the bus to the hardware er something.
    So many ports you simply can't send it a byte and expect something to happen.
    Some ports need to be advised of a write comming before the write,
    and might even need to be configured before that,
    Like read data from another port, alter it and write it back which does the configuring of the read or write port,
    X. then to do a write, you have to advise it of what's comming, then write the byte,
    more writes start again at 'X' & at the end of your program, restore the port configuration back to it's original state.
    Ralf Brown's PORTS.A (A,B,C,D,etc) gives info about ports and their requirements.
    Viewing code others have written to do what you want is often a good place to start also. Have you tried a string search here or at google?
    There might be working code available.
    You can search previous help posts here for strings too.

    I hope there's something usefull in there for ya.......

    Bitdog


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories