;______________________________________ ; MODULE Wait ; Matériel : ATtiny 45/85 4MHz à 20Mhz 5V ; (c) sammy76.free.fr ; V1.0 2016/11/06 ;______________________________________ ;.ifndef F_CPU ; .define F_CPU 16500000 ;16.5MHz ;.error "F_CPU must be defined!" ;.endif .if F_CPU < 4000000 .message "Processeur beaucoup trop lent" .warning "F_CPU too low, possible wrong delay" .endif .define CYCLES_PER_US (F_CPU/1000000) ;Nombre de cycles par us .define C4PUS (F_CPU/4000000) ;/4 nombre de périodes par us attention aux approximation .define FOR1MS (F_CPU/1000)/(F_CPU/1000000) ;Pour éviter l'approximation des 16.5MHz ;.define DVUS(x) (C4PUS*x) ;------------------------------------------------------------------------------ ; Input : XH:XL - number of CPU cycles to wait (divided by four) ;------------------------------------------------------------------------------ Wait4xCycles: sbiw XH:XL, 1 ; x-- (2 cycles) brne Wait4xCycles ; jump if not zero (2 cycles) ret ;------------------------------------------------------------------------------ ; Input : A - number of miliseconds to wait ;------------------------------------------------------------------------------ ;Attention: ;Approximation pour 1ms = 4*1000*4cyc*1000rep*3mult/16.5E6 soit 0.969ms ;donc avec les répétitions on cumul l'erreur ; WaitMiliseconds: push A WaitMsLoop: ldi XH,HIGH(C4PUS*FOR1MS) ;1000us soit 1ms en fait avec 16.5MHz mettre 1031 ldi XL,LOW(C4PUS*FOR1MS) rcall Wait4xCycles dec A brne WaitMsLoop pop A ret ;------------------------------------------------------------------------------ ;Input : A - number of seconds to wait ;------------------------------------------------------------------------------ waitseconds: push A push YL push YH waitsec: ldi YL,10 ;1s push A waitms: ldi A,100 ;0,1s rcall WaitMiliseconds dec YL brne waitms pop A dec A brne waitsec pop YH pop YL pop A ret