📄 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
; Clear the TMR0 中断 condition
; Add 1 to LEDCtr
; Add 1 to PiezoCtr
; Reload the Timer for accurate timing
; Macro to context restore when leaving ISR
; Return from 中断
Initialize
LEDOff 0 ; Turn off both LEDs
LEDOff 1 ; "
clrf LEDCtr ; Initialze Task Couters to 0
; " (both LED and Piezo)
; MACRO to setup I/O port to drive LEDs RB1 and RB0
; 500 Hz Beep when PiezoOn is used
; Preload the timer for appropriate time delay
; set banking to access OPTION_REG in bank 1
; Set up TMR0 for 256 prescale and
; internal clock mode
; Return to accessing BANK 0
; Turn on GIE and TMR0 中断
movwf INTCON ; "
LEDTest
movlw D'8' ; Test LED1 Counter Value for overflow
; by subtracting 8 from it. Leave result in W
; Test for 0 to determine if equal
goto NotEqual1 ; If counter is not 8, test if LED should be on or off
; If counter is 8, it is reset to 0
NotEqual1
; Test LED counter against "On" time
; by subtracting 3 from it. Leave result in W
; Test for negative value to determine if less than 3
goto TurnOffLED ; if 3 or more, goto LEDOff Code
TurnOnLED
; 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
; Test Piezo Counter Value
; by subtracting 30 from it. Leave result in W
; Test for 0 to determine if equal
goto NotEqual2 ; If counter is not 30, test if LED should be on or off
; If counter is 30, it is reset to 0
NotEqual2
; Test Piezo Counter against "On" time
; by subtracting 10 from it. Leave result in W
; Test for negative value to determine if less than 3
goto TurnOffPiezo ; if 10 or more, goto LEDOff Code
TurnOnPiezo
; Turn on LED1
; Turn on Piezo (by turning on CCP1)
goto LEDTest ; manage tasks by returning to top of list
TurnOffPiezo
; 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
; Preload Timer to
; count 195 times before roll-over
; return from subroutine
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -