0
|
1 ;=============================================================================
|
|
2 ;
|
634
|
3 ; File wait.asm * combined next generation V3.09.4
|
0
|
4 ;
|
582
|
5 ; Wait routines
|
0
|
6 ;
|
|
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
|
|
8 ;=============================================================================
|
|
9 ; HISTORY
|
604
|
10 ; 2004-01-31 : [chsw] initial version
|
|
11 ; 2007-05-11 : updated (OSTC code)
|
|
12 ; 2011-10-18 : [mH] timings tested with oscilloscope
|
582
|
13
|
275
|
14 #include "hwos.inc"
|
0
|
15
|
604
|
16
|
0
|
17
|
634
|
18 ;=============================================================================
|
|
19 wait1 CODE
|
|
20 ;=============================================================================
|
623
|
21
|
634
|
22 ;-----------------------------------------------------------------------------
|
|
23 ; Wait 1 Second
|
|
24 ; Warning: do not use for time critical routines - can be between 0 and 1 sec!
|
|
25 ;
|
623
|
26 global wait_1s
|
|
27 wait_1s:
|
|
28 bcf trigger_full_second ; clear any left-over trigger
|
|
29 btfss trigger_full_second ; did a new trigger occurred?
|
|
30 bra $-2 ; NO - loop
|
|
31 return ; YES - done
|
|
32
|
|
33
|
634
|
34 ;=============================================================================
|
|
35 wait2 CODE
|
|
36 ;=============================================================================
|
|
37
|
|
38 ;-----------------------------------------------------------------------------
|
|
39 ; Wait for a Multiple of 1 Second
|
|
40 ; Warning: do not use for time critical routines - can be up to 1 sec longer!
|
|
41 ;
|
|
42 global WAITSX
|
|
43 WAITSX:
|
|
44 bcf trigger_full_second ; clear any left-over trigger
|
|
45 btfss trigger_full_second ; did a new trigger occurred?
|
|
46 bra $-2 ; NO - loop
|
|
47 decfsz WREG,W ; YES - count down loop counter, became zero?
|
|
48 bra WAITSX ; NO - loop
|
|
49 return ; YES - done
|
|
50
|
|
51
|
|
52 ;=============================================================================
|
|
53 wait3 CODE
|
|
54 ;=============================================================================
|
|
55
|
|
56 ;-----------------------------------------------------------------------------
|
|
57 ; Wait for a Multiple of 1 Millisecond
|
623
|
58 ; Remark: not exact: 1.008 ms +/- 30.5 µs + worst case ISR latency
|
634
|
59 ;
|
582
|
60 global WAITMSX
|
|
61 WAITMSX:
|
623
|
62 movwf wait_counter ; store number of milliseconds to wait
|
582
|
63 WAITMSX2:
|
623
|
64 setf TMR5H ; initialize timer 5, high byte first
|
|
65 movlw .255-.32 ; 32 x 31.5 µs = 1.008 ms
|
|
66 movwf TMR5L ; initialize timer 5, low byte thereafter
|
|
67 bcf PIR5,TMR5IF ; clear timer 5 overrun flag
|
582
|
68 WAITMSX3:
|
623
|
69 btfss PIR5,TMR5IF ; did timer 5 overrun?
|
|
70 bra WAITMSX3 ; NO - repeat inner loop
|
|
71 decfsz wait_counter,F ; YES - decrement number of milliseconds to do, done?
|
|
72 bra WAITMSX2 ; NO - repeat outer loop
|
|
73 return ; YES - done
|
0
|
74
|
634
|
75 ;-----------------------------------------------------------------------------
|
0
|
76
|
582
|
77 END |