ORG 0000H
JMP REST
RTNI
JMP TIMER_IS0
RTNI
RTNI
;************************
;TM0中断子程序
;************************
TIMER_IS0:
STA AC_BACK,00H
ANDIM IRQ,1011B
SBIM DELAY,01H
BNZ TIMER_IS0_END
ORIM FLAG,0001B; .0=1计时1ms到
LDI DELAY,04H
;计时1ms到
ADIM DELAY1,01H
SBI DELAY1,05H
BNZ TIMER_IS0_END
LDI DELAY1,00H
ORIM FLAG,0010B;FLAG位1=1 5ms定时到
;定时5ms时间到
ADIM DELAY6,01H
SBI DELAY6,02H
BNZ TIMER_IS0_END
LDI DELAY6,00H
ORIM FLAG,0100B; .2=1计时10ms到
;定时10ms到
ADIM DELAY2,01H
SBI DELAY2,0AH
BNZ TIMER_IS0_END
LDI DELAY2,00
ORIM FLAG,1000B; .3=1定时100ms到
;定时100ms到
ADIM DELAY3,01H
SBI DELAY3,0AH
BNZ TIMER_IS0_END
LDI DELAY3,00H
ORIM FLAG1,0001B;FLAG1.0=1定时1s到
;定时1s到
ADIM DELAY4,01H
SBI DELAY4,0AH
BNZ TIMER_IS0_END
LDI DELAY4,00H
;定时10s到
ADIM DELAY5,01H
SBI DELAY5,06H
BNZ TIMER_IS0_END
LDI DELAY5,00H
;定时时间1min到
ORIM FLAG1,0010B;FLAG1.1=1定时1min到
TIMER_IS0_END:
LDI IE,0100B
LDA AC_BACK,00H
RTNI
;上电初始化用户寄存器
REST:
LDI DPL,00H
LDI DPM,03H
LDI DPH,00H
POWER_1:
LDI INX,00H
ADIM DPL,01H
LDI TEMP,00H
ADCM DPM,00H
BA3 POWER_2
JMP POWER_3
POWER_2:
ADIM DPH,01H
POWER_3:
SBI DPH,01H
BNZ POWER_1
SBI DPM,04H
BNZ POWER_1
;;;;;;;;;;;;;;;;;;初始化系统寄存器
LDI PA,0011B
LDI PACR,0FH
LDI PD,00H
LDI PDCR,0FH
LDI PE,00H
LDI PECR,0FH
;初始化TM0\TM1
LDI T0L,06H
LDI T0H,00H
LDI TM0,07H;中断周期为250us
;初始化用户自定义寄存器
LDI DELAY,04H;用于TM0定时1ms用
LDI DAOJ1,03H
LDI DAOJ2,00H
LDI IRQ,00H
LDI IE,0100B
;PD口用于数据传输、164传输时钟和数码管的位选,PE口用于外接按键,PC.2设置为PWM0驱动蜂鸣器,
;PC.0设置为时钟输出脚,PC.1用于ADC转换输入
;主程序
MAIN:
LDA FLAG,00H
BA0 CLOCK;传送和显示数据子程序 1ms
BA1 KEY;按键扫描子程序 5ms扫描一次
BA2 WEIXUAN;数码管1和2之间的切换子程序 10ms切换一次
BA3 SPEAK;蜂鸣器鸣叫报警
LDA FLAG1,00H
BA0 WENDU;温度读取1s读取一次
BA1 MIN1;1min到时钟显示数据处理
HALTMODE:
NOP
NOP
HALT
NOP
NOP
JMP MAIN
;1s读取一次温度
WENDU:
ANDIM FLAG1,1110B;清1s时间标志
JMP MAIN
;蜂鸣器鸣叫报警子程序
SPEAK:
ANDIM FLAG,0111B;清100ms时间标志
JMP MAIN
;按键扫描子程序
KEY:
ANDIM FLAG,1101B;清5ms时间标志
JMP MAIN
; 数码管1和2之间的切换子程序
WEIXUAN:
ANDIM FLAG,1011B;清定时10ms到
EORIM FLAG2,0010B
BA1 WEIXUAN1
ANDIM PD,1011B
ORIM PD,1000B;PD.3位选2
LDI TBR,0FH
LDA DAOJ1,00H
CALL 03FFH
STA DATA1,00H
LDA TBR,00H
STA DATA0,00H
JMP MAIN
WEIXUAN1:
ANDIM PD,0111B;关闭位选2打开位选1 PD.2位选1
ORIM PD,0100B
LDI TBR,0FH
LDA DAOJ2,00H
CALL 03FFH
STA DATA1,00H
LDA TBR,00H
STA DATA0,00H
JMP MAIN
;时钟显示出自子程序
MIN1:
ANDIM FLAG1,1101B;清定时1min到标志
SBIM DAOJ2,01H
OR DAOJ1,00H
BAZ CLOSE
DAS DAOJ2
LDI TEMP,00H
SBCM DAOJ1,00H
DAS DAOJ1
JMP MAIN
CLOSE:
ANDIM PD,0011B
JMP MAIN
;传送和显示数据子程序
;PD.0 clock时钟脚,PD.1数据输出脚,PD.2=1位选1,PD.3=1位选2 ,先传DATA1中的数据再传DATA0中数据
CLOCK:
ANDIM FLAG,1110B;清定时1ms标志位
LDI TEMP3,08H
CLOCK_2:
LDA DATA0,00H
SHR
STA DATA0,00H
LDI TEMP4,00H
ADCM TEMP4,00H
;左移传到最高位
ZUOYI:
LDA TEMP4,00H
ADDM TEMP4,00H
ADIM TEMP1,01H
SBI TEMP1,03H;运行第6次时在此处产生了一个中断到JMP TIMER_IS0很是纳闷??????????????????????
BNZ ZUOYI
LDI TEMP1,00H
LDA DATA1,00H
SHR
STA DATA1,00H
LDI TEMP2,00H
ADCM TEMP2,00H
LDA TEMP,00H
ADDM DATA1,00H
LDA TEMP2,00H
BA0 CLOCK_1
CLOCK_0:
ANDIM PD_BACK,1101B;赋值0
JMP $+2
CLOCK_1:
ORIM PD_BACK,0010B;赋值1
STA PD,00H;PD.1传送数据
NOP
NOP
NOP
ORIM PD_BACK,0001B;PD.0输出高电平传送数据
STA PD,00H
NOP
NOP
ANDIM PD_BACK,1110B;PD.0输出低电平等待下次传送
STA PD,00H
SBIM TEMP3,01H
BNZ CLOCK_2
JMP MAIN |
|