Furki316
Newbie level 3
My code is supposed to draw on the LCD screen using the mouse left click, the same concept used in this page.
http://www.scienceprog.com/connect-nokia-3310-lcd-to-lpt-port/
I have studied the 8544 data sheet. The problem is my LCD screen shows nothing.
There is no problem with the connections or the LCD screen per se. Can anyone check if there's a problem with my code with initialization or the procedure for sending data bytes to the 8544 or maybe... the delay. its soo frustrating? thank you for reading my post.
; Program to draw on a nokia 3310 LCD(pcd 8544) using left mouse
.model small
.stack 100h
.data
bank db ? ; Bank number will get stored here from 0 to 5
rbit db ? ; bit number will be stored from 0 to 7
col db ? ; column number from 0h to 54h (0 - 84 decimal)
oldbank db 6 ; previous RAM bank number
oldrbit db 0 ; previous bit number
oldcol db 89 ; previous column number
row db ? ; contains the true address of row (0-48)
msg1 db "Done", 0ah, 0dh, '$'
msg2 db "Connect the LCD and press any key to start!",0ah, 0dh, '$'
msg3 db "Setting Y address.... ", 0dh, 0ah, '$'
msg4 db "Setting X address.... ", 0dh, 0ah, '$'
msg5 db "Resetting 8544....", 0dh, 0ah, '$'
msg6 db "Setting Vop....", 0dh, 0ah, '$'
msg7 db "Clearing RAM...", 0dh, 0ah, '$'
msg8 db "Normal instruction set", 0ah, 0dh, '$'
msg9 db "Sending data byte...", 0ah, 0dh, '$'
msg10 db "Data byte sent", 0ah, 0dh, '$'
msg11 db "Display control set: Normal mode", 0ah, 0dh, '$'
eight db 08
seven db 07
four db 04
.code
main proc
mov ax, @data
mov ds, ax
mov al, 00h
mov dx, 0378h
out dx, al
mov ah, 09h
LEA dx, msg2
int 21h
mov ah, 01h
int 21h
mov ah,09h
LEA dx, msg5
int 21h
mov dx, 0378h
; Reset 8544
mov al, 0E8h
out dx, al
call DelayProc
mov al, 0F8h
out dx, al
call DelayProc
; Extended instruction set
mov cx, 02
loop2:
mov al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop2
mov al, 0F2h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov cx, 04
loop3:
mov al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop3
mov al, 0F2h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov ah, 09h
LEA dx, msg6
int 21h
mov dx, 0378h
; set Vop
mov al,0F2h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov cx, 2
loop4:
mov al, 0f0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop4
mov al, 0f2h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov cx, 04
loop5:
mov al, 0f0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop5
mov ah,09h
LEA dx, msg8
int 21h
mov dx, 0378h
; Normal instruction set
mov cx, 02
loop6:
mov al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop6
mov al, 0F2h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov cx, 05
loop7:
mov al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop7
mov ah,09h
LEA dx, msg7
int 21h
mov dx, 0378h
CLEAR_RAM:
; Clear RAM
mov cx, 0fC0h ; fc0h = 4032 bits(pixels)
CLRAM:
mov al, 0f4h
out dx, al
call delay
inc al
out dx, al
call delay
loop CLRAM
mov ah,09h
LEA dx, msg11
int 21h
mov cx, 04h
loop111:
mov al, 0F0h ; inverse mode
mov dx, 0378h
out dx, al
call Delayproc
inc al
out dx, al
call DelayProc
loop loop111
mov cx, 02h
loop12:
mov al, 0F2h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop12
mov al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov al, 0F0h
mov dx, 0378h
out dx, al
call Delayproc
inc al
out dx, al
call DelayProc
mov ah,09h
LEA dx, msg1
int 21h
getMouse:
MOV AX,5 ; 5 in AX tells INT 33 to get mouse button info
INT 33h ; get mouse button info
CMP AX,1 ; this compares AX (button status) with 1
JL getMouse
JA exit
mov ax, cx ; move cursor's horizontal position into ax
div seven ; scaling of columns
mov col, al ; store column number
mov ax, dx ; move cursor's vertical position into ax
div four ; scaling of rows
mov row, al ; row contains the true address of row (0-48)
mov ah,00h
div eight ; divide row address by 8 to get bank no. of 8544 RAM.
mov bank, al ; get bank number from al(quotient)
mov rbit, ah ; get bit number from ah(remainder)
mov al, oldcol ; compare with the previous cursor position
cmp col, al
JNZ nomatch
mov al, oldrbit
cmp rbit, al
JNZ nomatch
mov al, oldbank
cmp bank, al
JE getMouse
nomatch:
mov ah,09h
LEA dx, msg3
int 21h
; Set Y address
mov al, 0F0h
mov dx, 0378h ; Start sending command byte to set Y address
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov cx, 3
snd3z:
mov al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
Loop snd3z
mov al, bank
SHR al, 1 ; Shift right to get Y2 to position of bit 1(for SDIN)
AND al, 02h ; get 000000Y0
OR al, 0F0h
out dx, al ; send 111100Y(2)0
call DelayProc
inc al
out dx, al
call DelayProc
mov al, bank
AND al, 02h
OR al, 0f0h
out dx, al ; send 111100Y(1)0
call DelayProc
inc al
out dx, al
call DelayProc
mov al, bank
SHL al, 1
AND al, 02
OR al, 0F0h
out dx, al ; send 111100Y(0)0
call DelayProc
inc al
out dx, al
call DelayProc
mov ah,09h
LEA dx, msg4
int 21h
mov dx, 0378h
; Set X address
mov al, 0F2h
out dx, al
call DelayProc
inc al
out dx, al ; send data bit 7(D7) as 1
call DelayProc
mov cx, 05
shftl:
mov al, col ; loop sends X6, X5, X4, X3 and X2
SHR al, cl
AND al, 02h ; 000000X0
OR al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
Loop shftl
; get X1
mov al, col
AND al, 02h ; 000000X(1)0
OR al, 0F0h
out dx, al ; send X1
call DelayProc
inc al
out dx, al
call DelayProc
mov al, col
SHL al, 1
AND al, 02h
OR al, 0F0h
out dx, al ; send X0
call DelayProc
inc al
out dx, al
call DelayProc
mov ah, 09h
LEA dx, msg9
int 21h
cmp rbit, 07 ; Process the data byte for sending
mov ax, 07h
JE setRow
cmp rbit, 06
mov ax, 06h
JE setRow
cmp rbit, 05
mov ax, 05h
JE setRow
cmp rbit, 04
mov ax, 04h
JE setRow
cmp rbit, 03
mov ax, 03h
JE setRow
cmp rbit, 02
mov ax, 02h
JE setRow
cmp rbit, 01
mov ax, 01h
JE setRow
cmp rbit, 00
mov ax, 00h
JE setRow
setRow: ; Sending data byte
push ax
mov cx, 7
sub cx, ax
mov dx, 0378h
cmp ax, 07h
JE MSB1
snd0:
mov dx, 0378h
mov al, 0f4h ; send "0" bit to SDIN and 0 to clck
out dx, al
call DelayProc ; CHECK THROUGH DELAY
mov al, 0f5h
out dx, al ; "0" bit is clocked in on positive egde of clck(i.e when it goes 1)
call DelayProc ; CHECK THROUGH DELAY
Loop snd0
MSB1:
mov al, 0f6h
out dx, al ; "1" bit data with 0 clock
call DelayProc ; CHECK THROUGH DELAY
inc al
out dx, al ; "1" bit data is clocked in on the positive edge(when clock goes high)
call DelayProc
pop cx ; pop into cx what was pushed out of ax(the number of 0s after 1)
cmp cx, 00h
JE LSB1
snd0_2:
mov dx, 0378h
mov al, 0f4h
out dx, al
call DelayProc
inc al
out dx, al
Call DelayProc
Loop snd0_2
LSB1: ; code after sending last bit
mov ah,09h
LEA dx, msg10
int 21h
mov al, col ; save cursor's position (columns and rows) for comparison
mov oldcol, al
mov al, bank
mov oldbank, al
mov al, rbit
mov oldrbit, al
JMP getMouse ; sense for another mouse click
exit: ; Clear RAM and exit
mov ah, 09h
LEA dx, msg7
int 21h
mov cx, 0fC0h ; fc0h = 4032 bits(pixels)
mov dx, 0378h
CLERAM:
mov al, 0f4h
out dx, al
call delay
inc al
out dx, al
call delay
loop CLERAM
MOV AH,4Ch
INT 21h
main endp
DelayProc proc near
push dx
push cx
push ax
mov cx, 30 ; delay time 1(decimal) equals 14ms, 70(decimal) equals 1 second
mov dx,3dah
loop11:
push cx
l1:
in al,dx
and al,08h
jnz l1
l2:
in al,dx
and al,08h
jz l2
pop cx
loop loop11
pop ax
pop cx
pop dx
ret
DelayProc endp
delay proc near
push cx
mov cx, 03 ;1 in decimal is 0.7ms
dlay0:
push cx
mov cx, 0ffffh
dlay:
mov bx, 0fh
dlay2:
dec bx
cmp bx, 00h
JNZ dlay2
loop dlay
pop cx
loop dlay0
pop cx
ret
delay endp
end main
http://www.scienceprog.com/connect-nokia-3310-lcd-to-lpt-port/
I have studied the 8544 data sheet. The problem is my LCD screen shows nothing.
There is no problem with the connections or the LCD screen per se. Can anyone check if there's a problem with my code with initialization or the procedure for sending data bytes to the 8544 or maybe... the delay. its soo frustrating? thank you for reading my post.
; Program to draw on a nokia 3310 LCD(pcd 8544) using left mouse
.model small
.stack 100h
.data
bank db ? ; Bank number will get stored here from 0 to 5
rbit db ? ; bit number will be stored from 0 to 7
col db ? ; column number from 0h to 54h (0 - 84 decimal)
oldbank db 6 ; previous RAM bank number
oldrbit db 0 ; previous bit number
oldcol db 89 ; previous column number
row db ? ; contains the true address of row (0-48)
msg1 db "Done", 0ah, 0dh, '$'
msg2 db "Connect the LCD and press any key to start!",0ah, 0dh, '$'
msg3 db "Setting Y address.... ", 0dh, 0ah, '$'
msg4 db "Setting X address.... ", 0dh, 0ah, '$'
msg5 db "Resetting 8544....", 0dh, 0ah, '$'
msg6 db "Setting Vop....", 0dh, 0ah, '$'
msg7 db "Clearing RAM...", 0dh, 0ah, '$'
msg8 db "Normal instruction set", 0ah, 0dh, '$'
msg9 db "Sending data byte...", 0ah, 0dh, '$'
msg10 db "Data byte sent", 0ah, 0dh, '$'
msg11 db "Display control set: Normal mode", 0ah, 0dh, '$'
eight db 08
seven db 07
four db 04
.code
main proc
mov ax, @data
mov ds, ax
mov al, 00h
mov dx, 0378h
out dx, al
mov ah, 09h
LEA dx, msg2
int 21h
mov ah, 01h
int 21h
mov ah,09h
LEA dx, msg5
int 21h
mov dx, 0378h
; Reset 8544
mov al, 0E8h
out dx, al
call DelayProc
mov al, 0F8h
out dx, al
call DelayProc
; Extended instruction set
mov cx, 02
loop2:
mov al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop2
mov al, 0F2h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov cx, 04
loop3:
mov al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop3
mov al, 0F2h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov ah, 09h
LEA dx, msg6
int 21h
mov dx, 0378h
; set Vop
mov al,0F2h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov cx, 2
loop4:
mov al, 0f0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop4
mov al, 0f2h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov cx, 04
loop5:
mov al, 0f0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop5
mov ah,09h
LEA dx, msg8
int 21h
mov dx, 0378h
; Normal instruction set
mov cx, 02
loop6:
mov al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop6
mov al, 0F2h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov cx, 05
loop7:
mov al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop7
mov ah,09h
LEA dx, msg7
int 21h
mov dx, 0378h
CLEAR_RAM:
; Clear RAM
mov cx, 0fC0h ; fc0h = 4032 bits(pixels)
CLRAM:
mov al, 0f4h
out dx, al
call delay
inc al
out dx, al
call delay
loop CLRAM
mov ah,09h
LEA dx, msg11
int 21h
mov cx, 04h
loop111:
mov al, 0F0h ; inverse mode
mov dx, 0378h
out dx, al
call Delayproc
inc al
out dx, al
call DelayProc
loop loop111
mov cx, 02h
loop12:
mov al, 0F2h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
loop loop12
mov al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov al, 0F0h
mov dx, 0378h
out dx, al
call Delayproc
inc al
out dx, al
call DelayProc
mov ah,09h
LEA dx, msg1
int 21h
getMouse:
MOV AX,5 ; 5 in AX tells INT 33 to get mouse button info
INT 33h ; get mouse button info
CMP AX,1 ; this compares AX (button status) with 1
JL getMouse
JA exit
mov ax, cx ; move cursor's horizontal position into ax
div seven ; scaling of columns
mov col, al ; store column number
mov ax, dx ; move cursor's vertical position into ax
div four ; scaling of rows
mov row, al ; row contains the true address of row (0-48)
mov ah,00h
div eight ; divide row address by 8 to get bank no. of 8544 RAM.
mov bank, al ; get bank number from al(quotient)
mov rbit, ah ; get bit number from ah(remainder)
mov al, oldcol ; compare with the previous cursor position
cmp col, al
JNZ nomatch
mov al, oldrbit
cmp rbit, al
JNZ nomatch
mov al, oldbank
cmp bank, al
JE getMouse
nomatch:
mov ah,09h
LEA dx, msg3
int 21h
; Set Y address
mov al, 0F0h
mov dx, 0378h ; Start sending command byte to set Y address
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
mov cx, 3
snd3z:
mov al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
Loop snd3z
mov al, bank
SHR al, 1 ; Shift right to get Y2 to position of bit 1(for SDIN)
AND al, 02h ; get 000000Y0
OR al, 0F0h
out dx, al ; send 111100Y(2)0
call DelayProc
inc al
out dx, al
call DelayProc
mov al, bank
AND al, 02h
OR al, 0f0h
out dx, al ; send 111100Y(1)0
call DelayProc
inc al
out dx, al
call DelayProc
mov al, bank
SHL al, 1
AND al, 02
OR al, 0F0h
out dx, al ; send 111100Y(0)0
call DelayProc
inc al
out dx, al
call DelayProc
mov ah,09h
LEA dx, msg4
int 21h
mov dx, 0378h
; Set X address
mov al, 0F2h
out dx, al
call DelayProc
inc al
out dx, al ; send data bit 7(D7) as 1
call DelayProc
mov cx, 05
shftl:
mov al, col ; loop sends X6, X5, X4, X3 and X2
SHR al, cl
AND al, 02h ; 000000X0
OR al, 0F0h
out dx, al
call DelayProc
inc al
out dx, al
call DelayProc
Loop shftl
; get X1
mov al, col
AND al, 02h ; 000000X(1)0
OR al, 0F0h
out dx, al ; send X1
call DelayProc
inc al
out dx, al
call DelayProc
mov al, col
SHL al, 1
AND al, 02h
OR al, 0F0h
out dx, al ; send X0
call DelayProc
inc al
out dx, al
call DelayProc
mov ah, 09h
LEA dx, msg9
int 21h
cmp rbit, 07 ; Process the data byte for sending
mov ax, 07h
JE setRow
cmp rbit, 06
mov ax, 06h
JE setRow
cmp rbit, 05
mov ax, 05h
JE setRow
cmp rbit, 04
mov ax, 04h
JE setRow
cmp rbit, 03
mov ax, 03h
JE setRow
cmp rbit, 02
mov ax, 02h
JE setRow
cmp rbit, 01
mov ax, 01h
JE setRow
cmp rbit, 00
mov ax, 00h
JE setRow
setRow: ; Sending data byte
push ax
mov cx, 7
sub cx, ax
mov dx, 0378h
cmp ax, 07h
JE MSB1
snd0:
mov dx, 0378h
mov al, 0f4h ; send "0" bit to SDIN and 0 to clck
out dx, al
call DelayProc ; CHECK THROUGH DELAY
mov al, 0f5h
out dx, al ; "0" bit is clocked in on positive egde of clck(i.e when it goes 1)
call DelayProc ; CHECK THROUGH DELAY
Loop snd0
MSB1:
mov al, 0f6h
out dx, al ; "1" bit data with 0 clock
call DelayProc ; CHECK THROUGH DELAY
inc al
out dx, al ; "1" bit data is clocked in on the positive edge(when clock goes high)
call DelayProc
pop cx ; pop into cx what was pushed out of ax(the number of 0s after 1)
cmp cx, 00h
JE LSB1
snd0_2:
mov dx, 0378h
mov al, 0f4h
out dx, al
call DelayProc
inc al
out dx, al
Call DelayProc
Loop snd0_2
LSB1: ; code after sending last bit
mov ah,09h
LEA dx, msg10
int 21h
mov al, col ; save cursor's position (columns and rows) for comparison
mov oldcol, al
mov al, bank
mov oldbank, al
mov al, rbit
mov oldrbit, al
JMP getMouse ; sense for another mouse click
exit: ; Clear RAM and exit
mov ah, 09h
LEA dx, msg7
int 21h
mov cx, 0fC0h ; fc0h = 4032 bits(pixels)
mov dx, 0378h
CLERAM:
mov al, 0f4h
out dx, al
call delay
inc al
out dx, al
call delay
loop CLERAM
MOV AH,4Ch
INT 21h
main endp
DelayProc proc near
push dx
push cx
push ax
mov cx, 30 ; delay time 1(decimal) equals 14ms, 70(decimal) equals 1 second
mov dx,3dah
loop11:
push cx
l1:
in al,dx
and al,08h
jnz l1
l2:
in al,dx
and al,08h
jz l2
pop cx
loop loop11
pop ax
pop cx
pop dx
ret
DelayProc endp
delay proc near
push cx
mov cx, 03 ;1 in decimal is 0.7ms
dlay0:
push cx
mov cx, 0ffffh
dlay:
mov bx, 0fh
dlay2:
dec bx
cmp bx, 00h
JNZ dlay2
loop dlay
pop cx
loop dlay0
pop cx
ret
delay endp
end main