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

📄 lampe.asm

📁 CCP1模块使用的有关PIC应用程序Trabicom On Board Engine Controller
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	call	PAUSE_SHORT2            ; kurz
	btfsc	BIT_ARRAY,BIT_TASTER
	goto 	SOS_MODE_ENDE		; Taster wurde gedr點kt

	decfsz	SOS_COUNTER,f
	goto	SOS_MODE_2
	goto	SOS_MODE

SOS_MODE_ENDE
	bcf	BIT_ARRAY,BIT_TASTER
	return


; ************************************************
; * in dieser Pause ist die Lampe ausgeschaltet
; ************************************************

PAUSE_SHORT
	call	LAMP_OFF
	call	Delay10
	call	Delay10
	call	Delay10
	call	Delay10
	call	Delay10
	call	LAMP_ON
	return


; ************************************************
; * Lampe leuchtet kurz
; ************************************************

PAUSE_SHORT2
	call	Delay10
	call	Delay10
	call	Delay10
	call	Delay10
	call	Delay10
	return

; ************************************************
; * Lampe leuchtet lang
; ************************************************

PAUSE_LONG
	call	Delay1
	call	Delay10
	call	Delay10
	call	Delay10
	call	Delay10
	call	Delay10
	return



; *******************************************************
; * PWM Initialisieren
; *******************************************************

InitPwm
; *******************************************************
; * PWM_Periode = Tocs / [4 * TM2PS * (PR2 + 1)]
; *
; * PR2 = Tocs / (4 * PWM_Periode * TM2PS) - 1
; *
; * Vorteiler:
; * 		T2CKPS1	T2CKPS0
; * 	 1:1	   0	   0
; * 	 4:1	   0	   1
; * 	16:1	   1	  egal
; *
; * Resolution = log(Fosc/Fpwm) / log(2) [bits]
; *
; * Duty-Cycle ist ein 10-bit Wert; der Wert steht im Register CCPR1L und den Bits 5 und 4 vom Register CCP1CON
; *******************************************************

; Vorteiler auf 4:1 und TMR2 einschalten
	bcf	T2CON,T2CKPS1
	bsf	T2CON,T2CKPS0
	bsf	T2CON,TMR2ON

; Einstellen der Frequenz von 1 kHz
; PR2 = 4.000.000 / (4 * 1.000 * 4)) -1  =  4.000.000 / 16.000 - 1 = 249
	movlw	D'249'
	BANK_1
	errorlevel -302
	movwf	PR2
	BANK_0

; Einstellen vom Tastverh鋖tnis (0%)
	movlw	D'0'
	movwf	CCPR1L

; CCP Pin zum Ausgang machen
	BANK_1
	errorlevel -302
	bcf	TRISC,PWM_OUT
	BANK_0

; Aktivieren vom PWM Modul
	clrf	CCP1CON
	bsf	CCP1CON,CCP1M3
	bsf	CCP1CON,CCP1M2

	return


;**************************************************************************
;* mit jeder Instruction wird der Timer0 incrementiert
;* bei 4 MHz alle 10^-6 Sekunden (1 ns)
;* bei einem 躡erlauf erfolgt der Interrupt
;* durch den Prescaler kann die Aufl鰏ung herabgesetzt werden
;* bei 1:256 erfolgt alle 0,065536 Sekunden ein 躡erlauf
;*
;* spezielle Wert vom COUNTER_TMR0
;* 	15   1 Sekunde
;*	38   2,5 Sekunden
;*	76   5 Sekunden
;**************************************************************************

TIMER0_INTERRUPT
	bcf	INTCON,T0IF		; ansonsten Endlosschleife
	btfss	INTCON,T0IE
	return				; Timer interrupt ist gar nicht aktiv

	incf	COUNTER_TMR0,f		; nur ca. alle 17 Sekunden kommt es zu einem 躡erlauf vom COUNTER_TMR0

	btfsc	PORTB,PIN_TASTER
	goto	TASTER_UP		; Taster wurde losgelassen

	movfw	COUNTER_TMR0
	sublw	D'76'			; w = const - w
	btfsc	STATUS,C
	return				; Taster wurde nicht lange genug f黵 einen langen Tastendruck gedr點kt

	bsf	BIT_ARRAY,BIT_TASTER_LONG
	clrf	COUNTER_TMR0
	; Lampe ein-/ausschalten weil Taster wurde lange gedr點kt
	btfss	BIT_ARRAY,BIT_ONOFF
	goto	LAMP_100_ON          	; Lampe war ausgeschaltet --> einschalten

	call	RESET                   ; Lampe war eingeschaltet --> ausschalten
	return

TASTER_UP				; Taster wurde losgelassen
	bcf	INTCON,INTF
	bsf	INTCON,INTE		; RB0 Interrupt enablen
	bcf	INTCON,T0IE		; Timer0 Interrupt disablen

	movfw	COUNTER_TMR0
	sublw	D'15'			; w = const - w
	btfsc	STATUS,C
	return				; Taster wurde zu kurz gedr點kt --> Interrupt verlassen

	movfw	COUNTER_TMR0		;
	sublw	D'38'			; w = const - w
	btfss	STATUS,C
	return				; Taster wurde l鋘ger als kurz gedr點kt

	bsf	BIT_ARRAY,BIT_TASTER	; es erfolgte ein kurzer Tastendruck

; Status der LED abfragen
	btfss	BIT_ARRAY,BIT_LED100
	goto	LED100OFF		; 100% ist nicht aktiv

	bcf	BIT_ARRAY,BIT_LED100	; --> 80%
	bsf	BIT_ARRAY,BIT_LED80
	movlw	PROZENT_80
	movwf	CCPR1L_TMP
	movwf	CCPR1L
	return

LED100OFF
	btfss	BIT_ARRAY,BIT_LED80
	goto	LED80OFF		; 80% ist nicht aktiv

	bcf	BIT_ARRAY,BIT_LED80     ; --> 50%
	bsf	BIT_ARRAY,BIT_LED50
	movlw	PROZENT_50
	movwf	CCPR1L_TMP
	movwf	CCPR1L
	return

; derzeit ohne SOS Modus

LED80OFF
	btfss	BIT_ARRAY,BIT_LED50
	goto	LED50OFF		; 50% ist nicht aktiv

	bcf	BIT_ARRAY,BIT_LED50	; --> SOS
	bsf	BIT_ARRAY,BIT_LEDSOS
	movlw	PROZENT_80
	movwf	CCPR1L_TMP
	movwf	CCPR1L
	return

LED50OFF
	bcf	BIT_ARRAY,BIT_LEDSOS	; --> 100%
	bsf	BIT_ARRAY,BIT_LED100
	movlw	PROZENT_100
	movwf	CCPR1L_TMP
	movwf	CCPR1L
	return


LAMP_100_ON				; Lampe war ausgeschaltet
	bsf	BIT_ARRAY,BIT_LED100
	bsf	BIT_ARRAY,BIT_ONOFF

; Einstellen vom Tastverh鋖tnis (100%)
	movlw	PROZENT_100
	movwf	CCPR1L_TMP
	call	LAMP_ON			; f黨rt auch einen Softstart aus
	call	Delay1
	return

RESET
	clrf	BIT_ARRAY
	clrf	BIT_ARRAY2
	clrf	COUNTER_TMR0
	bcf	PORTB,LED_GREEN	; test
	call	LAMP_OFF
	return


PORT_CHANGE_INTERRUPT			; Taster wurde gedr點kt
	bcf	INTCON,INTF		; ansonsten Endlosschleife
	btfss	INTCON,INTE
	return				; RB0 interrupt ist gar nicht aktiv

	clrf	TMR0
	clrf	COUNTER_TMR0		; --> Taster ist tats鋍hlich gedr點kt
	bcf	INTCON,T0IF
	bsf	INTCON,T0IE		; Timer0 Interrupt enablen
	bcf	INTCON,INTE		; RB0 Interrupt disablen
	bcf	INTCON,INTF		; sicherheitshalber...
	return

;
; Generated by www.piclist.com/cgi-bin/delay.exe (January 1, 2002 version)
; Sun Nov 24 09:58:56 2002 GMT

; See also various delay routines at http://www.piclist.com/techref/microchip/delays.htm

; Delay = 1 seconds
; Clock frequency = 4 MHz

; Actual delay = 1 seconds = 1000000 cycles
; Error = 0 %

Delay1
 ifdef	DEBUG
 	call	Delay10000
 	return
 endif
			;999990 cycles
	movlw	0x07
	movwf	d1
	movlw	0x2F
	movwf	d2
	movlw	0x03
	movwf	d3
Delay_0_1
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0_1

			;6 cycles
	goto	$+1
	goto	$+1
	goto	$+1

			;4 cycles (including call)
	return

; *******************************************************************************************

; Delay = 100000 instruction cycles
; Clock frequency = 4 MHz

; Actual delay = 0.1 seconds = 100000 cycles
; Error = 0 %

Delay10
 ifdef	DEBUG
 	call	Delay10000
 	return
 endif
			;99993 cycles
	movlw	0x1E
	movwf	d1
	movlw	0x4F
	movwf	d2
Delay_0_10
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay_0_10

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return

; Generated by www.piclist.com/cgi-bin/delay.exe (January 1, 2002 version)
; Sun Nov 24 10:01:42 2002 GMT

; See also various delay routines at http://www.piclist.com/techref/microchip/delays.htm


; *******************************************************************************************

; Delay = 10000 instruction cycles
; Clock frequency = 4 MHz

; Actual delay = 0.01 seconds = 10000 cycles
; Error = 0 %

Delay100
 ifdef	DEBUG
 	call	Delay10000
 	return
 endif
			;9993 cycles
	movlw	0xCE
	movwf	d1
	movlw	0x08
	movwf	d2
Delay_0_100
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay_0_100

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return

; *******************************************************************************************
; Delay = 1000 instruction cycles
; Clock frequency = 4 MHz

; Actual delay = 0.001 seconds = 1000 cycles
; Error = 0 %

Delay1000
 ifdef	DEBUG
 	call	Delay10000
 	return
 endif
			;993 cycles
	movlw	0xC6
	movwf	d1
	movlw	0x01
	movwf	d2
Delay_0_1000
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay_0_1000

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return

; *******************************************************************************************
; Delay = 100 instruction cycles
; Clock frequency = 4 MHz

; Actual delay = 0.0001 seconds = 100 cycles
; Error = 0 %

Delay10000
			;94 cycles
	movlw	0x1F
	movwf	d1
Delay_0_10000
	decfsz	d1, f
	goto	Delay_0_10000

			;2 cycles
	goto	$+1

			;4 cycles (including call)
	return
; *******************************************************************************************

	END

⌨️ 快捷键说明

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