⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lab5.asm

📁 pic单片机资料
💻 ASM
字号:
		#INCLUDE p16F877A.inc	; Include the standard definitions
		#INCLUDE 701PIC.inc		; Include MACROs from MASTER抯 03, PIC 102 class

ISRCtr	EQU	0x30				; location for ISRCtr variable (countdown for ISR loops)

		ORG	0					; Reset Vector Location (0)
Start 
		goto	Initialize		; On start-up go to Initialization code

		ORG	4					; Interrupt Vector Location (4)
ISR
		ISRSave					; Macro to context save in ISR
		bcf		INTCON,T0IF		; Clear the TMR0 interrupt condition
		call	DoReloadTimer	; Reload the Timer for accurate timing
		decfsz	ISRCtr,F		; Decrement the ISRCounter (from 4 to 0) and test for 0
		goto	SkipToggle		; if the counter is not yet 0, then toggling is not needed
		goto	ToggleLED		; if the counter is 0, run toggle code

ToggleLED
		movlw	4				; put 4 into W to reload into the
		movwf	ISRCtr			; Interrupt counter (after 4 counts we need to reset it)

		movlw	B'00000001'		; write 1 to W in order to, 
		xorwf	PORTB,F			;  toggle LED 0 of PORTB - XOR with 1 will toggle the bit

SkipToggle						; Done interrupt, so restore and exit
		ISRRestore				; Macro to context restore when leaving ISR
		retfie					; Return from interrupt

Initialize
		LEDOff	0				; Ensure LED 0 is off
		LEDEnable	H'FE'		; MACRO to setup I/O port to drive LED RB0
		movlw	4				; Write 4 to W to 
		movwf	ISRCtr			;  preload the ISR counter with
		call	DoReloadTimer	; Preload the timer for appropriate time delay
		movlw	B'10100000'		; Turn on GIE and 
		movwf	INTCON			;  TMR0 interrupt (T0IE)
		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

		goto	$				; Wait forever for Interrupt


; 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 + -