line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package VIC::PIC::P12F683; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.32'; |
5
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
6
|
1
|
|
|
1
|
|
551
|
use Moo; |
|
1
|
|
|
|
|
9600
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
extends 'VIC::PIC::Base'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# role CodeGen |
10
|
|
|
|
|
|
|
has type => (is => 'ro', default => 'p12f683'); |
11
|
|
|
|
|
|
|
has include => (is => 'ro', default => 'p12f683.inc'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#role Chip |
14
|
|
|
|
|
|
|
has f_osc => (is => 'ro', default => 4e6); # 4MHz internal oscillator |
15
|
|
|
|
|
|
|
has pcl_size => (is => 'ro', default => 13); # program counter (PCL) size |
16
|
|
|
|
|
|
|
has stack_size => (is => 'ro', default => 8); # 8 levels of 13-bit entries |
17
|
|
|
|
|
|
|
has wreg_size => (is => 'ro', default => 8); # 8-bit register WREG |
18
|
|
|
|
|
|
|
# all memory is in bytes |
19
|
|
|
|
|
|
|
has memory => (is => 'ro', default => sub { |
20
|
|
|
|
|
|
|
{ |
21
|
|
|
|
|
|
|
flash => 2048, # words |
22
|
|
|
|
|
|
|
SGPM => 128, |
23
|
|
|
|
|
|
|
EEPROM => 256, |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
}); |
26
|
|
|
|
|
|
|
has address => (is => 'ro', default => sub { |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
isr => [ 0x0004 ], |
29
|
|
|
|
|
|
|
reset => [ 0x0000 ], |
30
|
|
|
|
|
|
|
range => [ 0x0000, 0x07FF ], |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
}); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has pin_counts => (is => 'ro', default => sub { { |
35
|
|
|
|
|
|
|
pdip => 8, ## PDIP or DIP ? |
36
|
|
|
|
|
|
|
soic => 8, |
37
|
|
|
|
|
|
|
dfn => 8, # like qfn but only 2 sides |
38
|
|
|
|
|
|
|
total => 8, |
39
|
|
|
|
|
|
|
io => 6, |
40
|
|
|
|
|
|
|
}}); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has banks => (is => 'ro', default => sub { |
43
|
|
|
|
|
|
|
{ |
44
|
|
|
|
|
|
|
count => 2, |
45
|
|
|
|
|
|
|
size => 0x80, |
46
|
|
|
|
|
|
|
gpr => { |
47
|
|
|
|
|
|
|
0 => [ 0x020, 0x07F], |
48
|
|
|
|
|
|
|
1 => [ 0x0A0, 0x0BF], |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
# remapping of these addresses automatically done by chip |
51
|
|
|
|
|
|
|
common => [0x070, 0x07F], |
52
|
|
|
|
|
|
|
remap => [ |
53
|
|
|
|
|
|
|
[0x0F0, 0x0FF], |
54
|
|
|
|
|
|
|
], |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
}); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
has registers => (is => 'ro', default => sub { |
59
|
|
|
|
|
|
|
{ |
60
|
|
|
|
|
|
|
INDF => [0x000, 0x080], # indirect addressing |
61
|
|
|
|
|
|
|
TMR0 => [0x001], |
62
|
|
|
|
|
|
|
OPTION_REG => [0x081], |
63
|
|
|
|
|
|
|
PCL => [0x002, 0x082], |
64
|
|
|
|
|
|
|
STATUS => [0x003, 0x083], |
65
|
|
|
|
|
|
|
FSR => [0x004, 0x084], |
66
|
|
|
|
|
|
|
GPIO => [0x005], |
67
|
|
|
|
|
|
|
TRISIO => [0x085], |
68
|
|
|
|
|
|
|
PCLATH => [0x00A, 0x08A], |
69
|
|
|
|
|
|
|
INTCON => [0x00B, 0x08B], |
70
|
|
|
|
|
|
|
PIR1 => [0x00C], |
71
|
|
|
|
|
|
|
PIE1 => [0x08C], |
72
|
|
|
|
|
|
|
TMR1L => [0x00E], |
73
|
|
|
|
|
|
|
PCON => [0x08E], |
74
|
|
|
|
|
|
|
TMR1H => [0x00F], |
75
|
|
|
|
|
|
|
OSCCON => [0x08F], |
76
|
|
|
|
|
|
|
T1CON => [0x010], |
77
|
|
|
|
|
|
|
OSCTUNE => [0x090], |
78
|
|
|
|
|
|
|
TMR2 => [0x011], |
79
|
|
|
|
|
|
|
T2CON => [0x012], |
80
|
|
|
|
|
|
|
PR2 => [0x092], |
81
|
|
|
|
|
|
|
CCPR1L => [0x013], |
82
|
|
|
|
|
|
|
CCPR1H => [0x014], |
83
|
|
|
|
|
|
|
CCP1CON => [0x015], |
84
|
|
|
|
|
|
|
WPU => [0x095], |
85
|
|
|
|
|
|
|
IOC => [0x096], |
86
|
|
|
|
|
|
|
WDTCON => [0x018], |
87
|
|
|
|
|
|
|
CMCON0 => [0x019], |
88
|
|
|
|
|
|
|
VRCON => [0x099], |
89
|
|
|
|
|
|
|
CMCON1 => [0x01A], |
90
|
|
|
|
|
|
|
EEDAT => [0x09A], |
91
|
|
|
|
|
|
|
EEADR => [0x09B], |
92
|
|
|
|
|
|
|
EECON1 => [0x09C], |
93
|
|
|
|
|
|
|
EECON2 => [0x09D], |
94
|
|
|
|
|
|
|
ADRESH => [0x01E], |
95
|
|
|
|
|
|
|
ADRESL => [0x09E], |
96
|
|
|
|
|
|
|
ADCON0 => [0x01F], |
97
|
|
|
|
|
|
|
ANSEL => [0x09F], |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
}); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
has pins => (is => 'ro', default => sub { |
102
|
|
|
|
|
|
|
my $h = { |
103
|
|
|
|
|
|
|
# number to pin name and pin name to number |
104
|
|
|
|
|
|
|
1 => [qw(Vdd)], |
105
|
|
|
|
|
|
|
2 => [qw(GP5 T1CKI OSC1 CLKIN)], |
106
|
|
|
|
|
|
|
3 => [qw(GP4 AN3 T1G OSC2 CLKOUT)], |
107
|
|
|
|
|
|
|
4 => [qw(GP3 MCLR Vpp)], |
108
|
|
|
|
|
|
|
5 => [qw(GP2 AN2 T0CKI INT COUT CCP1)], |
109
|
|
|
|
|
|
|
6 => [qw(GP1 AN1 CIN- Vref ICSPCLK)], |
110
|
|
|
|
|
|
|
7 => [qw(GP0 AN0 CIN+ ICSPDAT ULPWU)], |
111
|
|
|
|
|
|
|
8 => [qw(Vss)], |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
foreach my $k (keys %$h) { |
114
|
|
|
|
|
|
|
my $v = $h->{$k}; |
115
|
|
|
|
|
|
|
foreach (@$v) { |
116
|
|
|
|
|
|
|
$h->{$_} = $k; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
return $h; |
120
|
|
|
|
|
|
|
}); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
has clock_pins => (is => 'ro', default => sub { |
123
|
|
|
|
|
|
|
{ |
124
|
|
|
|
|
|
|
out => 'CLKOUT', |
125
|
|
|
|
|
|
|
in => 'CLKIN', |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
}); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
has oscillator_pins => (is => 'ro', default => sub { |
130
|
|
|
|
|
|
|
{ |
131
|
|
|
|
|
|
|
1 => 'OSC1', |
132
|
|
|
|
|
|
|
2 => 'OSC2', |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
}); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
has program_pins => (is => 'ro', default => sub { |
137
|
|
|
|
|
|
|
{ |
138
|
|
|
|
|
|
|
clock => 'ICSPCLK', |
139
|
|
|
|
|
|
|
data => 'ICSPDAT', |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
}); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
has io_ports => (is => 'ro', default => sub { |
144
|
|
|
|
|
|
|
{ |
145
|
|
|
|
|
|
|
#port => tristate, |
146
|
|
|
|
|
|
|
GPIO => 'TRISIO', |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
}); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
has input_pins => (is => 'ro', default => sub { |
151
|
|
|
|
|
|
|
{ |
152
|
|
|
|
|
|
|
#I/O => [port, tristate, bit] |
153
|
|
|
|
|
|
|
GP0 => ['GPIO', 'TRISIO', 0], |
154
|
|
|
|
|
|
|
GP1 => ['GPIO', 'TRISIO', 1], |
155
|
|
|
|
|
|
|
GP2 => ['GPIO', 'TRISIO', 2], |
156
|
|
|
|
|
|
|
GP3 => ['GPIO', 'TRISIO', 3], # input only |
157
|
|
|
|
|
|
|
GP4 => ['GPIO', 'TRISIO', 4], |
158
|
|
|
|
|
|
|
GP5 => ['GPIO', 'TRISIO', 5], |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
}); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
has output_pins => (is => 'ro', default => sub { |
163
|
|
|
|
|
|
|
{ |
164
|
|
|
|
|
|
|
#I/O => [port, tristate, bit] |
165
|
|
|
|
|
|
|
GP0 => ['GPIO', 'TRISIO', 0], |
166
|
|
|
|
|
|
|
GP1 => ['GPIO', 'TRISIO', 1], |
167
|
|
|
|
|
|
|
GP2 => ['GPIO', 'TRISIO', 2], |
168
|
|
|
|
|
|
|
GP4 => ['GPIO', 'TRISIO', 4], |
169
|
|
|
|
|
|
|
GP5 => ['GPIO', 'TRISIO', 5], |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
}); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
has analog_pins => (is => 'ro', default => sub { |
174
|
|
|
|
|
|
|
{ |
175
|
|
|
|
|
|
|
# use ANSEL for pins AN0-AN7 and ANSELH for AN8-AN11 |
176
|
|
|
|
|
|
|
#pin => number, bit |
177
|
|
|
|
|
|
|
AN0 => [7, 0], |
178
|
|
|
|
|
|
|
AN1 => [6, 1], |
179
|
|
|
|
|
|
|
AN2 => [5, 2], |
180
|
|
|
|
|
|
|
AN3 => [3, 3], |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
}); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
has adc_channels => (is => 'ro', default => 4); |
185
|
|
|
|
|
|
|
has adcs_bits => (is => 'ro', default => sub { |
186
|
|
|
|
|
|
|
{ |
187
|
|
|
|
|
|
|
2 => '000', |
188
|
|
|
|
|
|
|
4 => '100', |
189
|
|
|
|
|
|
|
8 => '001', |
190
|
|
|
|
|
|
|
16 => '101', |
191
|
|
|
|
|
|
|
32 => '010', |
192
|
|
|
|
|
|
|
64 => '110', |
193
|
|
|
|
|
|
|
internal => '111', |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
}); |
196
|
|
|
|
|
|
|
has adc_chs_bits => (is => 'ro', default => sub { |
197
|
|
|
|
|
|
|
{ |
198
|
|
|
|
|
|
|
#pin => chsbits |
199
|
|
|
|
|
|
|
AN0 => '0000', |
200
|
|
|
|
|
|
|
AN1 => '0001', |
201
|
|
|
|
|
|
|
AN2 => '0010', |
202
|
|
|
|
|
|
|
AN3 => '0011', |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
}); |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
has timer_prescaler => (is => 'ro', default => sub { |
207
|
|
|
|
|
|
|
{ |
208
|
|
|
|
|
|
|
2 => '000', |
209
|
|
|
|
|
|
|
4 => '001', |
210
|
|
|
|
|
|
|
8 => '010', |
211
|
|
|
|
|
|
|
16 => '011', |
212
|
|
|
|
|
|
|
32 => '100', |
213
|
|
|
|
|
|
|
64 => '101', |
214
|
|
|
|
|
|
|
128 => '110', |
215
|
|
|
|
|
|
|
256 => '111', |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
}); |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
has wdt_prescaler => (is => 'ro', default => sub { |
220
|
|
|
|
|
|
|
{ |
221
|
|
|
|
|
|
|
1 => '000', |
222
|
|
|
|
|
|
|
2 => '001', |
223
|
|
|
|
|
|
|
4 => '010', |
224
|
|
|
|
|
|
|
8 => '011', |
225
|
|
|
|
|
|
|
16 => '100', |
226
|
|
|
|
|
|
|
32 => '101', |
227
|
|
|
|
|
|
|
64 => '110', |
228
|
|
|
|
|
|
|
128 => '111', |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
}); |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
has timer_pins => (is => 'ro', default => sub { |
233
|
|
|
|
|
|
|
{ |
234
|
|
|
|
|
|
|
TMR0 => { reg => 'TMR0', flag => 'T0IF', enable => 'T0IE', freg => 'INTCON', ereg => 'INTCON' }, |
235
|
|
|
|
|
|
|
TMR1 => { reg => ['TMR1H', 'TMR1L'], freg => 'PIR1', ereg => 'PIE1', flag => 'TMR1IF', enable => 'TMR1E' }, |
236
|
|
|
|
|
|
|
TMR2 => { reg => 'TMR2', freg => 'PIR1', flag => 'TMR2IF', enable => 'TMR2IE', ereg => 'PIE1' }, |
237
|
|
|
|
|
|
|
T0CKI => 5, |
238
|
|
|
|
|
|
|
T1CKI => 2, |
239
|
|
|
|
|
|
|
T1G => 3, |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
}); |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
has ccp_pins => (is => 'ro', default => sub { |
244
|
|
|
|
|
|
|
{ |
245
|
|
|
|
|
|
|
CCP1 => 'CCP1', |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
}); |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
#external interrupt |
250
|
|
|
|
|
|
|
has eint_pins => (is => 'ro', default => sub { |
251
|
|
|
|
|
|
|
{ |
252
|
|
|
|
|
|
|
INT => 5, |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
}); |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
has ioc_pins => (is => 'ro', default => sub { |
257
|
|
|
|
|
|
|
{ |
258
|
|
|
|
|
|
|
GP0 => [7, 'IOC0', 'IOC'], |
259
|
|
|
|
|
|
|
GP1 => [6, 'IOC1', 'IOC'], |
260
|
|
|
|
|
|
|
GP2 => [5, 'IOC2', 'IOC'], |
261
|
|
|
|
|
|
|
GP3 => [4, 'IOC3', 'IOC'], |
262
|
|
|
|
|
|
|
GP4 => [3, 'IOC4', 'IOC'], |
263
|
|
|
|
|
|
|
GP5 => [2, 'IOC5', 'IOC'], |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
}); |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
has ioc_ports => (is => 'ro', default => sub { |
268
|
|
|
|
|
|
|
{ |
269
|
|
|
|
|
|
|
GPIO => 'IOC', |
270
|
|
|
|
|
|
|
FLAG => 'GPIF', |
271
|
|
|
|
|
|
|
ENABLE => 'GPIE', |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
}); |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
has cmp_input_pins => (is => 'ro', default => sub { |
276
|
|
|
|
|
|
|
{ |
277
|
|
|
|
|
|
|
'CIN+' => 'CIN+', |
278
|
|
|
|
|
|
|
'CIN-' => 'CIN-', |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
}); |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
has cmp_output_pins => (is => 'ro', default => sub { |
283
|
|
|
|
|
|
|
{ |
284
|
|
|
|
|
|
|
COUT => 'COUT', |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
}); |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
has chip_config => (is => 'ro', default => sub { |
289
|
|
|
|
|
|
|
{ |
290
|
|
|
|
|
|
|
on_off => { |
291
|
|
|
|
|
|
|
MCLRE => 0, |
292
|
|
|
|
|
|
|
WDT => 0, |
293
|
|
|
|
|
|
|
PWRTE => 0, |
294
|
|
|
|
|
|
|
CP => 0, |
295
|
|
|
|
|
|
|
BOREN => 0, |
296
|
|
|
|
|
|
|
IESO => 0, |
297
|
|
|
|
|
|
|
FCMEN => 0, |
298
|
|
|
|
|
|
|
}, |
299
|
|
|
|
|
|
|
f_osc => { |
300
|
|
|
|
|
|
|
INTRC_OSC => 0, |
301
|
|
|
|
|
|
|
}, |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
}); |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
my @rolenames = qw(CodeGen Operators Chip GPIO ADC ISR Timer Operations CCP Comparator); |
306
|
|
|
|
|
|
|
my @roles = map (("VIC::PIC::Roles::$_", "VIC::PIC::Functions::$_"), @rolenames); |
307
|
|
|
|
|
|
|
with @roles; |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
sub list_roles { |
310
|
1
|
|
|
1
|
0
|
1451
|
my @arr = grep {!/CodeGen|Oper|Chip|ISR/} @rolenames; |
|
10
|
|
|
|
|
28
|
|
311
|
1
|
50
|
|
|
|
4
|
return wantarray ? @arr : [@arr]; |
312
|
|
|
|
|
|
|
} |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
1; |
315
|
|
|
|
|
|
|
__END__ |