本帖最后由 mugangzhu 于 2009-12-23 13:25 编辑
LIST P=69P42
ROMSIZE=3072
;*******************************
;系统寄存器
;********************************
IE EQU 00H
IRQ EQU 01H
TM0 EQU 02H
TM1 EQU 03H
T0L EQU 04H
T0H EQU 05H
T1L EQU 06H
T1H EQU 07H
PORTA EQU 08H
PORTB EQU 09H
PORTC EQU 0AH;输出口
PORTD EQU 0BH;输入口
TBR EQU 0EH
INX EQU 0FH
DPL EQU 10H
DPM EQU 11H
DPH EQU 12H
PDCR EQU 1BH
PCCR EQU 1AH
T0 EQU 1EH
WDT EQU 1FH
;**************
;用户定义寄存器
;**************
AC_BACK EQU 30H
TEMP EQU 31H
CT1 EQU 32H;
CT0 EQU 33H;延时用寄存器
KEY_ST EQU 34H;键状态
T0M_CT EQU 35H;计时用3s
T0M_CT_1 EQU 36H
T0M_CT_2 EQU 37H
T0M_1 EQU 38H;bit0=1关闭输出=0开启输出
YS_1 EQU 39H
YS_2 EQU 3AH
YS_3 EQU 3BH
TEMP5 EQU 3CH
FLAGE5 EQU 3DH
KEY_OLD EQU 3EH
DELAY1 EQU 3FH;TIMER1延时用
T5MS_CT1 EQU 40H
T5MS_CT2 EQU 41H
TMP_T0 EQU 42H
F_TIMER EQU 43H;位0=1 TIMER0延时5ms时间到,位1=1 TIMER1延时时间到
AC1_BACK EQU 44H
;***************
;程序
;****************
ORG 0000H
JMP REST
RTNI
JMP TIMER0_ISP
JMP TIMER1_ISP
RTNI
;****************************
;延时5mS TM0中断服务子程序
;****************************
TIMER0_ISP:
STA AC_BACK,00H
ANDIM IRQ,1011B
SBIM T5MS_CT1,01H
LDI TMP_T0,00H
SBCM T5MS_CT2,00H
OR T5MS_CT1,00H
BNZ TIMER0_END ;没到5ms, 跳转
ORIM F_TIMER,0001B ;设置“5ms 到”标志
LDI T5MS_CT2,01H ;重置5ms 计数器
LDI T5MS_CT1,04H
TIMER0_END:
ORIM IE,0100B
LDA AC_BACK,00H
RTNI
;****************************
;延时3S TM1中断服务子程序
;****************************
TIMER1_ISP:
STA AC1_BACK,00H
ANDIM IRQ,1101B
ADIM DELAY1,01H
SBI DELAY1,06H
BNZ TIMER1_END
ORIM F_TIMER,0010B
TIMER1_END:
ORIM IE,0010B
LDA AC1_BACK,00H
RTNI
;****************
;上电初始化
;*****************
REST:
NOP
NOP
LDI DPL,00H
LDI DPM,03H
LDI DPH,00H
POWER_RESET_1:
LDI INX,00H
ADIM DPL,01H
LDI TEMP,00H
ADCM DPM,00H
BA3 POWER_RESET_2
JMP POWER_RESET_3
POWER_RESET_2:
ADIM DPH,01H
POWER_RESET_3:
SBI DPH,01H
BNZ POWER_RESET_1
SBI DPM,04H
BNZ POWER_RESET_1
CALL XTJCQ_IST ;初始化系统寄存器
XTJCQ_IST:
LDI PORTD,00H
LDI PDCR,00H;输入口
LDI PORTC,00H
LDI PCCR,0FH;输出口
LDI PORTD,0FH;使用低电平按键有效
LDI T0,00H;选择外部时钟
LDI T0L,06H;timer0设置
LDI T0H,00H
LDI TM0,07H; 1分频比
LDI T1L,00H;timer1设置
LDI T1H,00H
LDI TM1,00H;2048分频
LDI T5MS_CT2,01H
LDI T5MS_CT1,04H;延时5ms
ORIM IE,0110B ;打开timer0、timer1中断
;主程序
MAIN:
ADI F_TIMER,0001B
BA0 HALTMODE ;未到5ms, 跳转
ANDIM F_TIMER,1110B ;清"5ms 到"标志
NOP
LDA PORTD,00H
STA TEMP,00H
SBI TEMP,0FH;=0,没有按键动作跳走
BAZ YS_4
ADIM TEMP5,01H
SBI TEMP5,01H;是否是第一次按键按下是的话存起来初次按键值
BAZ YS_5
LDA KEY_OLD,00H
SUB TEMP,00H
BNZ YS_4
SBI TEMP5,05H;扫描8次按键未完成继续扫描
BNZ MAIN
LDA KEY_OLD,00H
STA PORTC,00H
JMP MAIN
HALTMODE:
NOP
HALT
NOP
NOP
JMP MAIN
YS_4:
ANDIM F_TIMER,1110B
LDI TEMP5,00H
JMP MAIN
YS_5:
LDA TEMP,00H
STA KEY_OLD,00H
RTNI
END |