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

📄 dddddd.asm

📁 pic实验源程序 分为六个实验,前面的太简单,就没有了,后面的比较复杂!
💻 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

		org 0

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.

		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


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)


		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	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)


		banksel CCP1CON
		clrf	CCP1CON		; Turn off CCP1 module by writing 0 to it

		;banksel PR2
		;RRF	PR2,f
		banksel CCP1CON
		goto	CheckAgain 	; Do A/D read and value test over again
		END

⌨️ 快捷键说明

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