-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpw1setoc.c
222 lines (196 loc) · 5.14 KB
/
pw1setoc.c
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include <p18cxxx.h>
#include <pwm.h>
/********************************************************************
* Function Name: SetOutputPWM1 *
* Return Value: void *
* Parameters: outputconfig: holds PWM output configuration. *
* These configurations are defined in pwm.h. *
* outputmode: holds PWM output mode. *
* These modes are defined in pwm.h. *
* Description: This routine sets the PWM output config bits *
* and mode bits for ECCP and configures the *
* appropriate TRIS bits for output. *
********************************************************************/
#if defined (PWM_V1) || defined (PWM_V2) || defined (PWM_V3) || defined (PWM_V4) ||\
defined (PWM_V5) || defined (PWM_V6) || defined (PWM_V7) || defined (EPWM_V7) ||\
defined (PWM_V9) || defined (PWM_V10) || defined (PWM_V11) || defined (PWM_V12)
void SetOutputPWM1(unsigned char outputconfig, unsigned char outputmode)
{
char eccpmx; /* will be set iff bit 1 of __CONFIG3H is set */
#ifndef _OMNI_CODE_
unsigned char TBLPTR_U, TBLPTR_L;
_asm
movff TBLPTRU, TBLPTR_U
movff TBLPTRL, TBLPTR_L
_endasm
#endif
/* set P1M1 and P1M0 */
outputconfig |= 0b00111111;
outputmode |= 0b11111100;
CCP1CON = (CCP1CON | 0b11000000) & outputconfig;
/* set CCP1M3, CCP1M2, CCP1M1, CCP1M0 */
CCP1CON = (CCP1CON | 0b00001111) & outputmode;
#if defined (PWM_CONFIG3L_V1) || defined (PWM_CONFIG3L_V2)
#if defined (PWM1_IO_V4)
if (((*(unsigned char far rom *)__CONFIG3H) & 0b00000010))
eccpmx=0xff;
else
eccpmx = 0;
#endif
#endif
//--------------------------------------
#if defined PWM1_IO_V1
if (SINGLE_OUT == outputconfig)
{
TRISCbits.TRISC2 = 0;
}
else if (IS_DUAL_PWM(outputconfig))
{
TRISCbits.TRISC2 = 0;
TRISDbits.TRISD5 = 0;
}
else if (IS_QUAD_PWM(outputconfig))
{
TRISCbits.TRISC2 = 0;
TRISDbits.TRISD5 = 0;
TRISDbits.TRISD6 = 0;
TRISDbits.TRISD7 = 0;
}
#elif defined PWM1_IO_V2
if (SINGLE_OUT == outputconfig)
{
TRISCbits.TRISC2 = 0;
}
else if (IS_DUAL_PWM(outputconfig))
{
TRISCbits.TRISC2 = 0;
TRISEbits.TRISE6 = 0;
}
else if (IS_QUAD_PWM(outputconfig))
{
TRISCbits.TRISC2 = 0;
TRISEbits.TRISE6 = 0;
TRISEbits.TRISE5 = 0;
TRISGbits.TRISG4 = 0;
}
#elif defined PWM1_IO_V3
if (SINGLE_OUT == outputconfig)
{
TRISCbits.TRISC2 = 0;
}
else if (IS_DUAL_PWM(outputconfig))
{
TRISCbits.TRISC2 = 0;
TRISDbits.TRISD0 = 0;
}
else if (IS_QUAD_PWM(outputconfig))
{
TRISCbits.TRISC2 = 0;
TRISDbits.TRISD0 = 0;
TRISEbits.TRISE5 = 0;
TRISGbits.TRISG4 = 0;
}
#elif defined PWM1_IO_V4
if (SINGLE_OUT == outputconfig)
{
TRISCbits.TRISC2 = 0;
}
else if (IS_DUAL_PWM(outputconfig))
{
TRISCbits.TRISC2 = 0;
if(eccpmx)
TRISEbits.TRISE6 = 0;
else
TRISHbits.TRISH7 = 0;
}
else if (IS_QUAD_PWM(outputconfig))
{
TRISCbits.TRISC2 = 0;
if(eccpmx) {TRISEbits.TRISE6 = 0;TRISEbits.TRISE5 = 0;}
else {TRISHbits.TRISH7 = 0;TRISHbits.TRISH6 = 0;}
TRISGbits.TRISG4 = 0;
}
#elif defined PWM1_IO_V6
if (SINGLE_OUT == outputconfig)
{
TRISCbits.TRISC5 = 0;
}
else if (IS_DUAL_PWM(outputconfig))
{
TRISCbits.TRISC5 = 0;
TRISCbits.TRISC4 = 0;
}
else if (IS_QUAD_PWM(outputconfig))
{
TRISCbits.TRISC5 = 0;
TRISCbits.TRISC4 = 0;
TRISCbits.TRISC3 = 0;
TRISCbits.TRISC2 = 0;
}
//---------------------------------------------
#endif
#ifndef _OMNI_CODE_
_asm
movff TBLPTR_U, TBLPTRU
movff TBLPTR_L, TBLPTRL
_endasm
#endif
}
#elif defined (PWM_V8)
void SetOutputPWM1(unsigned char outputconfig, unsigned char outputmode)
{
char eccpmx; /* will be set iff bit 1 of __CONFIG3H is set */
#ifndef _OMNI_CODE_
unsigned char TBLPTR_U, TBLPTR_L;
_asm
movff TBLPTRU, TBLPTR_U
movff TBLPTRL, TBLPTR_L
_endasm
#endif
/* set P1M1 and P1M0 */
outputconfig |= 0b00111111;
outputmode |= 0b11111100;
CCP1CON = (CCP1CON | 0b11000000) & outputconfig;
/* set CCP1M3, CCP1M2, CCP1M1, CCP1M0 */
CCP1CON = (CCP1CON | 0b00001111) & outputmode;
#if defined (PWM1_IO_V4)
if (((*(unsigned char far rom *)__CONFIG3H) & 0b00000010))
eccpmx=0xff;
else
eccpmx = 0;
#endif
//--------------------------------------
if (SINGLE_OUT == outputconfig)
{
TRISBbits.TRISB3 = 0;
}
else if (IS_DUAL_PWM(outputconfig))
{
TRISBbits.TRISB3 = 0;
TRISBbits.TRISB2 = 0;
}
else if (IS_QUAD_PWM(outputconfig))
{
TRISBbits.TRISB3 = 0;
TRISBbits.TRISB2 = 0;
TRISBbits.TRISB6 = 0;
TRISBbits.TRISB7 = 0;
}
#ifndef _OMNI_CODE_
_asm
movff TBLPTR_U, TBLPTRU
movff TBLPTR_L, TBLPTRL
_endasm
#endif
}
#elif defined (PWM_V13)
void SetOutputPWM1(unsigned char outputconfig, unsigned char outputmode)
{
/* set P1M1 and P1M0 */
outputconfig |= 0b00111111;
outputmode |= 0b11111100;
CCP1CON = (CCP1CON | 0b11000000) & outputconfig;
/* set CCP1M3, CCP1M2, CCP1M1, CCP1M0 */
CCP1CON = (CCP1CON | 0b00001111) & outputmode;
}
#endif