-
Notifications
You must be signed in to change notification settings - Fork 0
/
16f628a-helper.inc
116 lines (81 loc) · 1.22 KB
/
16f628a-helper.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
list p=16f628a
#include p16f628a.inc
processor 16f628a
PICINIT macro
; Comparators off
movlw b'00000111'
movwf CMCON
; Bank 1
errorlevel -302
bsf STATUS, RP0
movlw PORTAInputs
movwf TRISA
movlw PORTBInputs
movwf TRISB
;bcf PCON, OSCF ; 48khz osc
bcf STATUS, RP0
errorlevel +302
endm
StateSaveMemory udata_shr
SAVE_W res 1
SAVE_STATUS res 1
SAVE_FSR res 1
Temp res 1
SaveState macro
; Save state
movwf SAVE_W
swapf STATUS, W
movwf SAVE_STATUS
movfw FSR
movwf SAVE_FSR
bcf STATUS, RP0
endm
RestoreState macro
; Restore state
movwf SAVE_FSR
movfw FSR
swapf SAVE_STATUS, W
movwf STATUS
swapf SAVE_W, F
swapf SAVE_W, W
endm
TableLookup macro
local TABLE
movwf Temp
movlw high(TABLE)
movwf PCLATH
movfw Temp
addlw low(TABLE)
skpnc
incf PCLATH, f
movwf PCL
TABLE
endm
Copy3 macro Dst, Src
movfw Src
movwf Dst
movfw Src+1
movwf Dst+1
movfw Src+2
movwf Dst+2
endm
incFwrap macro F, max, min
incf F, f
movfw F
xorlw max+1
btfss STATUS, Z
return
movlw min
movwf F
return
endm
decFwrap macro F, min, max
decf F, f
movfw F
xorlw min-1
btfss STATUS, Z
return
movlw max
movwf F
return
endm