📄 lab6.asm
字号:
#INCLUDE p16F877A.inc ; Include the standard definitions
#INCLUDE 701PIC.inc ; Include MACROs from MASTER’s 03, PIC 102 class
#DEFINE DEVICE_FREQ_HZ D'4000000' ; Needed by Piezo series macros
LEDCtr EQU 0x30 ; Counter for LED timing
PiezoCtr EQU 0x31 ; Counter for Piezo timing
ORG H'00' ; Reset Vector
Start
goto Initialize ; Jump to Initialization code
ORG H'04' ; 中断 Vector
ISR
ISRSave ; Macro to context save in ISR
bcf INTCON,TMR0IF ; Clear the TMR0 中断 condition
incf LEDCtr,F ; Add 1 to LEDCtr
incf PiezoCtr,F ; Add 1 to PiezoCtr
call DoReloadTimer ; Reload the Timer for accurate timing
ISRRestore ; Macro to context restore when leaving ISR
retfie ; Return from 中断
Initialize
LEDOff 0 ; Turn off both LEDs
LEDOff 1 ; "
clrf LEDCtr ; Initialze Task Couters to 0
clrf PiezoCtr ; " (both LED and Piezo)
LEDEnable H'FC' ; MACRO to setup I/O port to drive LEDs RB1 and RB0
PiezoEnable D'500' ; 500 Hz Beep when PiezoOn is used
call DoReloadTimer ; Preload the timer for appropriate time delay
BANKSEL OPTION_REG ; set banking to access OPTION_REG in bank 1
movlw B'11000111' ; Set up TMR0 for 256 prescale and
movwf OPTION_REG ; internal clock mode
BANKSEL PORTB ; Return to accessing BANK 0
movlw B'10100000' ; Turn on GIE and TMR0 中断
movwf INTCON ; "
LEDTest
movlw D'8' ; Test LED1 Counter Value for overflow
subwf LEDCtr,W ; by subtracting 8 from it. Leave result in W
btfss STATUS,Z ; Test for 0 to determine if equal
goto NotEqual1 ; If counter is not 8, test if LED should be on or off
clrf LEDCtr ; If counter is 8, it is reset to 0
NotEqual1
movlw D'3' ; Test LED counter against "On" time
subwf LEDCtr,W ; by subtracting 3 from it. Leave result in W
btfsc STATUS,C ; Test for negative value to determine if less than 3
goto TurnOffLED ; if 3 or more, goto LEDOff Code
TurnOnLED
LEDOn 0 ; else, Turn on LED 0 since counter is less than 3
goto PiezoTest ; LED Testing done, goto PiezoTest
TurnOffLED
LEDOff 0 ; Turn off LED since counter is 3 or more (up to 7)
; LED Testing now done, so fall into PiezoTest
PiezoTest
movlw D'30' ; Test Piezo Counter Value
subwf PiezoCtr,W ; by subtracting 30 from it. Leave result in W
btfss STATUS,Z ; Test for 0 to determine if equal
goto NotEqual2 ; If counter is not 30, test if LED should be on or off
clrf PiezoCtr ; If counter is 30, it is reset to 0
NotEqual2
movlw D'10' ; Test Piezo Counter against "On" time
subwf PiezoCtr,W ; by subtracting 10 from it. Leave result in W
btfsc STATUS,C ; Test for negative value to determine if less than 3
goto TurnOffPiezo ; if 10 or more, goto LEDOff Code
TurnOnPiezo
LEDOn 1 ; Turn on LED1
PiezoOn ; Turn on Piezo (by turning on CCP1)
goto LEDTest ; manage tasks by returning to top of list
TurnOffPiezo
LEDOff 1 ; Turn off LED1
PiezoOff ; Turn off Piezo (by turning off CCP1)
goto LEDTest ; manage tasks by returning to top of list
; Subroutine to reload TMR0
DoReloadTimer
movlw D'256' - D'195' ; Preload Timer to
movwf TMR0 ; count 195 times before roll-over
return ; return from subroutine
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -