單片機(jī)驅(qū)動(dòng)8×8點(diǎn)陣LED
CLK EQU P3.2
DINA EQU P3.3
DINB EQU P3.4
CLEAR EQU P3.5
ORG 0000H
AJMP MAIN
ORG 0100H
MAIN:
MOV SP,#70H ;設(shè)堆棧指針
MOV 50H,#07EH ;設(shè)置發(fā)送的列數(shù)據(jù)(Y0~Y7)
MOV 51H,#0BDH
MOV 52H,#0DBH
MOV 53H,#0E7H
MOV 54H,#0E7H
MOV 55H,#0DBH
MOV 56H,#0BDH
MOV 57H,#07EH
CLR CLEAR ;初始化I/O口
SETB CLK
SETB DINA
SETB DINB
SETB CLEAR
mainloop:
mov r6,#8h;設(shè)置掃描次數(shù)
mov dptr,#09000h;讀取掃描端口數(shù)據(jù)
MOV R1,#50H ;指定列數(shù)據(jù)指針
flashcy:
MOV A,@R1 ;讀取列數(shù)據(jù)
MOV R0,A
INC R1 ;列數(shù)據(jù)指針加1
CLR A
MOVC A,@A+DPTR
MOV P1,#0FFH
LCALL SENDTO
MOV P1,A
INC DPTR
LCALL DELAY
DJNZ R6,flashcy
SJMP MAINLOOP
sendto: ;發(fā)送數(shù)據(jù)子程序
PUSH ACC
CLR CLK
SENDTIME:
MOV R7,#08H
MOV A,R0
CLR C
SENDCY:
RRC A
MOV DINA,C
SETB CLK
CLR CLK
DJNZ R7,SENDCY
POP ACC
RET
DELAY: MOV R7,#01 ;延時(shí)子程序
DELAY0: MOV R4,#17
DELAY1: MOV R3,#28
DJNZ R3,$
DJNZ R4,DELAY1
DJNZ R7,DELAY0
RET
ORG 09000H
DB 0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,07FH ;X0~X7(列掃描)
end
評(píng)論