📄 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
__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _LVP_OFF & _BODEN_OFF
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 ; 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 TRISA ; 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 PORTA ; Return to accessing BANK 0
BSF INTCON, GIE
BSF INTCON, TMR0IE ; 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'61' ; 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 + -