📄 second.s
字号:
.equ __30F4011, 1
.include "p30F4011.inc"
.global __reset ;The label for the first line of code.
.global __OscillatorFail ;Declare Oscillator Fail trap routine label
.global __AddressError ;Declare Address Error trap routine label
.global __StackError ;Declare Stack Error trap routine label
.global __MathError ;Declare Math Error trap routine label
.global Flags
.global __T1Interrupt ;Declare Timer 1 ISR name global
.section .nbss
.align 2
Flags: .space 2
.equ Fcy, #7372800
.equiv LED1on, 0
.equiv LED2on, 1
.equiv LED3on, 2
.equiv LED0, 0
.equiv LED1, 1 ;LED1 connected to RE4
.equiv LED2, 2 ;LED2 connected to RE5
.equiv LED3, 3 ;LED2 connected to RE5
.equiv LED4, 4
.equiv LED5, 5
;Start of code
.text ;Start of Code section
__reset: mov #__SP_init,w15 ;Initalize the Stack Pointer
mov #__SPLIM_init,w0
mov w0,SPLIM ;Initialize the Stack Pointer Limit Register
nop ;Add NOP to follow SPLIM initialization
clr W0 ;Initialize Working registers to 0x0000
mov W0,W14 ;clr working registers w0 to w14
repeat #12
mov W0,[++W14]
clr W14
;main code
clr Flags ;clear all Flags
RCALL Init_PORTS ; Initialize the I/O ports
RCALL Init_TMR1 ;initialize TMR1 for 0.5 sec interrupt
Again:
nop
nop
bra Again ;repeat again
;------------------------------------------------------------------------------
Init_PORTS:
clr LATE
mov #0x0,W0 ; set RD7 to RD4 as outputs
mov W0,TRISE
return
;------------------------------------------------------------------------------
Init_TMR1:
CLR T1CON ; Stops the Timer1 and reset control reg.
CLR TMR1 ; Clear contents of the timer register
MOV #0x1FFF, w0 ; Load the Period register
MOV w0, PR1 ; with the value 0xFFFF
BSET IPC0, #T1IP0 ; Setup Timer1 interrupt for
BCLR IPC0, #T1IP1 ; desired priority level
BCLR IPC0, #T1IP2 ; (this example assigns level 1 priority)
BCLR IFS0, #T1IF ; Clear the Timer1 interrupt status flag
mov #0x8020,W0 ; Fosc/4, 1:8 prescale, start TMR1
mov W0,T1CON
BSET IEC0, #T1IE ; Enable Timer1 interrupts
return
;-----------------------------------------------------------------------------
__T1Interrupt:
bclr IFS0, #T1IF ;clr interrupt flag
; btsc Flags,#LED1on ; LED1 flags set?
; bra ToggleLED1 ;yes then toggle LED1
; bclr PORTE,#LED1 ;no then turn off LED1
; retfie
; bra next
;ToggleLED1:
nop
btg PORTE,#LED0
nop
btg PORTE,#LED1
nop ;yes then toggle LED1
btg PORTE,#LED2
nop
btg PORTE,#LED3
nop
btg PORTE,#LED4
nop
btg PORTE,#LED5
nop
;next: btsc Flags,#LED3on ; LED1 flags set?
; bra ToggleLED3 ;yes then toggle LED1
; bclr PORTE,#LED3 ;no then turn off LED1
; bra NextLED
;ToggleLED3:
; btg PORTE,#LED3 ;yes then toggle LED1
;NextLED:
; btsc Flags,#LED2on ; LED1 flags set?
; bra ToggleLED2 ;yes then toggle LED1
; bclr PORTE,#LED2 ;no then turn off LED1
; nop
; retfie
;ToggleLED2:
; btg PORTE,#LED2 ;yes then toggle LED1
; nop
retfie
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -