lab3.asm

来自「pic单片机资料」· 汇编 代码 · 共 28 行

ASM
28
字号
		#INCLUDE p16F877A.inc	; Include the standard definitions

Start
		BANKSEL	TRISC		; BANKSEL to get to TRISC bank (bank 1)
		bcf		TRISC,2		; Set CCP1 as an output
		movlw	D'70'		; Manualy Calculated Period
		movwf	PR2			;  loaded into PR2 (also in bank1)
		BANKSEL	CCPR1L		; BANKSEL is needed to get bank to bank 0.
		movlw	D'35'		; Manually Calculated Duty Cycle (50%)		
		movwf	CCPR1L		;  loaded into CCPR1L
		movlw	0x06		; Turn on TMR2 (for PWM) 
		movwf	T2CON		; and /16 prescale

CheckButton
		btfsc	PORTA,4		; Test the button - if pressed, its a low signal. 
		goto	ButtonOff	; if high (not pressed), go to "Button Off" code

ButtonOn
		movlw	H'0C'		; if low (pressed), fall here to "Button On" code.
		movwf	CCP1CON		; this turns on CCP1CON by writing 0C (hex) to it.
		goto	CheckButton	; go check the button again (back to CheckButton)

ButtonOff
		clrf	CCP1CON		; Turn off CCP1 module by writing 0 to it
		goto	CheckButton	; go check the button again (back to CheckButton)
		END					; All programs must have an END directive
		

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?