实现的功能如下:
芯片选用69P42,仿真使用IDE66软件中自带的软仿真
上电初始化用户寄存器,进入HALT模式等待外部按键中断唤醒(PORTD为输入端口PORTD.0-3分别接四个按键PORTC为输出口PORTC.0-3分别对应PORTC的四个输入口外接四个指示灯),外部一旦有按键中断其相应PORTC口的外接指示灯会闪亮(采用TIMER0作延时用设置有计时时间标志寄存器),按其他的按键则会关闭当前的输出,执行最后按下键的输出
程序如下:
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
;***************
;程序
;****************
ORG 0000H
JMP REST
ORG 0001H
RTNI
ORG 0002H
JMP TIMER0_ISP
ORG 0003H
RTNI
ORG 0004H
JMP PORT_IST
;中断服务程序
PORT_IST:
STA AC_BACK,00H
ANDIM IRQ,1110B
ORIM IE,0001B
PORT_IST_END:
LDA AC_BACK,00H
RTNI
;****************************
;延时3S TM0中断服务子程序
;****************************
TIMER0_ISP:
STA AC_BACK,00H
ANDIM IRQ,1011B
SBIM T0M_CT,01H
BNZ TIMER0_END
LDI T0M_CT,0FH
ADIM YS_1,01H
SBI YS_1,02H
BNZ TIMER0_END
LDI T0M_CT,0FH
LDI T0M_1,0001B
TIMER0_END:
ORIM 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 YS_1,0FH
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,00H
LDI YS_1,00H
;主程序
MAIN:
LDI PORTA,03H;
LDI PORTB,0CH;
LDI PORTD,0FH;打开上拉电阻使用下降沿中断
NOP
NOP
NOP
LDI IRQ,00H
LDI IE,0001B
HALT
NOP
NOP
CALL KEY_CK;检测按键状态
KEY_CK:
LDA PORTD,00H
STA TEMP,00H
CALL DELAY
LDA PORTD,00H
SUB TEMP,00H
BNZ MAIN
EORIM TEMP,0FH
STA KEY_ST,00H
CALL DISP;输出显示
DISP:
CALL RS_4
LDA KEY_ST,00H
STA PORTC,00H
ADI T0M_1,0001B
BA0 DISP;定时时间没到返回到HALT模式
ANDIM PORTC,00H;关闭输出口
ANDIM T0M_1,1110B;定时时间到了清定时时间到标志位
LDI YS_1,00H
JMP MAIN
DELAY:
LDI CT1,03H
LDI CT0,0EH
SBIM CT0,01H
BC $-1
SBIM CT1,01H
BC $-4
RTNI
RS_4:
ORIM IE,0100B
RTNI
END
现在的问题是按下按键相应的输出只是延时一段时间不是闪亮的,而且必须当前的程序执行完其它的按键才会有效,我想问一下如果实现上面说的那些功能我该如何修改呢? |
|