|
楼主 |
发表于 6-9-2004 10:41 AM
|
显示全部楼层
faiko 于 4-9-2004 04:23 PM 说 :
呵呵!怎样解决呢?post上来你改过的原码
; 8051 Timer With 7-Segment x 4 + Alarm + BZ
;---------------------------------------------------------------------
; MOV TL0,#(8192-5000).MOD.32
; MOV TH0,#(8192-5000)/32
LO EQU 24
HI EQU 99
;---------------------------------------------------------------------
CO EQU 200 ; Adj To Match Time 200 x 5 mS = 1 Second
ALB EQU 20H.0 ; Alarm Bit
BUF EQU 30H ; 7-Segment Buffer Ram 30H 31H 32H 33H 4 Bytes
MIN EQU 34H ; Min
SEC EQU 35H ; Second
DEDA EQU 36H ; DEDA Count 5 mS Count
SEC0 EQU 37H ; Old Second
MM EQU 38H ; Alarm Min
SS EQU 39H ; Alarm Second
;----------------------------------------------------------------------
; INPUT...
K1 EQU P3.7 ; K1 - Start / Continued Timer
K2 EQU P3.6 ; K2 - Stop / Pause Timer
K3 EQU P3.5 ; K3 - Reset Timer To 00:00
K4 EQU P3.4 ; K4 - Set Alarm / Set Alarm Finish
K5 EQU P3.3 ; K5 - Set Alarm Min
K6 EQU P3.2 ; K6 - Set Alarm Second
; OUTPUT...
OP_LAMP EQU P1.0 ; Opeartion Lamp
SEC_LED EQU P1.1 ; Second LED
ALM_LED EQU P1.2 ; Alarm On - LED On / Alarm Off - LED Off
TO_LED EQU P1.3 ; Time Out LED
SPK EQU P1.4 ; BZ
P_LED EQU P1.7 ; Power LED
;----------------------------------------------------------------------
ORG 0H
JMP BEGIN
ORG 0BH
JMP T0_INT
;----------------------------------------------------------------------
BEGIN:
CLR P_LED ; On Power LED
CLR ALB ; Off Alarm
MOV MM,#00 ; Default Alarm Time Min -- 00
MOV SS,#01 ; Default Alarm Time Second -- 00
RESET:
SETB OP_LAMP
SETB TO_LED
CALL LOAD_DATA ; Set 7-Segment Display 00:00
CALL INIT
;********************************************************************
; SCAN_KEY
; K1 - Start / Continued Timer
; K2 - Stop / Pause Timer
; K3 - Reset Timer To 00:00
; K4 - Set Alarm
;********************************************************************
; Scan K1 Start / Continued Timer ...
; Scan K4 Set Alarm ...
LOOP1:
CALL TIME_PRO ; Update Time Data
JB TO_LED,TOO1
JMP RESET
TOO1: CALL SCAN1 ; Scan 7-Segment
JB K1,L1 ; Press K1 Start Timer
CALL INIT_TIMER_START; Start Timer
JMP LOOP2
L1: JB K4,LOOP1 ; Press K4 Set Alarm
JNB K4,$
CALL SET_ALARM
CALL LOAD_DATA
JMP LOOP1
; Scan K2 Stop / Pause Timer ...
LOOP2:
CALL TIME_PRO ; Update Time Data
JB TO_LED,TOO2
JMP RESET
TOO2: CALL SCAN1 ; Scan 7-Segment
JNB K2,LOOP3 ; Press K2 Stop Timer / Pause Timer
JMP LOOP2
; Scan K1 Continued Timer ...
; Scan K3 Reset Timer ...
LOOP3:
CALL INIT_TIMER_STOP ; Stot Timer
CALL TIME_PRO ; Update Time Data
JB TO_LED,TOO3
JMP RESET
TOO3: CALL SCAN1 ; Scan 7-Segment
JB K1,L3 ; Prees K1 Continued Timer
JMP LOOP1
L3: JB K3,LOOP3 ; Press K3 Reset Timer
JMP RESET
;*********************************************************************
; K4 - Set Finish Alarm
; K5 - Set Alarm Min
; K6 - Set Alarm Second
;*********************************************************************
SET_ALARM:
CALL CONVA
; Scan K1 Adj Min ...
SK1:
CALL SCAN1 ; Scan 7-Segment
JB K5,SK2 ; Press K5 Count Up Min
INC MM
MOV A,MM
CJNE A,#30,N1 ; Maximize Display
MOV MM,#00
N1:
CALL CONVA
CALL SCANS
JMP SK1
; Scan K2 Adj Second ...
SK2:
JB K6,FINISH ; Press K6 Count Up Sec
INC SS
MOV A,SS
CJNE A,#60,N2 ; Maximize Display
MOV SS,#00
N2:
CALL CONVA
CALL SCANS
JMP SK1
FINISH:
JB K4,SK1
JNB K4,$
; CHECK MIN ...
MOV A,MM
CJNE A,#00,F1
; CHECK SEC ...
MOV A,SS
CJNE A,#00,F1
; OFF ALARM ...
CALL ALARM_OFF
JMP F2
F1:
CALL ALARM_ON
F2:
RET
;**********************************************************************
; ALM_LED On - Alarm On
; ALM_LED Off - Alarm Off
;**********************************************************************
ALARM_ON:
; Alarm On ...
SETB ALB
CLR ALM_LED
JMP AL1
ALARM_OFF:
; Alarm Off ...
CLR ALB
SETB ALM_LED
JMP AL1
AL1:
RET
;----------------------------------------------------------------------
TITLE: DB "8051 Timer With 7-Segment x 4 + Alarm + BZ"
;----------------------------------------------------------------------
; DELAY Xms R5*10 ms
DELAY:
MOV R6,#50
D1: MOV R7,#100
DJNZ R7,$
DJNZ R6,D1
DJNZ R5,DELAY
RET
;----------------------------------------------------------------------
; DELAY A WHILE
DELAY1:
MOV R6,#1
D2: MOV R7,#100
DJNZ R7,$
DJNZ R6,D2
DJNZ R5,DELAY1
RET
;----------------------------------------------------------------------
; 7-SEGMENT COMMON CATHODE
TABLE:
DB 3FH, 06H, 5BH, 4FH, 66H
DB 6DH, 7DH, 07H, 7FH, 6FH
DB 77H, 7CH, 58H, 5EH, 79H
DB 71H
;----------------------------------------------------------------------
LOAD_DATA:
MOV BUF, #3FH
MOV BUF+1,#3FH
MOV BUF+2,#3FH
MOV BUF+3,#3FH
RET
;----------------------------------------------------------------------
INIT:
MOV DEDA,#0
MOV SEC0,#0
MOV SEC,#0
MOV MIN,#0
RET
;----------------------------------------------------------------------
INIT_TIMER_START:
CLR OP_LAMP
MOV TMOD,#00000000B
MOV IE, #10000010B
MOV TL0,#LO
MOV TH0,#HI
SETB TR0
RET
;----------------------------------------------------------------------
INIT_TIMER_STOP:
MOV TMOD,#00000000B
MOV IE, #10000010B
MOV TL0,#LO
MOV TH0,#HI
CLR TR0
RET
;----------------------------------------------------------------------
; USE TIMER MODE 0
; COUNT=5ms/1us=5000
;----------------------------------------------------------------------
T0_INT:
PUSH ACC
MOV TL0,#LO
MOV TH0,#HI
INC DEDA
; 1 SEC TIME OUT CHECK
MOV A,DEDA
CJNE A,#CO,TT1
MOV DEDA, #0
CPL SEC_LED
INC SEC
MOV A,SEC
CJNE A,#60,TT1
; 1 MIN TIME OUT
INC MIN
MOV SEC,#0
MOV A, MIN
CJNE A,#30,TT1
MOV SEC,#0
MOV MIN,#0
TT1:
POP ACC
RETI
;----------------------------------------------------------------------
; 7 SEG HH:MM
; CONVERT ALARM DATA
; BUF0 | BUF1 | BUF2 | BUF3
CONVA:
; SHOW MIN...............
MOV A,MM
MOV B,#10
DIV AB
MOV DPTR, #TABLE
MOVC A,@A+DPTR
MOV BUF,A
MOV A,B
MOVC A,@A+DPTR
MOV BUF+1,A
; SHOW SEC...............
MOV A,SS
MOV B,#10
DIV AB
MOV DPTR, #TABLE
MOVC A,@A+DPTR
MOV BUF+2,A
MOV A,B
MOVC A,@A+DPTR
MOV BUF+3,A
RET
;----------------------------------------------------------------------
; 7 SEG MM:SS
; CONVERT DATA AND SHOW
; BUF0 | BUF1 | BUF2 | BUF3
CONV1:
; SHOW MIN...............
MOV A,MIN
MOV B,#10
DIV AB
MOV DPTR, #TABLE
MOVC A,@A+DPTR
MOV BUF,A
MOV A,B
MOVC A,@A+DPTR
MOV BUF+1,A
; SHOW SEC...............
MOV A,SEC
MOV B,#10
DIV AB
MOV DPTR, #TABLE
MOVC A,@A+DPTR
MOV BUF+2,A
MOV A,B
MOVC A,@A+DPTR
MOV BUF+3,A
RET
;----------------------------------------------------------------------
; SCAN 4 TIMES
SCAN1:
MOV R0, #BUF
MOV R2, #4
MOV ACC, #0FEH
S1:
PUSH ACC
; SEND OUT 1 7 SEGMENT DATA IN @R0
MOV A, @R0
MOV P0,ACC
; SEND SCAN CODE
POP ACC
MOV P2,ACC
MOV R5,#5
CALL DELAY1
; CHANGE SCAN CODE
RL A
INC R0
DJNZ R2, S1
RET
;----------------------------------------------------------------------
SCANS:
MOV R4,#55
SC: CALL SCAN1
DJNZ R4,SC
RET
;----------------------------------------------------------------------
; UPDATE MIN,SEC
TIME_PRO:
CALL CONV1 ; CONV. TO ASCII SHOW TO 7SEG
; CHECK ALARM ON/OFF............
JB ALB,TI1
RET
TI1:
; CHECK ALARM.................
MOV A,MIN
MOV B,MM
CJNE A,B,BK
MOV A,SEC
MOV B,SS
CJNE A,B,BK
; TIME MATCH....................
CLR TO_LED
CALL INIT_TIMER_STOP
PK:
CALL SCAN1
JB K3,PK
BK:
RET
;----------------------------------------------------------------------
BZ:
MOV R6,#0
B1: CALL DE
CPL SPK
DJNZ R6,B1
RET
;----------------------------------------------------------------------
DE: MOV R7,#50
DE1: NOP
DJNZ R7,DE1
RET
;----------------------------------------------------------------------
END |
|