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

📄 ex1201.asm

📁 关于PIC16F877A单片机的一些源代码,比较丰富.初学者认真看看应该有收获的.
💻 ASM
字号:
;
;	8 BITS A/D(VR) + LCD + PWM
;
	LIST P=16F877, R=DEC
	#INCLUDE P16F877.INC
	CBLOCK 0X20
	ENDC
;
;	DEFINE RAM
;
	CBLOCK
	 BCDBFH, BCDBFL
	ENDC
;
	ORG 0
	NOP
	GOTO MAIN
;
;

;---------------------------------------------------------------;
								;
	#INCLUDE <LCD.INC>					;
								;
; Defines for I/O ports that provide LCD data & control		;
								;
LCD_DATA	equ	PORTB					;
LCD_CNTL	equ	PORTB					;
								;
RS	equ	5	; RS=PORTB,5				;
E	equ	4						;
								;
;===============================================================;
;
	#INCLUDE <HX2BCD.INC>
	#include <DLY2_5mS.INC>
;
;.................................
;

MAIN:
	call	InitLCD
	call	clrLCD
;
;************************************************
;*   - Initialize the A/D converter             *
;*        - Left justified                      *
;*        - 1 analog channels, 0 references     *
;*        - Fosc/8 clock source                 *
;*        - Channel 0                           *
;*        - Enable A/D                          *
;************************************************
;
	BANKSEL ADCON1		; ADCON1 is in bank1
	MOVLW B'00001110'	; select left(0) justified (d7)
				; 1 ch(AN0)/0 refs
	MOVWF ADCON1
;
	BANKSEL ADCON0
	MOVLW B'01000001'	; select Fosc/8(01), AN0(000)
	MOVWF ADCON0		; a/d done(0), x(0), a/d ON(1)
;
;************************************************
;*   - Initialize the CCP1 Module               *
;*        - Set the period to FFh               *
;*        - Make RC2 an output                  *
;*        - Configure CCP1 for PWM (xxxx11xx)   *
;*   - Initialize Timer2                        *
;*        - 1:1 Postscale (x0000xxx)            *
;*        - 1:4 Prescale  (xxxxxx01)            *
;*        - Enable the timer (xxxxx1xx)         *
;************************************************

	BANKSEL PR2
	MOVLW H'FF'
	MOVWF PR2
	BCF TRISC,2
	BANKSEL CCP1CON
	MOVLW	B'00001111'
	MOVWF	CCP1CON
	MOVLW	B'00000101'
	MOVWF	T2CON

	CALL DLY2_5mS		; wait for input charge
MAIN1:
	BSF ADCON0,GO		; start a/d converting
MAIN2:
	BTFSC ADCON0,GO		; a/d convertion finished?
	GOTO MAIN2		; no	
;
	call	L2homeLCD
	MOVF ADRESH,W		; read a/d result ( high byte )
	CALL HX2BCD		; convert HEX to BCD
				; results in BCDBFH/BCDBFL
;
	MOVF BCDBFH,W		; output a/d results to LCD
	CALL	putHexLCD
;
	MOVF BCDBFL,W
	CALL	putHexLCD
;
	MOVF ADRESH,W
	MOVWF CCPR1L		; Also in Duty cycle
;
	GOTO MAIN1
;
;
;
	END

⌨️ 快捷键说明

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