1. Ma trận phím + 7 Thanh
;chương trình code asm
;Design By Chipkool_online
;SV ĐH Kinh tế - Kỹ Thuật công Nghiệp
ORG 00H
;QUET HANG 1
MOV P3,#11111110B
JNB P3.4,PHIM7
JNB P3.5,PHIM8
JNB P3.6,PHIM9
JNB P3.7,PHIM10
;QUET HANG 2
MOV P3,#11111101B
JNB P3.4,PHIM4
JNB P3.5,PHIM5
JNB P3.6,PHIM6
JNB P3.7,PHIM11
;QUET HANG 3
MOV P3,#11111011B
JNB P3.4,PHIM1
JNB P3.5,PHIM2
JNB P3.6,PHIM3
JNB P3.7,PHIM12
;QUET HANG 4
MOV P3,#11110111B
JNB P3.4,PHIM13
JNB P3.5,PHIM14
JNB P3.6,PHIM15
JNB P3.7,PHIM16
JMP MAIN
PHIM1:
MOV R0,#1
CALL CTHT
LJMP MAIN
PHIM2:
MOV R0,#2
CALL CTHT
LJMP MAIN
PHIM3:
MOV R0,#3
CALL CTHT
LJMP MAIN
PHIM4:
MOV R0,#4
CALL CTHT
LJMP MAIN
PHIM5:
MOV R0,#5
CALL CTHT
LJMP MAIN
PHIM6:
MOV R0,#6
CALL CTHT
LJMP MAIN
PHIM7:
MOV R0,#7
CALL CTHT
LJMP MAIN
PHIM8:
MOV R0,#8
CALL CTHT
LJMP MAIN
PHIM9:
MOV R0,#9
CALL CTHT
LJMP MAIN
PHIM10:
MOV R0,#10
CALL CTHT
LJMP MAIN
PHIM11:
MOV R0,#11
CALL CTHT
LJMP MAIN
PHIM12:
MOV R0,#12
CALL CTHT
LJMP MAIN
PHIM13:
MOV R0,#13
CALL CTHT
LJMP MAIN
PHIM14:
MOV R0,#14
CALL CTHT
LJMP MAIN
PHIM15:
MOV R0,#15
CALL CTHT
LJMP MAIN
PHIM16:
MOV R0,#16
CALL CTHT
LJMP MAIN
CTHT:
MOV R7,#20
QUAY:
MOV A,R0
MOV B,#10
DIV AB
MOV DPTR,#MALED
MOVC A,@A+DPTR
MOV P0,A
SETB P2.0
CALL DELAY
CLR P2.0
MOV A,B
MOVC A,@A+DPTR
MOV P0,A
SETB P2.1
CALL DELAY
CLR P2.1
DJNZ R7,QUAY
RET
MALED:DB 11000000B,11111001B,10100100B,10110000B,10011001B,10010010B,10000010B,11111000B,10000000B,10010000B
DELAY:
MOV R1,#100
LAP:
NOP
NOP
DJNZ R1,LAP
RET
END
;P2=data pin
;P3.0 -> RS pin
;P3.1 -> R/W pin
;P3.2 -> E pin
;RS EQU P3.0
;RW EQU P3.1
;E EQU P3.2
ORG 00H
MAIN:
;*** chuong trinh khoi tao LCD
MOV A,#38H ;init. LCD 2 dong ma tran 5x7
ACALL CSTROBE
MOV A,#0EH ;LCD on, cursor on
ACALL CSTROBE
MOV A,#01H ;clear LCD
ACALL CSTROBE
;QUET HANG 1
MOV P1,#11111110B
JNB P1.4,PHIM1
JNB P1.5,PHIM2
JNB P1.6,PHIM3
JNB P1.7,PHIM4
;QUET HANG 2
MOV P1,#11111101B
JNB P1.4,PHIM5
JNB P1.5,PHIM6
JNB P1.6,PHIM7
JNB P1.7,PHIM8
;QUET HANG 3
MOV P1,#11111011B
JNB P1.4,PHIM9
JNB P1.5,PHIM10
JNB P1.6,PHIM11
JNB P1.7,PHIM12
;QUET HANG 4
MOV P1,#11110111B
JNB P1.4,PHIM13
JNB P1.5,PHIM14
JNB P1.6,PHIM15
JNB P1.7,PHIM16
LJMP MAIN
PHIM1:; hien thi chay chu sang trai
LCALL CTSO1
LJMP MAIN
PHIM2:
LCALL CTSO2
LJMP MAIN
PHIM3:
LCALL CTSO3
LJMP MAIN
PHIM4:
LCALL CTSO4
LJMP MAIN
PHIM5:
LCALL CTSO5
LJMP MAIN
PHIM6:
LCALL CTSO6
LJMP MAIN
PHIM7:
LCALL CTSO7
LJMP MAIN
PHIM8:
LCALL CTSO8
LJMP MAIN
PHIM9:
LCALL CTSO9
LJMP MAIN
PHIM10:
LCALL CTSO10
LJMP MAIN
PHIM11:
LCALL CTSO11
LJMP MAIN
PHIM12:
LCALL CTSO12
LJMP MAIN
PHIM13:
LCALL CTB
LJMP MAIN
PHIM14:
LCALL CTA
LJMP MAIN
PHIM15:
LJMP MAIN
PHIM16:
LJMP MAIN
;***************CHUONG TRINH CON CAC SO 1 - 12
CTSO1:
;Hien dong 1
MOV A,#80H
LCALL CSTROBE
LCALL DELAY100MS
;
MOV A,#'1'
LCALL DSTROBE
LCALL DELAY100MS
RET
CTSO2:
;Hien dong 1
MOV A,#80H
LCALL CSTROBE
LCALL DELAY100MS
;
MOV A,#'2'
LCALL DSTROBE
LCALL DELAY100MS
RET
CTSO3:
;Hien dong 1
MOV A,#80H
LCALL CSTROBE
LCALL DELAY100MS
;
MOV A,#'3'
LCALL DSTROBE
LCALL DELAY100MS
RET
CTSO4:
;Hien dong 1
MOV A,#80H
LCALL CSTROBE
LCALL DELAY100MS
;
MOV A,#'4'
LCALL DSTROBE
LCALL DELAY100MS
RET
CTSO5:
;Hien dong 1
MOV A,#80H
LCALL CSTROBE
LCALL DELAY100MS
;
MOV A,#'5'
LCALL DSTROBE
LCALL DELAY100MS
RET
CTSO6:
;Hien dong 1
MOV A,#80H
LCALL CSTROBE
LCALL DELAY100MS
;
MOV A,#'6'
LCALL DSTROBE
LCALL DELAY100MS
RET
CTSO7:
;Hien dong 1
MOV A,#80H
LCALL CSTROBE
LCALL DELAY100MS
;
MOV A,#'7'
LCALL DSTROBE
LCALL DELAY100MS
RET
CTSO8:
;Hien dong 1
MOV A,#80H
LCALL CSTROBE
LCALL DELAY100MS
;
MOV A,#'8'
LCALL DSTROBE
LCALL DELAY100MS
RET
CTSO9:
;Hien dong 1
MOV A,#80H
LCALL CSTROBE
LCALL DELAY100MS
;
MOV A,#'9'
LCALL DSTROBE
LCALL DELAY100MS
RET
CTSO10:
;Hien dong 1
MOV A,#80H
LCALL CSTROBE
LCALL DELAY100MS
;
MOV A,#'10'
LCALL DSTROBE
LCALL DELAY100MS
RET
CTSO11:
;Hien dong 1
MOV A,#80H
LCALL CSTROBE
LCALL DELAY100MS
;
MOV A,#'11'
LCALL DSTROBE
LCALL DELAY100MS
RET
CTSO12:
;Hien dong 1
MOV A,#80H
LCALL CSTROBE
LCALL DELAY100MS
;
MOV A,#'12'
LCALL DSTROBE
LCALL DELAY100MS
RET
;*******************HIEN THI CHAY CHU DHKTKTCN
CTA:
MOV A,#06H ; con tro dich phai
ACALL CSTROBE
MOV A,#80H ;chuyen Con tro den dong 1 vi tri 0
ACALL CSTROBE
MOV DPTR,#MYDATA ;Dua con tro du lieu toi bang
DONG1: CLR A
MOVC A,@A+DPTR
JZ THOAT ;Neu A=0 thi thi thoat
LCALL DSTROBE
INC DPTR
SJMP DONG1
THOAT:
MOV A,#18H
LCALL CSTROBE
LCALL DELAY100MS
SJMP THOAT
RET
; ********************HIEN THI CHU CHIPKOOL - UNETI
CTB:
MOV A,#0C1H; Lenh dong 2
LCALL CSTROBE
LCALL DELAY100MS
MOV R0,#1; LAP 1 LAN HIEN THI 1 LAN
LAP1:
MOV A,#'C'
LCALL DSTROBE
LCALL DELAY100MS
;
MOV A,#'H'
LCALL DSTROBE
LCALL DELAY100MS
;
MOV A,#'I'
LCALL DSTROBE
LCALL DELAY100MS
;
MOV A,#'P'
LCALL DSTROBE
LCALL DELAY100MS
;
MOV A,#'K'
LCALL DSTROBE
LCALL DELAY100MS
;
MOV A,#'O'
LCALL DSTROBE
LCALL DELAY100MS
;
MOV A,#'O'
LCALL DSTROBE
LCALL DELAY100MS
;
MOV A,#'L'
LCALL DSTROBE
LCALL DELAY100MS
;
MOV A,#'-'
LCALL DSTROBE
LCALL DELAY100MS
; ******************UNETI
MOV A,#'U'
LCALL DSTROBE
LCALL DELAY100MS
;
MOV A,#'N'
LCALL DSTROBE
LCALL DELAY100MS
;
MOV A,#'E'
LCALL DSTROBE
LCALL DELAY100MS
;
MOV A,#'T'
LCALL DSTROBE
LCALL DELAY100MS
;
MOV A,#'I'
LCALL DSTROBE
LCALL DELAY100MS
;
DJNZ R0,LAP1
CALL DELAY100MS
CALL DELAY100MS
CALL DELAY100MS
RET
; ***********************************BAT DAU CHUONG TRINH CON LCD*******************
CSTROBE: ;command strobe
ACALL READY ;is LCD ready?
MOV P2,A ;xuat ma lenh
CLR P3.0 ;RS=0: lenh
CLR P3.1 ;R/W=0 -> ghi ra LCD
SETB P3.2 ;E=1 -> tao canh xuong
CLR P3.2 ;E=0 chot
RET
DSTROBE: ;data strobe
ACALL READY ;is LCD ready?
MOV P2,A ;xuat du lieu
SETB P3.0 ;RS=1 for data
CLR P3.1 ;R/W=0 to write to LCD
SETB P3.2 ;E=1 -> tao canh xuong
CLR P3.2 ;E=0 chot
RET
; kiem tra co BF
READY: SETB P2.7 ;P2.7: input
CLR P3.0 ;RS=0: thanh ghi lenh
SETB P3.1 ;R/W=1: doc
BACK: CLR P3.2 ;E=0 -> tao canh lenh
SETB P3.2 ;E=1
JB P2.7,BACK ;cho co flag bang 0
RET
DELAY100MS:
MOV R2,#100
DL5: MOV R1,#250
DL4: NOP
NOP
DJNZ R1,DL4
DJNZ R2,DL5
RET
ORG 250H
MYDATA:
DB "DAI HOC KINH TE KY THUAT CONG NGHIEP"
END
3. Ma trận phím + Ma trận led
ORG 00H
MAIN:
;QUET HANG 1
MOV P0,#11111110B
JNB P0.4,PHIM1 ;SO 7
JNB P0.5,PHIM2 ;SO 8
JNB P0.6,PHIM3 ;SO 9
JNB P0.7,PHIM4 ;KT CHIA
;QUET HANG 2
MOV P0,#11111101B
JNB P0.4,PHIM5 ;SO 4
JNB P0.5,PHIM6 ;SO 5
JNB P0.6,PHIM7 ;SO 6
JNB P0.7,PHIM8 ;KT NHAN
;QUET HANG 3
MOV P0,#11111011B
JNB P0.4,PHIM9 ;SO 1
JNB P0.5,PHIM10 ;SO 2
JNB P0.6,PHIM11 ;SO 3
JNB P0.7,PHIM12 ;KT -
;QUET HANG 4
MOV P0,#11110111B
JNB P0.4,PHIM13 ; ON
JNB P0.5,PHIM14 ;SO 0
JNB P0.6,PHIM15 ;KT =
JNB P0.7,PHIM16 ;KT +
LJMP MAIN
PHIM1:
CALL MS1
LJMP MAIN
PHIM2:
CALL MS2
LJMP MAIN
PHIM3:
CALL MS3
LJMP MAIN
PHIM4:
CALL MS4
LJMP MAIN
PHIM5:
CALL MS5
LJMP MAIN
PHIM6:
CALL MS6
LJMP MAIN
PHIM7:
CALL MS7
LJMP MAIN
PHIM8:
CALL MS8
LJMP MAIN
PHIM9:
CALL MS9
LJMP MAIN
PHIM10:
CALL MS10
LJMP MAIN
PHIM11:
CALL MS11
LJMP MAIN
PHIM12:
CALL MS12
LJMP MAIN
PHIM13:
CALL MS13
LJMP MAIN
PHIM14:
CALL MS14
LJMP MAIN
PHIM15:
CALL MS15
LJMP MAIN
PHIM16:
CALL MS16
LJMP MAIN
MS1:
MOV DPTR,#MASO1
CALL CTHT
RET
MS2:
MOV DPTR,#MASO2
CALL CTHT
RET
MS3:
MOV DPTR,#MASO3
CALL CTHT
RET
MS4:
MOV DPTR,#MASO4
CALL CTHT
RET
MS5:
MOV DPTR,#MASO5
CALL CTHT
RET
MS6:
MOV DPTR,#MASO6
CALL CTHT
RET
MS7:
MOV DPTR,#MASO7
CALL CTHT
RET
MS8:
MOV DPTR,#MASO8
CALL CTHT
RET
MS9:
MOV DPTR,#MASO9
CALL CTHT
RET
MS10:
MOV DPTR,#MASO10
CALL CTHT
RET
MS11:
MOV DPTR,#MASO11
CALL CTHT
RET
MS12:
MOV DPTR,#MASO12
CALL CTHT
RET
MS13:
MOV DPTR,#MASO13
CALL CTHT
RET
MS14:
MOV DPTR,#MASO14
CALL CTHT
RET
MS15:
MOV DPTR,#MASO15
CALL CTHT
RET
MS16:
MOV DPTR,#MASO16
CALL CTHT
RET
CTHT:;CHUONG TRINH HIEN THI
MOV R2,#20
QUET:
MOV R0,#0
MOV R1,#01H
BACK_1:
MOV A,R0
MOVC A,@A+DPTR
MOV P2,A
MOV P3,R1
CALL DELAY
MOV P3,#00H
MOV A,R1
RL A
MOV R1,A
INC R0
CJNE R0,#8,BACK_1
DJNZ R2,Q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