,, ;-----------------------------------------------------
;S3F9454,FOSC=8MHZ
.INCLUDE "S3C9454.REG"
;-----------------------------------------------------
;以下为程序运行所用变量定义
RUNFLAG EQU 00H
KEY_TIME EQU 01H
TMR_1S EQU 02H
TMR_1M EQU 03H
TMR_10M EQU 04H
KEY_CODE1 EQU 05H
KEY_CODE2 EQU 06H
KEY_CODE EQU 07H
TMR_SET EQU 0AH
TMR_CNT EQU 0BH
;-----------------------------------------------------
;各输入输出I/O口功能定义:
;JDQ_H1 BIT P0.0
;JDQ_H3 BIT P0.1
;JDQ_H5 BIT P0.2
;KEY_H1 BIT P0.3
;KEY_H3 BIT P0.4
;KEY_H5 BIT P0.5
;KEY_RESET BIT P0.6
;------------------------
;按键码定义
H1_KEY .EQU 08H
H3_KEY .EQU 10H
H5_KEY .EQU 20H
RESET_KEY .EQU 40H
;--------------------------------------------------------
;-------<<INTERRUPT VECTOR ADDRESS>>
ORG 0000H ;S3C9454 HAS ONLY ONE INTERRUPT VECTOR
.VECTOR 0000H,INT_9454
;------------------------------------------------------------
;-----------------------------------------------------------
;SMART OPTION
ORG 003CH
DB 00H
DB 00H
DB 0E7H
DB 0H
;-----------------------------------------------------------
;-------<<INITIALIZE SYSTEM AND PERIPHERAL>>
ORG 0100H
RESET: ;-------------------------
;FOLLOW MUST SET
DI ;DISABLE INTERRUPT
LD BTCON,#10100011B ;WATCH-DOG DISABLE
LD CLKCON,#00011000B ;SELET NON-DIVIDED CPU CLOCK
LD SP,#0C0H ;STACK POINTER MUST BE SET AS 0C0H
CLR P0PND
LD P0CONH,#00000000B
LD P0CONL,#01101010B
;START INITIATED ALL RAM
LD T0CON,#01001010B ;FX=8MHZ,32US
LD T0DATA,#125 ;4MS INT
;---------------------------------------
CLR KEY_CODE1
CLR KEY_CODE2
CLR KEY_TIME
CLR KEY_CODE
CLR TMR_1S
CLR TMR_1M
CLR TMR_10M
CLR TMR_CNT
;------------------------
MAIN_START:
;未开机,清定时器
CLR TMR_1S
CLR TMR_1M
CLR TMR_10M
CLR TMR_CNT
CALL DELAY_1MS
CALL KEY_CHECK
CP KEY_CODE,#H1_KEY
JR EQ,SET_TMR_1H
CP KEY_CODE,#H3_KEYy
JR EQ,SET_TMR_3H
CP KEY_CODE,#H5_KEY
JR EQ,SET_TMR_5H
JR MAIN_START
SET_TMR_1H:
LD TMR_SET,#1 ;10分钟为单位 6*10=60分
OR P0, #01H ;SET BIT JDQ_H1=>P0.0
JR ON_LOOP
SET_TMR_3H:
LD TMR_SET,#2 ;10分钟为单位 18*10=180分
OR P0, #02H ;SET BIT JDQ_H3=>P0.1
JR ON_LOOP
SET_TMR_5H:
LD TMR_SET,#3 ;10分钟为单位,30*10=300分钟,5小时
OR P0, #04H ;SET BIT JDQ_H5=>P0.2
JR ON_LOOP
;-------------------
;开机循环过程
ON_LOOP:
EI
CALL DELAY_1MS;长调用
CALL KEY_CHECK
CP KEY_CODE,#RESET_KEY
JR EQ,TURN_OFF ;复位键有按下,则复位定时器,关机回到待机循环
CHK_TMR:
;检查定时运行过程
CP TMR_10M,#10
JR ULT,ON_LOOP
CLR TMR_10M
INC TMR_CNT ;每10分钟增量一次计时器
CP TMR_CNT,TMR_SET
JR ULT,ON_LOOP
;定时时间已到,关闭全部继电器,返回到待机循环
TURN_OFF:
AND P0, #0feH ;CLR BIT JDQ_H1=>P0.0
AND P0, #0fdH ;CLR BIT JDQ_H3=>P0.1
AND P0, #0fbH ;CLR BIT JDQ_H5=>P0.2
JR MAIN_START
;---------------------------------------
KEY_CHECK:
LD KEY_CODE1,P0
COM KEY_CODE1
AND KEY_CODE1,#01111000B
CP KEY_CODE1,KEY_CODE2
JR EQ,INC_TIME
LD KEY_CODE2,KEY_CODE1
CLR KEY_TIME
CLR KEY_CODE
JR KEY_BACK
INC_TIME:
INC KEY_TIME
CP KEY_TIME,#20
JR ULT,KEY_BACK
;若连续20次检测键码均相同,则确认本次按键有效
LD KEY_CODE,KEY_CODE1
KEY_BACK:
RET
;---------------------------------------
;TMR0,4MS INT
INT_9454:
TM T0CON,#01H
JR Z,INT_BACK
AND T0CON,#0FEH
;检查计时1S
INC TMR_1S;加一
CP TMR_1S,#250;比较
JR ULT,INT_BACK
CLR TMR_1S;寄存器清零
;检查计时1分钟
INC TMR_1M
CP TMR_1M,#60
JR ULT,INT_BACK
CLR TMR_1M
;增量10分钟累加器
INC TMR_10M
INT_BACK:
IRET
;---------------------------------------
DELAY_1MS:
PUSH R15
LD R15,#99
_1MS:
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DEC R15
JR NZ,_1MS
POP R15
RET
;-----------------------------------------
.END;程序结束
|
|