📄 lab2.asm
字号:
#INCLUDE p16F877A.inc ; Include the standard definitions
clrf PORTB ; Initialize PORTB so that all LEDs are off by default
BANKSEL TRISB ; BANKSEL is used to get to bank with TRISB in it (bank 1)
clrf TRISB ; Clear TRISB to make all PORTB pins outputs
movlw B'00010000' ; Make pin RA4 an input (rest of PORTA pins are outputs)
movwf TRISA ; This is redundant as TRISA bits are 1抯 by default (inputs)
; (the rest of the pins are set low)
movlw H'07' ; Writing 7 into ADCON1 causes all analog pins to allow
movwf ADCON1 ; digital input. You must set ADCON1 when using pins with
; A/D functions as they are analog mode by default.
; This code isn抰 needed in this example - do you know why?
BANKSEL PORTA ; BANKSEL is used to return to bank 0 (for PORTA, PORTB)
Loop
btfss PORTA,4 ; Test RA4 on PORTA, skip if pin is high
goto On ; go to "On" code if button is pressed (pressed button is low)
Off
movlw B'00000010' ; "On" code is skipped so "Off" code runs - it writes a value to
movwf PORTB ; PORTB to turn on RB1 (high) and sets rest of PORTB low
goto Loop ; The test of the button happens again by branching to 揕oop
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -