comparison src/wait.asm @ 623:c40025d8e750

3.03 beta released
author heinrichsweikamp
date Mon, 03 Jun 2019 14:01:48 +0200
parents ca4556fb60b9
children 4050675965ea
comparison
equal deleted inserted replaced
622:02d1386429a6 623:c40025d8e750
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File wait.asm V2.98c 3 ; File wait.asm combined next generation V3.02.1
4 ; 4 ;
5 ; Wait routines 5 ; Wait routines
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
11 ; 2007-05-11 : updated (OSTC code) 11 ; 2007-05-11 : updated (OSTC code)
12 ; 2011-10-18 : [mH] timings tested with oscilloscope 12 ; 2011-10-18 : [mH] timings tested with oscilloscope
13 13
14 #include "hwos.inc" 14 #include "hwos.inc"
15 15
16 wait CODE 16 wait CODE
17
18
19 ; ==========================================================
20 ; WAIT 1 second (Warning: Do not use for time critical routines. Can be between 0 and 1 sec!)
21 ; ==========================================================
22 global wait_1s
23 wait_1s:
24 ; Wait until "next second" flag is set
25 bcf onesecupdate
26 btfss onesecupdate
27 bra $-2
28 return
29 17
30 18
31 ; ============================================================================= 19 ; =============================================================================
32 ; WAIT 1 MILLISECOND (Not exact: 1,008ms +/- 30,5µs + worst case ISR latency) 20 ; WAIT 1 second
21 ; Warning: Do not use for time critical routines - can be between 0 and 1 sec!
22 ; =============================================================================
23
24 global wait_1s
25 wait_1s:
26 bcf trigger_full_second ; clear any left-over trigger
27 btfss trigger_full_second ; did a new trigger occurred?
28 bra $-2 ; NO - loop
29 return ; YES - done
30
31
32 ; =============================================================================
33 ; WAIT for multiples of 1 Millisecond
34 ; Remark: not exact: 1.008 ms +/- 30.5 µs + worst case ISR latency
33 ; ============================================================================= 35 ; =============================================================================
34 36
35 global WAITMSX 37 global WAITMSX
36 WAITMSX: 38 WAITMSX:
37 movwf wait_counter 39 movwf wait_counter ; store number of milliseconds to wait
38 WAITMSX2: 40 WAITMSX2:
39 setf TMR5H 41 setf TMR5H ; initialize timer 5, high byte first
40 movlw .255-.32 ; 32 x 31,5µs = 1,008ms 42 movlw .255-.32 ; 32 x 31.5 µs = 1.008 ms
41 movwf TMR5L 43 movwf TMR5L ; initialize timer 5, low byte thereafter
42 bcf PIR5,TMR5IF ; clear flag 44 bcf PIR5,TMR5IF ; clear timer 5 overrun flag
43 WAITMSX3: 45 WAITMSX3:
44 btfss PIR5,TMR5IF 46 btfss PIR5,TMR5IF ; did timer 5 overrun?
45 bra WAITMSX3 ; wait loop 47 bra WAITMSX3 ; NO - repeat inner loop
46 decfsz wait_counter,F 48 decfsz wait_counter,F ; YES - decrement number of milliseconds to do, done?
47 bra WAITMSX2 49 bra WAITMSX2 ; NO - repeat outer loop
48 return 50 return ; YES - done
49 51
50 ;============================================================================= 52 ;=============================================================================
51 53
52 END 54 END