免电源的电话使用计时器
FZ == 02 ;FLAG OF ZERO
FC == 00 ;FLAG OF CARRY
P5 == 0X05 ;PORT 5
P6 == 0X06 ;PORT 6
MIN == 0X10 ;MINUTE
SEC == 0X11 ;SECOND
DD == 0X12 ;DISPLAY DIGIT
DDH == 0X13 ;DISPLAY DIGIT HIGH
AB == 0X14 ;A BACK_UP
RFB == 0X15 ;RF BACK_UP
ORG 0
0000 JMP INIT ;PROGRAM START
ORG 8
;TCC INTERRUPT-------------------------------------------------------------
TCCI:
0008 MOV AB,A ;AB <- A
0009 SWAP AB ;AB <- BA
000A SWAPA RF
000B MOV RFB,A ;RFB<- FR
000C INC SEC
CHECK:
000D MOV A,SEC
000E SUB A,@59 ;59-SEC=A
000F JBC RF,FC
0010 JMP C_MIN
0011 CLR SEC
0012 INC MIN
C_MIN:
0013 MOV A,MIN
0014 SUB A,@99 ;99-MIN=A
0015 JBS RF,FC
0016 CLR MIN
TCCE:
0017 SWAPA RFB
0018 MOV RF,A ;RF<- RFB
0019 SWAPA AB ;A <- BA
001A BC 0X0F,0 ;CLEAR TCC_INT
001B RETI
;TABLE 7 SEGEMENT-----------------------------------------------------
T7:
001C ADD PC,A ; GFE DCBA
001D RETL @0B01000000 ;0 0100 0000
001E RETL @0B01111001 ;1 0111 1001
001F RETL @0B00100100 ;2 0010 0100
0020 RETL @0B00110000 ;3 0011 0000
0021 RETL @0B00011001 ;4 0001 1001
0022 RETL @0B00010010 ;5 0001 0010
0023 RETL @0B00000010 ;6 0000 0010
0024 RETL @0B01011000 ;7 0101 1000
0025 RETL @0B00000000 ;8 0000 0000
0026 RETL @0B00010000 ;9 0001 0000
;INIT ---------------------------------------------------------------------------
INIT:
0027 MOV A,@0X00
0028 MOV MIN,A
0029 MOV SEC,A
002A IOW 0X0E ;DISABLE WDT
002B IOW P5 ;PORT 5 OUTPUT
002C IOW P6 ;PORT 6 OUTPUT
002D MOV A,@0X01
002E IOW 0X0F ;ENABLE TCC_INT
002F MOV A,@0X05 ;1/64
0030 CONTW
0031 ENI
;SCAN -------------------------------------------------------------------------
SCAN:
0032 MOV A,MIN
HTD:
0033 CLR DDH
H_H:
0034 ADD A,@246 ;A=A-10
0035 JBS RF,FC
0036 JMP H_L
0037 INC DDH
0038 JMP H_H
H_L:
0039 ADD A,@10
003A CALL T7
003B IOW P6
003C MOV P6,A
003D MOV A,@255 ;DISPLAY DIGIT 0
003E MOV P5,A
003F MOV A,DDH
0040 CALL T7
0041 IOW P6
0042 XOR A,@0XFF
0043 MOV P6,A
0044 MOV A,@00 ;DISPLAY DIGIT 1
0045 MOV P5,A
0046 JMP SCAN
原来问题就在中断子程序的A及R3暂存及复原这部份。
原来程序在A及R3的暂存部份:
0008 MOV AB, A ;AB←A
0009 MOV A, RF ;A←RF
000A MOV RFB, A ;RFB←RF
错就错在0009时MOV A, RF指令会破坏ZERO FLAG的资料。故改变指令的用法即可恢复正常,新的程序在A及R3的暂存部份:
0008 MOV AB, A ;AB←A
0009 SWAP AB
000A SWAPA RF
000B MOV RFB, A ;RFB←FR
新的程序在A及R3的复原部份:
0017 SWAPA RFB
0018 MOV RF, A ;RF←RFB
0019 SWAPA AB ;A←BA
动作有点别扭,但是好用得很,请尽量用。
效果观察:
此时此刻的您一定是欢喜异常,眼睛看着分钟一分一分的增加又不死机,刚才紧绷的心情顿时得到解脱,一切的心血总算有了回报了。
增加花招:
拿着半成品把玩半天总觉得有些不够完美的,原来是一分钟才变化一次会让人觉得成品好像没在正常工作,总是怀疑成品是死的,好吧,再动些手脚将秒的闪烁呈现在七段的小数点上以满足动感要求。
TC5.ICE
;
; FILE NAME:TC5.DT
; DATE :1999,5,5
; BY :HWANG JYN_GUO
;
; FUNCTION DESCRIPTION:
; USING TCC TO GET 1 SEC INTERRUPT
; 32768/(2*64*256)= 1 SEC
; CRYSTAL MODE 32768 Hz
; 2 CYCLE AND 2 CLOCK MODE
;
PC == 02
RF == 03 ;STATUS
FZ == 02 ;FLAG OF ZERO
FC == 00 ;FLAG OF CARRY
P5 == 0X05 ;PORT 5
P6 == 0X06 ;PORT 6
DL == 0X10 ;DELAY LOOP
MIN == 0X11 ;MINUTE
SEC == 0X12 ;SECOND
DD == 0X13 ;DISPLAY DIGIT
DDH == 0X14 ;DISPLAY DIGIT HIGH
AB == 0X15 ;A BACK_UP
RFB == 0X16 ;RF BACK_UP
FG == 0X17 ;FLAG
ORG 0
0000 JMP INIT ;PROGRAM START
ORG 8
;TCC INTERRUPT---------------------------------------------------------------
TCCI:
0008 MOV AB,A ;AB <- A
0009 SWAP AB ;AB <- BA
000A SWAPA RF
000B MOV RFB,A ;RFB<- FR
000C COM FG
000D INC SEC
CHECK:
000E MOV A,SEC
000F SUB A,@59 ;59-SEC=A
0010 JBC RF,FC
0011 JMP C_MIN
0012 CLR SEC
0013 INC MIN
C_MIN:
0014 MOV A,MIN
0015 SUB A,@99 ;99-MIN=A
0016 JBS RF,FC
0017 CLR MIN
TCCE:
0018 SWAPA RFB
0019 MOV RF,A ;RF<- RFB
001A SWAPA AB ;A <- BA
001B BC 0X0F,0 ;CLEAR TCC_INT
001C RETI
;TABLE 7 SEGEMENT------------------------------------------------------
T7:
001D CALL TABLE ;用来增加小数点闪烁
001E JBC FG,00
001F XOR A,@0X80
0020 RET
;TABLE -------------------------------------------------------------------------
TABLE:
0021 ADD PC,A ; GFE DCBA
0022 RETL @0B01000000 ;0 0100 0000
0023 RETL @0B01111001 ;1 0111 1001
0024 RETL @0B00100100 ;2 0010 0100
0025 RETL @0B00110000 ;3 0011 0000
0026 RETL @0B00011001 ;4 0001 1001
0027 RETL @0B00010010 ;5 0001 0010
0028 RETL @0B00000010 ;6 0000 0010
0029 RETL @0B01011000 ;7 0101 1000
002A RETL @0B00000000 ;8 0000 0000
002B RETL @0B00010000 ;9 0001 0000
;INIT -----------------------------------------------------------------------------
INIT:
002C MOV A,@0X00
002D MOV MIN,A
002E MOV SEC,A
002F IOW 0X0E ;
Tags:
作者:佚名评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论