📄 lab4.asm
字号:
#INCLUDE p16F877A.inc ; Include the standard definitions
#INCLUDE 701PIC.inc ; Include MACROs from MASTER抯 03, PIC 102 class
#DEFINE TESTVAL D'100' ; High Value to compare A/D reading against
#DEFINE DEVICE_FREQ_HZ D'4000000' ; Used in later calculations
Start
LEDEnable B'11111100' ; MACRO to setup I/O port to drive LEDs RB1 and RB0
BANKSEL TRISA ; BANKSEL to TRISA in bank 1
movlw H'01' ; Initialize PORTA so that RA0 (analog channel 0) is an input,
movwf TRISA ; all other PORTA pins are outputs
movlw H'0E' ; Initialize the A/D to be analog on
movwf ADCON1 ; channel 0 (RA0), all other pins are digital mode
BANKSEL ADCON0 ; BANKSEL to ADCON0 in bank 0
movlw H'41' ; Also, A/D clock is Fosc/8 (good for up to 5 MHz, 5V) and,
movwf ADCON0 ; A/D is turned on but not yet converting and ready on Ch 0.
PiezoEnable 440
CheckAgain
Dly32 D'50' ; MACRO to Wait 1 ms (at 4 MHz)
bsf ADCON0,GO ; Start the Conversion
PollAD
btfsc ADCON0,GO ; Wait for Conversion to finish
goto PollAD ; go back and poll the A/D GO/DONE bit again
ConvertDone
movf ADRESH,W ; Move A/D result (high byte) into W for later testing
sublw TESTVAL ; Test A/D result against test value
btfss STATUS,C ; go to "over" if A/D result larger than test value
goto Over ; value is too large, run "Over" code
Ok
LEDOn 0 ; MACRO to turn on LED 0
LEDOff 1 ; MACRO to turn off LED 1 (this shows "Ok" condition)
PiezoOff
goto CheckAgain ; Do A/D read and value test over again
Over
LEDOn 1 ; MACRO to turn on LED 1
LEDOff 0 ; MACRO to turn off LED 0 (this shows "Over" condition)
PiezoOn
goto CheckAgain ; Do A/D read and value test over again
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -