Ver0

Z MAM wiki

Přejít na: navigace, hledání
; 
; example fan program for ATmega168
;
; P4 CPU fan Ucc pin is supposed to be connected 
; to +15 V, GND pin is supposed to be connected 
; to FET Drain, Source on GND, Gate on 
; pin 16 (PB2, FAN). Fan runs when FAN is 1.


	.EQU DDRB = $04
	.EQU PORTB = $05

	.EQU FAN = 2

	.EQU DDRC = $07
	.EQU PORTC = $08
	.EQU PINC = $06

	.EQU DDRD = $0A
	.EQU PORTD = $0B
	.EQU PIND = $09


; Pin driving FAN is set as output:

	SBI	DDRB, FAN

; Basic keyboard init:
	SBI DDRD, 2
	SBI PORTC, 2

GO:
	RCALL   FAN_OFF

	SBIS	PINC, 2
	RCALL	FAN3W

	RCALL	WAIT
	RCALL	WAIT
	RCALL	WAIT
	RJMP	GO


;;;
;;;
;;; P R O C E D U R E S
;;;
;;;
	
VERYSMALLWAIT:
	LDI R20, 0xFC
	MOV R1, R20
SMALLWAIT:
	INC	R1
	BRNE	SMALLWAIT
	RET

WAIT:
	LDI	R21, 4
WAIT1:
	INC	R1
	BRNE	WAIT1
	INC	R2
	BRNE	WAIT1
	DEC	R21
	BRNE	WAIT1
	RET
	
FAN_ON:
    SBI	PORTB, FAN
	RET

FAN_OFF:
	CBI	PORTB, FAN
	RET

FAN3W:
	LDI	R16, 0x20
FAN3X:
 	RCALL	FAN_ON
	RCALL	VERYSMALLWAIT  ; pulse ratio controlled by number of waits
	RCALL	VERYSMALLWAIT  ; 4:1 in this case
	RCALL	VERYSMALLWAIT
	RCALL	VERYSMALLWAIT
	RCALL	FAN_OFF
	RCALL	VERYSMALLWAIT 


	INC	R2
	BRNE	FAN3X
	DEC	R16
	BRNE	FAN3X
	RET


Osobní nástroje