Digital Clock dengan menggunakan led dot matrix
Daftar Komponen :
IC AT89C51
IC 74164
Resistor 10k
Capasitor 33p
Dot matrix
Kabel Penghubung
Crystal ( x-tal )
Sumber tegangan 5v
Elco 47 uf 16 v
Respack
tidak usah panjang lebar ini source codenya :
;=================================================
;PROGRAM 4.1:
;=================================================
;PORT0=DATA SEGMEN
;PORT2=DIGIT SELECT
;PORT 3.2=SET JAM
;PORT 3.3=SET MENIT
;PORT 3.4=SET DETIK
$MOD51
SEGM EQU P0
DGSEL EQU P2
DSEG
ORG 50H
JAM: DS 1
MENIT: DS 1
DETIK: DS 1
DTK20: DS 1
TSCAN: DS 1
DISPBUF: DS 32
S_DTK BIT P3.0
S_MNT BIT P3.2
S_JAM BIT P3.4
BARIS EQU P0
DTA BIT P2.0
MRST BIT P2.2
CLOCK BIT P2.4
JKL EQU 40
CSEG
ORG 0H
JMP START
ORG 0BH
JMP TIMER0
START: MOV JAM,#0
MOV MENIT,#0
MOV DETIK,#0
MOV DPTR,#TBL
MOV TMOD,#11H
MOV TH0,#HIGH(-50000)
MOV TL0,#LOW(-50000)
MOV DTK20,#20
SETB EA
SETB ET0
SETB TR0
MAIN:
MOV TSCAN,#100
LOOP:
CALL DISPLAY
DJNZ TSCAN,LOOP
CALL SCAN_INPUT
JMP MAIN
;SUB PROGRAM
TIMER0:
MOV TH0,#HIGH(-5000)
MOV TL0,#LOW(-5000)
MOV R4,DTK20
CJNE R4,#10,TXX
MOV DISPBUF+12,#107
MOV DISPBUF+26,#107
TXX:
CJNE R4,#20,TXY
MOV DISPBUF+12,#127
MOV DISPBUF+26,#127
TXY:
DJNZ DTK20,X_TIM0
MOV DTK20,#20
INC DETIK
MOV R4,DETIK
CJNE R4,#60,X_TIM0
MOV DETIK,#0
INC MENIT
MOV R4,MENIT
CJNE R4,#60,X_TIM0
MOV MENIT,#0
INC JAM
MOV R4,JAM
CJNE R4,#24,X_TIM0
MOV JAM,#0
X_TIM0: RETI
SCAN_INPUT:
P_JAM: JB S_JAM,P_MNT
INC JAM
MOV A,JAM
CJNE A,#24,EXIT_SCAN
MOV JAM,#0
P_MNT: JB S_MNT,P_DTK
INC MENIT
MOV A,MENIT
CJNE A,#60,EXIT_SCAN
MOV MENIT,#0
P_DTK: JB S_DTK,EXIT_SCAN
INC DETIK
MOV A,DETIK
CJNE A,#60,EXIT_SCAN
MOV DETIK,#0
EXIT_SCAN: RET
DISPLAY:CALL CONVERT
MOV R0,#DISPBUF
CALL RST
MOV R6,#0
NKOLOM: MOV A,@R0
MOV BARIS,A
CALL TUNDA
MOV BARIS,#127
CALL CLK
INC R6
INC R0
CJNE R6,#JKL,NKOLOM
SDATA:
SETB DTA
CALL CLK
CLR DTA
RET
RST:
CLR MRST
NOP
SETB MRST
CALL SDATA
RET
CLK:
SETB CLOCK
NOP
CLR CLOCK
RET
TUNDA:
MOV B,#85
DJNZ B,$
RET
CONVERT:
MOV DPTR,#TBL
MOV R0,#DISPBUF
MOV R1,#JAM
N_CONV:
MOV A,@R1
MOV B,#10
DIV AB
PUSH B
MOV B,#6
MUL AB
MOV B,#6
CON1:
PUSH ACC
MOVC A,@A+DPTR
MOV @R0,A
INC R0
POP ACC
INC A
DJNZ B,CON1
POP B
MOV A,#6
MUL AB
MOV B,#6
CON2:
PUSH ACC
MOVC A,@A+DPTR
MOV @R0,A
INC R0
POP ACC
INC A
DJNZ B,CON2
INC R0
MOV @R0,#127
INC R0
INC R1
CJNE R1,#detik+1,n_conv
RET
DELAY: MOV R6,#10
DLY: MOV R5,#150
DJNZ R5,$
DJNZ R6,DLY
RET
;angka
;0123456789=10 chr
tbl:
db 65,46,54,58,65,127 ;0
db 127,61,0,63,127,127 ;1
db 29,46,54,54,57,127 ;2
db 93,54,54,54,73,127 ;3
db 103,107,109,0,111,127 ;4
db 88,58,58,58,70,127 ;5
db 67,53,54,54,79,127 ;6
db 126,14,118,122,124,127 ;7
db 73,54,54,54,73,127 ;8
db 121,54,54,86,97,127 ;9
end
Kekurangan dari ini tidak ada RTCnya sehingga kalau listrik padam kita harus set ulang .Selamat mencoba....
No comments:
Post a Comment