OBJECTIVE
- Students understand the PS/2 PC keyboard interface circuit
- Students understand the assembly programming language for PC keyboard data retrieval.
- Students can display PC keyboard data on various displays, including Character LCD and 7 Segment.
Basic Theory
Figure 13.1. Dot Matrix Printer Configuration Pins
Figure 13.2. Signal naming on DB25 Female printer
During standard printer operation, the way data is transmitted through the parallel port varies, but in principle it is as follows:
- To send a byte of data, the software outputs the byte onto the data line, then issues a STROBE pulse.
- On the other hand, the Printer tests the BUSY line, and the computer waits for the line to be busy before sending the next byte.
- In another implementation, the ACK line is used by the printer to inform the PC that the data has been received.
- The PAPER EMPTY line is the line to inform the PC that the paper has come out.
- The printer also sends a SELECTED signal to the PC to indicate that the printer is on line and ready to receive data.
- The ERROR signal from the printer can be used for various errors that will cause the printer to be unable to receive data.
- AUTOFEED, tells the printer to automatically insert a line feed after the carriage return.
- INIT, initialize the printer after power supply.
Figure 13.3. Printer interface connection
Experiment 13.1 Print a character using a dot matrix printer
In this experiment, two sentences will be printed on paper using a printer via an interface to a microcontroller.
- Connect the 8 bit connector to P2 and the 3 bit connector to P3.
- Connect the printer module to the DB25 female printer connector.
- Connect the Microcontroller Trainer module to the +5V power supply.
- Connect the Microcontroller Trainer module to the programmer circuit
- Open the M-IDE Studio for MCS-51 program, as a program editor and compiler.
- Type the following program: ( download file prog132a.asm )
busy bit P3.0
strobe bit P3.1
portData equ P2
;
org 0h
start:call printchar; cetak sebuah karakter "A"
quit: sjmp Quit ; Hang Forever until reset pressed
;
;======================================================
;Subrutin ini digunakan untuk cetak satu karakter
;melalui D0 s/d D7
;sebelum melakukan cetak karakter, sinyal BUSY harus
;dideteksi, sampai terdeteksi sinyal dg logika low
;selanjutnya kirim sinyal STROBE dengan pulsa( --__-- )
;======================================================
Printchar:
mov portData,'A'
jb busy,$
setb strobe
clr strobe
acall delay
Setb strobe
acall delay
ret
;
delay: mov R7,#2
del1: mov R6,#20
DJNZ R6,$
DJNZ R7,del1
ret
;
end
- Save the program you typed and name it: prog132a.asm
- In the MIDE program, select Build /F9 or to compile the program from *.asm to *.hex.
- Program the microcontroller using the ISP Software Program (See Instructions for Use)
- Modify the program to display the 3 sentence data to a dot matrix printer.
Experiment 13.2 Print two sentences using a dot matrix printer.
In this experiment, two sentences will be printed on paper using a printer via an interface to a microcontroller.
- Connect the 8 bit connector to P2 and the 3 bit connector to P3.
- Connect the printer module to the DB25 female printer connector.
- Connect the Microcontroller Trainer module to the +5V power supply.
- Connect the Microcontroller Trainer module to the programmer circuit
- Open the M-IDE Studio for MCS-51 program, as a program editor and compiler.
- Type the following program: ( download file prog131a.asm )
busy bit P3.0
strobe bit P3.1
portData equ P2
;
org 0h
start: call word_Welcome ; to print ' Welcome To '
call enter ; new line feed
call word_Lab ; to print ' Computer Laboratory '
call enter ; new line feed
;
quit: sjmp Quit ; Hang Forever until reset pressed
;
;======================================================
;Subrutin ini digunakan untuk cetak satu karakter
:melalui D0 s/d D7
;sebelum melakukan cetak karakter, sinyal BUSY harus
;dideteksi, sampai terdeteksi sinyal dg logika low
;selanjutnya kirim sinyal STROBE dengan pulsa( --__-- )
;======================================================
Printchar:
mov portData,A
jb busy,$
setb strobe
clr strobe
acall delay
Setb strobe
acall delay
ret
;
delay: mov R7,#2
del1: mov R6,#20
DJNZ R6,$
DJNZ R7,del1
ret
;======================================================
;SUbrutine ini digunakan untuk cetak kalimat
;dengan mamanggil subrutine printchar dan look up data
;proses cetak akan berlangsung terus sampai ditemui '$'
;======================================================
word_welcome:
mov DPTR,#Text_welcome
lagi1: clr A
movc A,@A+DPTR
cjne A,#'$',Print1
sjmp Out1
Print1: call Printchar
inc dptr
call delay
sjmp lagi1
Out1: ret
;
;==========================================
;This subroutine print a text'Computer Laboratorium'
;this subroutine will print character by character till '$'
;character is detected, when this character is detected then
;It's indicated that a text has finished
;==========================================
word_Lab:
mov DPTR,#Text_lab
lagi2: clr A
movc A,@A+DPTR
cjne A,#'$',Print2
sjmp Out2
Print2:call Printchar
inc dptr
call delay
sjmp lagi2
Out2: ret
Enter:
mov A,#0dh
call printchar
call delay
mov A,#0ah
call printchar
ret
;
Text_welcome:
DB ' Welcome To $'
Text_Lab: DB ' Computer Laboratory $'
;
end
- Save the program you typed and name it: prog131a.asm
- In the MIDE program, select Build /F9 or to compile the program from *.asm to *.hex.
- Program the microcontroller using the ISP Software Program (See Instructions for Use)
- Modify the program to display the 3 sentences of data to a dot matrix printer.
Matrix Button Reading Program
Program to Read a Group of Matrix-Arranged Buttons
Part 1
;- BAB3_14.ASM -------------------------------------------------------------------
;
; Program Untuk Membaca Tombol-Tombol Yang Disusun Secara Matrik,
; Masukan ke Tombol Pada Port 3, Keluaran dibaca pada Port 2, dan
; hasil ditampilkan pada 7-segmen di Port 0
;
;---------------------------------------------------------------------------------
ORG 0H
;
MULAI:
MOV P2,#0FEH ; Buat P2.0=0 (Untuk Baca Tombol 0,A,B,C,F4)
JB P3.7,KEY1 ; Apakah tombol 'C' (P3.7) ditekan (P3.7=0)
; Tidak! cek tombol lain di KEY1
MOV P0,#0AAH ; Ya! Keluarkan Kode Huruf 'C' Ke Port 0
SJMP MULAI ; Ulangi lagi dari awal
KEY1:
JB P3.6,KEY2 ; Apakah tombol 'B' (P3.6) ditekan (P3.6=0)
; Tidak! cek tombol lain di KEY2
MOV P0,#38H ; Ya! Keluarkan kode huruf 'B' ke port 0
SJMP MULAI ; Ulangi lagi dari awal
KEY2:
JB P3.5,KEY3 ; Apakah tombol 'A' (P3.5) ditekan (P3.5=0)
; Tidak! cek tombol lain di KEY3
MOV P0,#60H ; Ya! Keluarkan kode huruf 'A' ke port 0
SJMP MULAI ; Ulangi lagi dari awal
KEY3:
JB P3.4,KEY4 ; Apakah tombol '0' (P3.4) ditekan (P3.4=0)
; Tidak! cek tombol lain di KEY4
MOV P0,#22H ; Ya! Keluarkan kode huruf 'A' ke port 0
SJMP MULAI ; Ulangi lagi dari awal
KEY4:
JB P3.3,KEY5 ; Apakah tombol F4 (P3.3) ditekan (P3.3=0)
; Tidak! cek tombol lain di KEY5
MOV P0,#70H ; Ya! Keluarkan kode '' ke port 0
SJMP MULAI ; Ulangi lagi dari awal
KEY5:
MOV P2,#0FDH ; Buat P2.1=0 (Untuk Baca Tombol 1,2,3,D,F3)
JB P3.7,KEY6
MOV P0,#34H
SJMP MULAI
KEY6:
JB P3.6,KEY7
MOV P0,#25H
SJMP MULAI
KEY7:
JB P3.5,KEY8
MOV P0,#0A4H
SJMP MULAI
KEY8:
JB P3.4,KEY9
MOV P0,#77H
SJMP MULAI
KEY9:
JB P3.3,KEY10
MOV P0,#22H
SJMP MULAI
KEY10:
MOV P2,#0FBH ; Buat P2.2=0 (Untuk Baca Tombol 4,5,6,E,F2)
JB P3.7,KEY11
MOV P0,#0A8H
SJMP MULAI
KEY11:
JB P3.6,KEY12
MOV P0,#28H
SJMP MULAI
KEY12:
JB P3.5,KEY13
MOV P0,#29H
SJMP MULAI
KEY13:
JB P3.4,KEY14
MOV P0,#71H
LJMP MULAI
KEY14:
JB P3.3,KEY15
MOV P0,#22H
LJMP MULAI
KEY15:
MOV P2,#0F7H ; Buat P2.3=0 (Untuk Baca Tombol 7,8,9,F,F1)
JB P3.7,KEY16
MOV P0,#0E8H
LJMP MULAI
KEY16:
JB P3.6,KEY17
MOV P0,#21H
LJMP MULAI
KEY17:
JB P3.5,KEY18
MOV P0,#20H
LJMP MULAI
KEY18:
JB P3.4,KEY19
MOV P0,#67H
LJMP MULAI
KEY19:
JB P3.3,KEY20
MOV P0,#0E0H
KEY20:
LJMP MULAI ; ulangi lagi dari awal
END
Part 2
;- BAB3_15.ASM -------------------------------------------------------------------
;
; Program untuk membaca tombol-tombol yang disusun secara matrik,
; masukan tombol pada port 1, keluaran tombol pada port 2 dan hasil
; ditampilkan pada display 7 segment di port 0
; Penggunaan Lokasi memori RAM:
; 70h : menyimpan data pembanding masukan P3
; 71h : menyimpan awal indeks data (per baris pada sebuah kolom)
; 72h : menyimpan indeks data yang akan ditampilkan ke 7-segmen
; 73h : menyimpan jumlah baris tombol matriks
; Cara 2 : pakai metoda pembanding melalui RAM internal AT89C51/52
;
; ------------------------------------------------------------------------------
ORG 0H
;
MULAI:
MOV 73H,#5 ;jumlah baris tombol matrik
MOV R5,#0FEH ;data scan untuk port 2 (kolom, active low)
MOV DPTR,#ANGKA ;DPTR menunjuk ke awal data tampilan
MOV 71H,#0 ;awal indeks data per baris
ULANG:
MOV 70H,#07FH ;data pembanding masukan P3
MOV 72H,#0 ;indeks untuk baris bersangkutan
ULANG1:
MOV P2,R5 ;kirim data scan ke Port 2
MOV A,P3 ;baca hasilnya di Port 3
;tombol mana yang ditekan
CJNE A,70H,GESER1 ;apakah sama dengan data pembanding?
MOV A,72H ;ya, indeks baris
ADD A,71H ;ditambah awal indeks data pd baris tsb.
MOVC A,@A+DPTR ;untuk membaca data yang sesuai
MOV P0,A ;untuk ditampilkan ke 7-segmen (P0)
SJMP MULAI ;ulangi lagi dari Mulai
GESER1:
INC 72H ;tidak, naikkan indeks baris (next row)
MOV A,70H ;data pembanding
RR A ;digeser-putar ke kanan
MOV 70H,A ;sebanyak 1 bit (utk scan kolom berikutnya)
MOV A,72H
CJNE A,#4,ULANG1 ;ulangi sebanyak kolom tombol
NEXTSCAN:
MOV A,71H ;indeks baris per kolom dinaikkan 5
ADD A,#5 ;agar menunjuk ke kolom berikut
MOV 71H,A ;pada baris pertama
MOV A,R5 ;
RL A ;data scan di-rotate agar
MOV R5,A ;menunjuk ke kolom berikutnya
DJNZ 73H,ULANG ;jumlah baris dikurangi 1
;jika <> 0 ulangi proses dari "Ulang"
MOV P2,#0FFH ;matikan tampilan 7-segmen
LJMP MULAI ;ulangi proses dari awal
;-------------------------------------------------------------------------------
; data-data untuk tampilan 7-segmen disimpan di
; memori program (menyatu dengan program)
;-------------------------------------------------------------------------------
ANGKA: DB 0cH,0f9H,0a4H,0b0H,99H,92H,82H,0f8H,80H,90H,0A8H
DB 28H,29H,71H,0BAH,0E8H,21H,20H,67H,0E0H
END
Hope this is useful & happy learning!