PARTNER

Minggu, 15 Agustus 2010

Countdown ( Pencacah Mundur ) Timer Menggunakan AT89c2051

Sebuah count-down (Pencacah mundur) timer sederhana menggunakan display LED yang mampu mencacah dalam beberapa menit dan detik. Tiga tombol dibawah LED digunakan untuk mengeset menit, detik dan tombol kontrol start/stop. Bila pencacahan telah selesai maka Alarm Buzzer akan berbunyi dan display LED menampilkan angka Nol. Alarm Buzzer akan berhenti berbunyi dengan menekan tombol start/stop. Rangkaian count-down (Pencacah mundur) timer dibangun menggunakan microcontoller keluarga mcs-51 yaitu AT89c2051.

Gambar Rangkaian count-down (Pencacah mundur) timer menggunakan AT89c2051.


Source code.
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;PROGRAM FOR TIMER
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
include REG_52.PDF

RB0 EQU 000H ; Select Register Bank 0
RB1 EQU 008H ; Select Register Bank 1 ...poke to PSW to use

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
; PORT DECLERATION
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DIS_A EQU P1.5
DIS_B EQU P1.4
DIS_C EQU P1.3
DIS_D EQU P1.1
DIS_E EQU P1.2
DIS_F EQU P1.6
DIS_G EQU P1.7

DIS1 EQU P1.0
DIS2 EQU P3.7
DIS3 EQU P3.5
DIS4 EQU P3.4

START EQU P3.0
STOP EQU P3.1
RESETS EQU P3.2

BUZZER EQU P3.3
DSEG ; This is internal data memory
ORG 20H ; Bit adressable memory

COUNT: DS 1
SPEED: DS 1
VALUE_1: DS 1
VALUE_2: DS 1
VALUE_3: DS 1
VALUE_4: DS 1

NUMB1: DS 1
NUMB2: DS 1
NUMB3: DS 1
NUMB4: DS 1

SEC: DS 1
MIN: DS 1


FINAL: DS 1
FIN: DS 1
TENS: DS 1
STACK DATA 3FH
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CSEG AT 0 ; RESET VECTOR
;---------==========----------==========---------=========---------
; PROCESSOR INTERRUPT AND RESET VECTORS
;---------==========----------==========---------=========---------
ORG 00H ; Reset
JMP MAIN

ORG 000BH ;Timer Interrupt0
JMP REFRESH

;---------==========----------==========---------=========---------
; Main routine. Program execution starts here.
;---------==========----------==========---------=========---------
MAIN:
MOV PSW,#RB0 ; Select register bank 0
MOV SP,STACK
MOV SPEED,#00H
MOV COUNT,#00H
CLR DIS1
CLR DIS2
CLR DIS3
CLR DIS4
MOV TMOD,#01H ;enable timer0 for scanning
MOV TL0,#00H
MOV TH0,#0FDH
SETB ET0
SETB EA
SETB TR0 ;Start the Timer
MOV VALUE_1,#15H
MOV VALUE_2,#15H
MOV VALUE_3,#15H
MOV VALUE_4,#15H
CLR BUZZER
TOP1: SETB START
JB START,$
SETB BUZZER
MOV SEC,#00H
MOV MIN,#00H
TOP:
SETB STOP
MOV R3,#05H ;1 SEC DELAY
REP3: MOV R1,#0BFH
REP2: MOV R2,#0FFH
REP1: JNB STOP,TIM_STOP1
DJNZ R2,REP1
DJNZ R1,REP2
CLR BUZZER
DJNZ R3,REP3
INC SEC
MOV A,MIN
CJNE A,#04H,FGV1
MOV A,SEC
CJNE A,#40,FGV1
SETB BUZZER
CALL DELAY
CLR BUZZER
CALL DELAY
SETB BUZZER
AJMP DOWN1

TIM_STOP1: AJMP TIM_STOP
FGV1: MOV A,MIN
CJNE A,#09H,FGV2
MOV A,SEC
CJNE A,#40,FGV2
SETB BUZZER
CALL DELAY
CLR BUZZER
CALL DELAY
SETB BUZZER
AJMP DOWN1
FGV2:
MOV A,MIN
CJNE A,#14,FGV3
MOV A,SEC
CJNE A,#40,FGV3
SETB BUZZER
CALL DELAY
CLR BUZZER
CALL DELAY
SETB BUZZER
AJMP DOWN1
FGV3:
MOV A,MIN
CJNE A,#19,FGV4
MOV A,SEC
CJNE A,#40,FGV4
SETB BUZZER
CALL DELAY
CLR BUZZER
CALL DELAY
SETB BUZZER
AJMP DOWN1
FGV4:
MOV A,MIN
CJNE A,#24,FGV5
MOV A,SEC
CJNE A,#40,FGV5
SETB BUZZER
CALL DELAY
CLR BUZZER
CALL DELAY
SETB BUZZER
AJMP DOWN1
FGV5:
MOV A,MIN
CJNE A,#29,FGV6
MOV A,SEC
CJNE A,#40,FGV6
SETB BUZZER
CALL DELAY
CLR BUZZER
CALL DELAY
SETB BUZZER
AJMP DOWN1
FGV6:
DOWN1:
MOV A,SEC
CJNE A,#60,DCF1
MOV SEC,#00H
INC MIN
SETB BUZZER
MOV A,MIN
CJNE A,#60,DCF1
MOV MIN,#00H
DCF1: MOV R2,SEC
ACALL HEX2BCD
MOV VALUE_4,R3 ;MOV LSB TO DISPLAY
MOV VALUE_3,R4
MOV R2,MIN
ACALL HEX2BCD
MOV VALUE_2,R3 ;MOV LSB TO DISPLAY
MOV VALUE_1,R4
AJMP TOP

TIM_STOP:
SETB BUZZER
CALL DELAY
CLR BUZZER
JNB STOP,$
CALL DELAY
JB STOP,$
SETB BUZZER
CALL DELAY
CLR BUZZER
MOV SEC,#00H
MOV MIN,#00H
MOV VALUE_1,#15H
MOV VALUE_2,#15H
MOV VALUE_3,#15H
MOV VALUE_4,#15H
AJMP TOP1
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
; 7 SEGMENT DISPLAY ROUTINE
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
DISP:
MOV R2,SPEED
CJNE R2,#00H,AAS1
CLR DIS_A
CLR DIS_B
CLR DIS_C
CLR DIS_D
CLR DIS_E
CLR DIS_F
SETB DIS_G
RET
AAS1: CJNE R2,#01H,AS2
CLR DIS_B
CLR DIS_C
SETB DIS_A
SETB DIS_D
SETB DIS_E
SETB DIS_F
SETB DIS_G
RET
AS2: CJNE R2,#02H,AS3
CLR DIS_A
CLR DIS_B
CLR DIS_D
CLR DIS_E
CLR DIS_G
SETB DIS_C
SETB DIS_F
RET
AS3: CJNE R2,#03H,AS4
CLR DIS_A
CLR DIS_B
CLR DIS_C
CLR DIS_D
CLR DIS_G
SETB DIS_E
SETB DIS_F
RET
AS4: CJNE R2,#04H,AS5
CLR DIS_B
CLR DIS_C
CLR DIS_F
CLR DIS_G
SETB DIS_A
SETB DIS_D
SETB DIS_E
RET
AS5: CJNE R2,#05H,AS6
CLR DIS_A
CLR DIS_C
CLR DIS_D
CLR DIS_F
CLR DIS_G
SETB DIS_B
SETB DIS_E
RET
AS6: CJNE R2,#06H,AS7
CLR DIS_A
CLR DIS_C
CLR DIS_D
CLR DIS_E
CLR DIS_F
CLR DIS_G
SETB DIS_B
RET
AS7: CJNE R2,#07H,AS8
CLR DIS_A
CLR DIS_B
CLR DIS_C
SETB DIS_D
SETB DIS_E
SETB DIS_F
SETB DIS_G
RET
AS8: CJNE R2,#08H,AS9
CLR DIS_A
CLR DIS_B
CLR DIS_C
CLR DIS_D
CLR DIS_E
CLR DIS_F
CLR DIS_G
RET
AS9: CJNE R2,#09H,AS10
CLR DIS_A
CLR DIS_B
CLR DIS_C
CLR DIS_D
CLR DIS_F
CLR DIS_G
SETB DIS_E
RET
AS10: CJNE R2,#15H,AS11 ;symbol for -
SETB DIS_A
SETB DIS_B
SETB DIS_C
SETB DIS_D
SETB DIS_E
SETB DIS_F
CLR DIS_G
RET
AS11: CJNE R2,#16H,AS12 ;switch off all disp
SETB DIS_A
SETB DIS_B
SETB DIS_C
SETB DIS_D
SETB DIS_E
SETB DIS_F
SETB DIS_G
RET
AS12: MOV SPEED,#00H
AJMP DISP
;**********************************************************
; INTRRUPT ROUTINE TO REFRESH THE DISPLAY
;**********************************************************
REFRESH:
PUSH PSW ; save current registerset
MOV PSW,#RB1
PUSH ACC
INC COUNT
MOV R4,COUNT
QA1: CJNE R4,#01H,QA2
MOV SPEED,VALUE_1
SETB DIS1
CLR DIS2
CLR DIS3
CLR DIS4
CALL DISP
AJMP DOWN
QA2: CJNE R4,#02H,QA3
MOV SPEED,VALUE_2
CLR DIS1
SETB DIS2
CLR DIS3
CLR DIS4
CALL DISP
AJMP DOWN
QA3: CJNE R4,#03H,QA4
MOV SPEED,VALUE_3
CLR DIS1
CLR DIS2
SETB DIS3
CLR DIS4
CALL DISP
AJMP DOWN
QA4: CJNE R4,#04H,QA5
MOV SPEED,VALUE_4
CLR DIS1
CLR DIS2
CLR DIS3
SETB DIS4
CALL DISP
AJMP DOWN
QA5: MOV COUNT,#01H
MOV R4,COUNT
AJMP QA1
DOWN: MOV TL0,#0FFH
MOV TH0,#0F0H
POP ACC
POP PSW
RETI
;**********************************************************
DELAY:
MOV R1,#0FFH
RAP2: MOV R2,#0FFH
RAP1: NOP
DJNZ R2,RAP1
DJNZ R1,RAP2
RET
;**********************************************************
Hex2BCD:
MOV R1,#00H ; MSByte
MOV R3,#00D
MOV R4,#00D
MOV R5,#00D
MOV R6,#00D
MOV R7,#00D
CALL H2B
RET
H2B: MOV B,#10D
MOV A,R2
DIV AB
MOV R3,B ;
MOV B,#10 ; R7,R6,R5,R4,R3
DIV AB
MOV R4,B
MOV R5,A
CJNE R1,#0H,HIGH_BYTE ; CHECK FOR HIGH BYTE
SJMP ENDD
HIGH_BYTE:
MOV A,#6
ADD A,R3
MOV B,#10
DIV AB
MOV R3,B
ADD A,#5
ADD A,R4
MOV B,#10
DIV AB
MOV R4,B
ADD A,#2
ADD A,R5
MOV B,#10
DIV AB
MOV R5,B
CJNE R6,#00D,ADD_IT
SJMP CONTINUE
ADD_IT:
ADD A,R6
CONTINUE:
MOV R6,A
DJNZ R1,HIGH_BYTE
MOV B, #10D
MOV A,R6
DIV AB
MOV R6,B
MOV R7,A
ENDD: RET
END
 
Source  : http://elkaubisa.blogspot.com or http://www.8051projects.info/proj.asp?ID=61
Share:

0 komentar:

Posting Komentar

Blog Archive

Blogger templates