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

📄 pulse.asm

📁 代码保护功能处于持续发展中。Microchip 承诺将不断改进产品的代码保护功能。任何试图破坏Microchip 代码保护功能的行为均可视 为违反了《数字器件千年版权法案(Digital Mille
💻 ASM
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;	PULSE.ASM	MPB		21-8-05
;	Generates timed output interval using Timer 1
;	in compare mode
;	Timer interrupt sets output, cleared after 1ms
; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	PROCESSOR 16F877A
;	Clock = XT 4MHz, standard fuse settings
	__CONFIG 0x3731

;	LABEL EQUATES	......................................

	INCLUDE "P16F877A.INC"	; Standard register labels 

Count	EQU	20		; soft timer

; Program begins ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	ORG	0		; Place machine code 
	NOP			; for ICD mode
	GOTO	init		; Jump over ISR vector

	ORG	4		; ISR vector address
	GOTO	isr		; run ISR

init	NOP
	BANKSEL	TRISC		; Select bank 1 
	MOVLW	B'11111011'	; RC2 = output
	MOVWF	TRISC		; Initialise display port
	MOVLW	B'00000100'	; Timer1 interrupt..
	MOVWF	PIE1		; ..enable 

	BANKSEL PORTC		; Select bank 0
	CLRF	PORTC		; Clear output
	MOVLW	B'11000000'	; Peripheral interupt.. 
	MOVWF	INTCON		; ..enable
	MOVLW	B'00001000'	; Compare mode..
	MOVWF	CCP1CON		; ..set output on match
	MOVLW	027		; Initial value..
	MOVWF	CCPR1H		; .. for high byte (10ms)
	MOVLW	010		; Initial value..
	MOVWF	CCPR1L		; .. for low byte (10ms)
	MOVLW	B'00000001'	; Timer1 enable..
	MOVWF	T1CON		; with internal clock (1MHz)

	GOTO	start		; Jump to main program 

;	SUBROUTINES............................................

;	1ms delay with 1us cycle time (1000 cycles)

onems	MOVLW	D'249'		; Count for 1ms delay 
	MOVWF	Count		; Load count
loop	NOP			; Pad for 4 cycle loop
	DECFSZ	Count		; Count
	GOTO	loop		; until Z
	RETURN			; and finish


;	INTERRUPT SERVICE ROUTINE..............................

;	Reset interrupt, check buttons, generate 1ms pulse

isr	CLRF	PIR1		; clear interrupt flags
	CLRF	TMR1H		; clear timer high..
	CLRF	TMR1L		; ..and low byte
	
	BTFSC	PORTD,0		; dec frequency button?
	GOTO	other		; no
	INCFSZ	CCPR1H		; yes, inc period, zero?
	GOTO	other		; no
	DECF	CCPR1H		; yes, step back

other	BTFSC	PORTD,1		; inc frequency button?
	GOTO	wait		; no
	DECFSZ	CCPR1H		; yes, inc period, zero?
	GOTO	wait		; no
	INCF	CCPR1H		; yes, step back

wait	CALL	onems		; wait 1ms
	BCF	CCP1CON,3	; clear output 
	BSF	CCP1CON,3	; re-enable timer mode

	RETFIE			; return to main program


;-----------------------------------------------------------
;	Main program
;-----------------------------------------------------------
start	GOTO	start		; wait for timer interrupt
	END			; of source code

⌨️ 快捷键说明

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