搜档网
当前位置:搜档网 › 十速TM57PE12外部中断唤醒应用范例

十速TM57PE12外部中断唤醒应用范例

;-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*
;-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*
#include<TM57PE12.inc>
;-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*
;-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*
; *********************** Program Start ********************************
;Config:
;nPROTECT(bit13-----'0'): Code protection
;nREUSE (bit12-----'1'): Not Re-use
;LVR (bit11:10----'10'): LVR threshold is 1.5V, disable in sleep mode
;CLKS (bit9:8----'11'): Fast Crystal (455KHz~24MHz)
;XRESETE (bit7-----'0'): Disable External pin Reset to use as input pin
;WDTE (bit6-----'0'): Disable WDT Reset
;IRC MHz (bit5-----'0'): IRCCLK=4MHz
;IRCF (bit4:0--'0000'): Internal RC Frequency adjustment control
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;nPROTECT: Code protection selection(0)
;--------> 1 No protect
;--------> 0 Code protection
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;nREUSE : PROM Re-use control(1)
;--------> 1 Not Re-use
;--------> 0 Re-use
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;LVR : LV reset mode(10)
;--------> 11 LVR threshold is 1.5V, always enable
;--------> 10 LVR threshold is 1.5V, disable in sleep mode
;--------> 01 LVR threshold is 2.4V, always enable
;--------> 00 LVR disable
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;CLKS : Clock Source Selection(11)
;--------> 11 Fast Crystal (455KHz~24MHz)
;--------> 10 Slow Crystal (32KHz)
;--------> 01 Internal High RC (8MHz/4MHz)
;--------> 00 External RC
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;XRESETE : External pin Reset Enable(0)
;--------> 1 Enable External pin Reset
;--------> 0 Disable External pin Reset to use as input pin
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;WDTE : WDT Reset Enable(0)
;--------> 1 Enable WDT Reset
;--------> 0 Disable WDT Reset
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;IRC MHz : 8/4MHz(0)
;--------> 1 IRCCLK=8MHz
;--------> 0 IRCCLK=4MHz
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;IRCF : Internal RC Frequency adjustment control(0)
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;-----------------------------------------------------------------------
;Note:
;Name TM57PE12_WAKEUP_TM2.asm
;Date 2010/04/30
;by pflee
;-----------------------------------------------------------------------
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;-----------------------------------------------------------------------
;%

%%%%%%%%%%%%%%%%%%%%%%%%%%% 常数定义 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;-----------------------------------------------------------------------
;!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;-----------------------------------------------------------------------
;-----------------------------------------------------------------------
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;-----------------------------------------------------------------------
;%%%%%%%%%%%%%%%%%%%%%%%%%%%% 寄存器定义 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;-----------------------------------------------------------------------
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;-----------------------------------------------------------------------
temp equ 4fh
accbuf equ 4eh
stabuf equ 4dh
tm0ctrlbuf equ 4ch
int0wktbuf equ 4bh
pwm0ctrlbuf equ 4ah
tm2subtypbuf equ 49h
;-----------------------------------------------------------------------
flag equ 20h
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kyh equ 0 ;有效按键按下标志
fsh equ 1 ;亮灭切换标志
f1 equ 4 ;k1按下标志
f2 equ 5 ;k2按下标志
f3 equ 6 ;k3按下标志
;-----------------------------------------------------------------------
keybuf equ 21h
keycnt equ 22h
;-----------------------------------------------------------------------
nmsr equ 23h
fshcnt equ 24h
;=======================================================================
;每个XX毫秒执行完一次操作即进入Idle状态
;按下k1,led1闪亮10秒钟后熄灭
;按下k2,led2闪亮10秒钟后熄灭
;按下k3,led3闪亮10秒钟后熄灭
;led1--------->pad,5
;led2--------->pad,6
;led3--------->pbd,0
;k1----------->pbd,1
;k2----------->pbd,2
;k3----------->pbd,3
;=======================================================================
org 000h
goto main_reset
org 001h
goto interrupt
org 002h
;=======================================================================
interrupt
movwf accbuf
movfw status
movwf stabuf
;-------------------------------------------------------
btfsc intf,tm2i
goto int_tm2
;-----------------------------------------------------------------------
int_exit
movfw stabuf
movwf status
movfw accbuf
reti
;-----------------------------------------------------------------------
int_tm2
movlw b'10111111'
movwf intf ;清除Time2中断标志
goto int_exit
;=======================================================================
main_reset
movlw b'01111111' ;pa0~pa6 output
movwr pae
movlw b'01111111' ;pa0~pa6 Pull up Disable
movwr papu
movlw b'00000000' ;pa1~pa6 wake up Disable
movwr pawkup
movlw b'00000000'
movwf pad
;-------------------------------------------------------
mo

vlw b'00000001' ;pb0 output, pb1~pb3 input
movwr pbe
movlw b'00000001' ;pb0 Pull up Disable,pb1~pb3 Pull up Enable
movwr pbpu
movlw b'00000000' ;pb1~pb3 wake up disable
movwr pbwkup
movlw b'00001110'

movwf pbd
;-------------------------------------------------------
movlw 20h
movwf temp
;-------------------------------------------------------
movfw temp
movwf fsr
movlw 00h
movwf indf
incf temp,f
movlw 4fh
subwf temp,w
btfss status,c
goto $-8
clrf temp ;清零20h~4fh
;=======================================================================
main_loop
movfw tm2subtypbuf ;系统子时钟类型设置
andlw subtypR
iorlw b'00000001' ;bit1~bit0--> sub-clk type 0:SXT , 1: ILRC , 2: XRC
movwf tm2subtypbuf
movwr tm2subtyp
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
movfw int0wktbuf ;系统子时钟频率设置
andlw wktpscR ;bit1~bit0,00->15mS,01->30mS,10->60mS,11->120mS
iorlw b'00000000' ;sub-clk T=30ms
movwf int0wktbuf
movwr int0wkt
;-------------------------------------------------------
movlw b'10111111'
movwf intf ;清除Time2中断标志
;-------------------------------------------------------
movlw b'01000000' ;Time2 interrupt enable
movwf inte
;-------------------------------------------------------
movfw tm2subtypbuf ;Timer2寄存器设置
andlw tm2clkR ;bit4------->Timer2 Clock Source 0:SLOW Clock; 1:CPUCLK/128
andlw tm2divR ;bit3~bit2-->Timer2 interrupt is timer2 clock divide by –
iorlw b'00001000' ;bit3~bit2--> 0: 32768, 1: 16384 , 2: 8192 ,3 :127
movwf tm2subtypbuf
movwr tm2subtyp
bsf ctrlsys,clrtm2 ;Write 1 to clear Time2 timer
;-------------------------------------------------------
movlw b'00011000' ;系统用到外部振荡源时
iorwf pad,f ;外部振荡源相对应的IO(PA3,PA4)必须设为input状态
movlw b'01100111' ;并且对应IO必须开启上拉,否则系统进入SLEEP后会影响静态电流
movwr pae
movlw b'01100111'
movwr papu
movlw b'00000000'
movwr pawkup
;-------------------------------------------------------
movlw b'00001110'
iorwf pbd,f
movlw b'00000001' ;pb0 output, pb1~pb3 input
movwr pbe
movlw b'00000001' ;pb0 Pull up Disable,pb1~pb3 Pull up Enable
movwr pbpu
movlw b'00000000' ;pb1~pb3 wake up disable
movwr pbwkup
;-------------------------------------------------------
bsf ctrlsys,sube
sleep ;进入休眠后Time2计数溢出唤醒(每52ms唤醒一次)
nop
nop
nop
;-------------------------------------------------------
incf nmsr,f
movlw .10
subwf nmsr,w
btfss status,c
goto main_scan
clrf nmsr
;-------------------------------------------------------
movlw 02h
xorwf flag,f
;-------------------------------------------------------
flash_st
btfs

c flag,f1
goto flash_led1
;-------------------------------------------------------
btfsc flag,f2
goto flash_led2
;-------------------------------------------------------
btfsc flag,f3
goto flash_led3
;-----------------------------------------------
--------
goto main_scan
;-------------------------------------------------------
flash_led1
bcf pad,6
bcf pbd,0
btfss flag,fsh
bsf pad,5
btfsc flag,fsh
bcf pad,5
goto flash_com
;-------------------------------------------------------
flash_led2
bcf pad,5
bcf pbd,0
btfss flag,fsh
bsf pad,6
btfsc flag,fsh
bcf pad,6
goto flash_com
;-------------------------------------------------------
flash_led3
bcf pad,5
bcf pad,6
btfss flag,fsh
bsf pbd,0
btfsc flag,fsh
bcf pbd,0
;-------------------------------------------------------
flash_com
incf fshcnt,f
movlw .20
subwf fshcnt,w
btfss status,c
goto main_scan
clrf fshcnt
;-------------------------------------------------------
bcf flag,f1
bcf flag,f2
bcf flag,f3
bcf pad,5
bcf pad,6
bcf pbd,0
;-------------------------------------------------------
main_scan
comf pbd,w
andlw b'00001110'
movwf temp
;-------------------------------------------------------
xorwf keybuf,w
btfss status,z
clrf keycnt
;-------------------------------------------------------
movfw temp
movwf keybuf
;-------------------------------------------------------
incf keycnt,f
movlw .5
subwf keycnt,w
btfss status,c
goto main_loop
clrf keycnt
;-------------------------------------------------------
movlw 08h
xorwf keybuf,w
btfsc status,z
goto get_k3
;-------------------------------------------------------
movlw 04h
xorwf keybuf,w
btfsc status,z
goto get_k2
;-------------------------------------------------------
movlw 02h
xorwf keybuf,w
btfsc status,z
goto get_k1
;-------------------------------------------------------
bcf flag,kyh
goto main_loop
;-------------------------------------------------------
get_k1
btfsc flag,kyh
goto main_loop
bsf flag,kyh
;-------------------------------------------------------
bsf flag,f1
bcf flag,f2
bcf flag,f3
goto scan_end
;-------------------------------------------------------
get_k2
btfsc flag,kyh
goto main_loop
bsf flag,kyh
;-------------------------------------------------------
bcf flag,f1
bsf flag,f2
bcf flag,f3
goto scan_end
;-------------------------------------------------------
get_k3
btfsc flag,kyh
goto main_loop
bsf flag,kyh
;-------------------------------------------------------
bcf flag,f1
bcf flag,f2
bsf flag,f3
;-------------------------------------------------------
scan_end
bcf flag,fsh
clrf nmsr
clrf fshcnt
goto flash_st
;=======================================================================
end


相关主题