?? lab2.asm
字號:
#INCLUDE p16F877A.inc ; Include the standard definitions
__CONFIG _CP_OFF & _DEBUG_ON & _WRT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC
NOP
clrf PORTB ; Initialize PORTB so that all LEDs are off by default初始化PORTB,將所有LED關閉
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?
On
movlw B'00001000' ; "On" code writes a value to PORTB to turn on RB3 (high)
movwf PORTB ; and sets rest of PORTB low, including RB1.
goto Loop ; The test of the button happens again by branching to "Loop"
Here
goto Here ; This code is not needed either. Why?
END ; All programs must have an END directive
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -