本帖最后由 mugangzhu 于 2009-12-17 17:15 编辑
呵呵,谢谢啊,还是不能实现亮灭的,我就是不知道为什么不行,查了应该没有问题了啊
LIST P=69P42
ROMSIZE=3072
;*******************************
;系统寄存器
;********************************
IE EQU 00H
IRQ EQU 01H
TM0 EQU 02H
T0L EQU 04H
T0H EQU 05H
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
;***************
;程序
;****************
ORG 0000H
JMP REST
RTNI
JMP TIMER0_ISP
RTNI
RTNI
;****************************
;延时3S TM0中断服务子程序
;****************************
TIMER0_ISP:
STA AC_BACK,00H
ANDIM IRQ,1011B
SBIM T0M_CT,01H
SBI T0M_CT,07H;分析定时时间是否允许打开输出
BAZ RS_4
SBIM T0M_CT,01H
BNZ TIMER0_END
LDI T0M_CT,0FH
LDI T0M_1,0001B;输出状态标志位置1关闭输出
TIMER0_END:
LDI IE,0100B
LDA AC_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 T0,00H;选择外部时钟
LDI T0L,0FH
LDI T0H,0EH
LDI T0M_CT,0FH;
LDI TM0,00H; 2048分频比
LDI T0M_1,01H
LDI PORTD,0FH;使用低电平按键有效
LDI YS_1,0FH
LDI IE,0100B
;主程序
MAIN:
NOP
NOP
LDA PORTD,00H
STA TEMP,00H
CALL DELAY
LDA PORTD,00H
SUB TEMP,00H
BNZ RS_1
SBI TEMP,0FH
BNZ RS_3 ;有新的按键按下
LDA T0M_1,00H
BA0 RS_1
JMP RS_2
DELAY:
LDI CT1,01H
LDI CT0,0FH
SBIM CT0,01H
BC $-1
SBIM CT1,01H
BC $-4
RTNI
RS_1:
ANDIM PORTC,00H;关闭输出口
ANDIM T0M_1,1000B;清输出状态标志
JMP MAIN
RS_2:
LDA YS_1,00H
STA YS_2,00H
EORIM YS_2,0FH
STA PORTC,00H
JMP MAIN
RS_3:
LDA TEMP,00H
STA YS_1,00H
LDA YS_1,00H
STA YS_3,00H
EORIM YS_3,0FH
STA PORTC,00H
JMP MAIN
RS_4:
LDI T0M_1,00H;输出状态标志位置0打开输出
JMP TIMER0_END
END |