SMK Binawiyata Sragen

Kontrol Motor Stepper

Rangkaian :
Code List :
 ORG    0H
 JMP    MAIN
 ORG    0BH
 JMP    TMR0 
 OK    EQU  7FH
 N1    EQU  7EH 
 N2    EQU  7DH ; BA ARZESH TARIN 
 N21   EQU  7CH
 DN    EQU  7BH   
 TMP   EQU  7AH 
 DHTMP EQU  79H
 DLTMP EQU  78H
 DTMP1  EQU  77H
 DTMP2  EQU  76H
 MDTMP1  EQU  75H
 MDTMP2  EQU  74H
 STEPM  EQU  73H
 KEYNUM EQU 72H
 SROTATION BIT 2FH  
 PKEY  EQU  P1  
 ORG 30H
MAIN: MOV    P0,#0H
 MOV    IE,#82H
 MOV    TMOD,#1H 
 MOV    N1,#0
 MOV    N2,#0 
 SETB   TR0
 CLR    SROTATION
 MOV    STEPM,#99H
M1: CALL   KEY
 JNB    SROTATION,M1
 CALL   BCD2DEC 
M2: CALL   ROTAION
 DJNZ   N21,M2
 CLR    SROTATION
 JMP    M1
 
;--------------------------- ROTAION
ROTAION:
 CALL   MDELAY
 MOV    A,STEPM
 RR     A
 MOV    P0,A
 MOV   STEPM,A
 CALL   MDELAY 
 RET 
;--------------------------- TIMER 0
TMR0: MOV    TMP,A
 MOV    DHTMP,DPH
 MOV    DLTMP,DPL
 MOV    TH0,#0ECH
 MOV    TL0,#077H
 CLR    TR0
 CALL   DISPLAY
 SETB   TR0
 MOV    DPH,DHTMP
 MOV    DPL,DLTMP
 MOV    A,TMP
 RETI
;--------------------------- DISPALY
DISPLAY:
 MOV    DN,N1
 CALL   NUM2SEG
 MOV    A,DN
 CPL    A
 MOV    P2,A
 SETB    P3.7 
 CALL   DELAY
 CLR   P3.7
 MOV    DN,N2
 CALL   NUM2SEG
 MOV    A,DN
 CPL    A
 MOV    P2,A 
 SETB    P3.6
 CALL   DELAY
 CLR    P3.6 
 RET
;---------------------------KEYBOARD
KEY:  MOV   PKEY,#0FH
 MOV   A,PKEY
 ANL   A,#0FH
 CJNE  A,#0FH,KEY2 ;KEY1
 JMP   KFNL
KEY2: CALL  MDELAY
 MOV   A,PKEY
 ANL   A,#0FH
 CJNE  A,#0FH,KEY3
 JMP   KFNL
KEY3: MOV   R0,#4
KEY31: RRC   A
 JNC   KEY4
 DJNZ  R0,KEY31
 JMP   KFNL
KEY4: CJNE  R0,#4,KEY42
 MOV   DPTR,#ROW_1
 JMP   KEY5
KEY42: CJNE  R0,#3,KEY43
 MOV   DPTR,#ROW_2
 JMP   KEY5
KEY43: CJNE  R0,#2,KEY44
 MOV   DPTR,#ROW_3
 JMP   KEY5
KEY44: CJNE  R0,#1,KFNL
 MOV   DPTR,#ROW_4
 JMP   KEY5
;----------
KEY5: MOV   PKEY,#0FFH
 MOV   PKEY,#0F0H
 NOP
 NOP
 NOP
 NOP
 MOV   A,PKEY
 SWAP  A 
 ANL   A,#0FH
 MOV   R0,#4
KEY51: RRC   A
 JNC   KEY6
 DJNZ  R0,KEY51
 JMP   KFNL
KEY6: CJNE  R0,#4,KEY61
 JMP   KEY7
KEY61: CJNE  R0,#3,KEY62
 INC   DPTR
 JMP   KEY7
KEY62: CJNE  R0,#2,KEY63
 INC   DPTR
 INC   DPTR 
 JMP   KEY7
KEY63: CJNE  R0,#1,KFNL
 INC   DPTR
 INC   DPTR 
 INC   DPTR
 JMP   KEY7
;----------
KEY7: MOV    A,#0
 MOVC   A,@A+DPTR
 MOV    KEYNUM,A
 MOV    A,#N2
 ADD    A,R1
 MOV    R0,A
 MOV    @R0,KEYNUM
KEY8: MOV    PKEY,#0FH
 MOV    A,PKEY
 CJNE   A,#0FH,KEY8
 INC    R1
 CJNE   R1,#2,KFNL
 MOV    R1,#0 
 SETB   SROTATION 
 JMP    KFNL
KFNL: RET   

;------------------------------------------------
NUM2SEG:MOV   DPTR,#TABLE
 MOV   A,DN
 MOVC  A,@A+DPTR
 MOV   DN,A

 RET
;--------------------------- DELAY
DELAY: MOV    DTMP1,#25
DD2: MOV    DTMP2,#25
DD1: DJNZ   DTMP2,DD1
 DJNZ   DTMP1,DD2
 RET
;--------------------------- MOTOR DELAY
MDELAY: MOV    MDTMP1,#50
MDD2: MOV    MDTMP2,#250
MDD1: DJNZ   MDTMP2,MDD1
 DJNZ   MDTMP1,MDD2
 RET
;--------------------------- DED2DEC
BCD2DEC:
 MOV   B,#10
 MOV   A,N2
 MUL   AB
 ADD   A,N1
 ADD   A,#1
 MOV   N21,A 
 RET
;------------------------------------------------
TABLE: DB    3FH,06H,5BH,4FH,66H,6DH,7DH,27H,7FH,6FH,00H,80H,40H
;------------------------------------------------
ROW_1: DB   1,2,3
ROW_2:  DB   4,5,6
ROW_3: DB   7,8,9
ROW_4: DB   '*',0,'#'
 
END 
Share:

Tidak ada komentar:

Posting Komentar

Silahkan berkomentar !

Jadwal Waktu Sholat

TIME WIB

TV EDUKASI LIVE

Popular Posts

myBlog

Recent Posts

Pages