line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package VIC::PIC::P16F631; |
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.29'; |
5
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
6
|
1
|
|
|
1
|
|
4
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
extends 'VIC::PIC::Base'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# role CodeGen |
10
|
|
|
|
|
|
|
has type => (is => 'ro', default => 'p16f631'); |
11
|
|
|
|
|
|
|
has include => (is => 'ro', default => 'p16f631.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 => 1024, # words |
22
|
|
|
|
|
|
|
SRAM => 64, |
23
|
|
|
|
|
|
|
EEPROM => 128, |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
}); |
26
|
|
|
|
|
|
|
has address => (is => 'ro', default => sub { |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
isr => [ 0x0004 ], |
29
|
|
|
|
|
|
|
reset => [ 0x0000 ], |
30
|
|
|
|
|
|
|
range => [ 0x0000, 0x03FF ], |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
}); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has pin_counts => (is => 'ro', default => sub { { |
35
|
|
|
|
|
|
|
pdip => 20, ## PDIP or DIP ? |
36
|
|
|
|
|
|
|
soic => 20, |
37
|
|
|
|
|
|
|
ssop => 20, |
38
|
|
|
|
|
|
|
total => 20, |
39
|
|
|
|
|
|
|
io => 18, |
40
|
|
|
|
|
|
|
}}); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has banks => (is => 'ro', default => sub { |
43
|
|
|
|
|
|
|
{ |
44
|
|
|
|
|
|
|
count => 4, |
45
|
|
|
|
|
|
|
size => 0x80, |
46
|
|
|
|
|
|
|
gpr => { |
47
|
|
|
|
|
|
|
0 => [ 0x040, 0x07F], |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
# remapping of these addresses automatically done by chip |
50
|
|
|
|
|
|
|
common => [0x070, 0x07F], |
51
|
|
|
|
|
|
|
remap => [ |
52
|
|
|
|
|
|
|
[0x0F0, 0x0FF], |
53
|
|
|
|
|
|
|
[0x170, 0x17F], |
54
|
|
|
|
|
|
|
[0x1F0, 0x1FF], |
55
|
|
|
|
|
|
|
], |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
}); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
has registers => (is => 'ro', default => sub { |
60
|
|
|
|
|
|
|
{ |
61
|
|
|
|
|
|
|
INDF => [0x000, 0x080, 0x100, 0x180], # indirect addressing |
62
|
|
|
|
|
|
|
TMR0 => [0x001, 0x101], |
63
|
|
|
|
|
|
|
OPTION_REG => [0x081, 0x181], |
64
|
|
|
|
|
|
|
PCL => [0x002, 0x082, 0x102, 0x182], |
65
|
|
|
|
|
|
|
STATUS => [0x003, 0x083, 0x103, 0x183], |
66
|
|
|
|
|
|
|
FSR => [0x004, 0x084, 0x104, 0x184], |
67
|
|
|
|
|
|
|
PORTA => [0x005, 0x105], |
68
|
|
|
|
|
|
|
TRISA => [0x085, 0x185], |
69
|
|
|
|
|
|
|
PORTB => [0x006, 0x106], |
70
|
|
|
|
|
|
|
TRISB => [0x086, 0x186], |
71
|
|
|
|
|
|
|
PORTC => [0x007, 0x107], |
72
|
|
|
|
|
|
|
TRISC => [0x087, 0x187], |
73
|
|
|
|
|
|
|
PCLATH => [0x00A, 0x08A, 0x10A, 0x18A], |
74
|
|
|
|
|
|
|
INTCON => [0x00B, 0x08B, 0x10B, 0x18B], |
75
|
|
|
|
|
|
|
PIR1 => [0x00C], |
76
|
|
|
|
|
|
|
PIE1 => [0x08C], |
77
|
|
|
|
|
|
|
EEDAT => [0x10C], |
78
|
|
|
|
|
|
|
EECON1 => [0x18C], |
79
|
|
|
|
|
|
|
PIR2 => [0x00D], |
80
|
|
|
|
|
|
|
PIE2 => [0x08D], |
81
|
|
|
|
|
|
|
EEADR => [0x10D], |
82
|
|
|
|
|
|
|
EECON2 => [0x18D], # not addressable apparently |
83
|
|
|
|
|
|
|
TMR1L => [0x00E], |
84
|
|
|
|
|
|
|
PCON => [0x08E], |
85
|
|
|
|
|
|
|
TMR1H => [0x00F], |
86
|
|
|
|
|
|
|
OSCCON => [0x08F], |
87
|
|
|
|
|
|
|
T1CON => [0x010], |
88
|
|
|
|
|
|
|
OSCTUNE => [0x090], |
89
|
|
|
|
|
|
|
WPUA => [0x095], |
90
|
|
|
|
|
|
|
WPUB => [0x115], |
91
|
|
|
|
|
|
|
IOCA => [0x096], |
92
|
|
|
|
|
|
|
IOCB => [0x116], |
93
|
|
|
|
|
|
|
WDTCON => [0x097], |
94
|
|
|
|
|
|
|
VRCON => [0x118], |
95
|
|
|
|
|
|
|
CM1CON0 => [0x119], |
96
|
|
|
|
|
|
|
CM2CON0 => [0x11A], |
97
|
|
|
|
|
|
|
CM2CON1 => [0x11B], |
98
|
|
|
|
|
|
|
ANSEL => [0x11E], |
99
|
|
|
|
|
|
|
SRCON => [0x19E], |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
}); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
has pins => (is => 'ro', default => sub { |
104
|
|
|
|
|
|
|
my $h = { |
105
|
|
|
|
|
|
|
# number to pin name and pin name to number |
106
|
|
|
|
|
|
|
1 => [qw(Vdd)], |
107
|
|
|
|
|
|
|
2 => [qw(RA5 T1CKI OSC1 CLKIN)], |
108
|
|
|
|
|
|
|
3 => [qw(RA4 T1G OSC2 CLKOUT)], |
109
|
|
|
|
|
|
|
4 => [qw(RA3 MCLR Vpp)], |
110
|
|
|
|
|
|
|
5 => [qw(RC5)], |
111
|
|
|
|
|
|
|
6 => [qw(RC4 C2OUT)], |
112
|
|
|
|
|
|
|
7 => [qw(RC3 C12IN3-)], |
113
|
|
|
|
|
|
|
8 => [qw(RC6)], |
114
|
|
|
|
|
|
|
9 => [qw(RC7)], |
115
|
|
|
|
|
|
|
10 => [qw(RB7)], |
116
|
|
|
|
|
|
|
11 => [qw(RB6)], |
117
|
|
|
|
|
|
|
12 => [qw(RB5)], |
118
|
|
|
|
|
|
|
13 => [qw(RB4)], |
119
|
|
|
|
|
|
|
14 => [qw(RC2 C12IN2-)], |
120
|
|
|
|
|
|
|
15 => [qw(RC1 C12IN1-)], |
121
|
|
|
|
|
|
|
16 => [qw(RC0 C2IN+)], |
122
|
|
|
|
|
|
|
17 => [qw(RA2 T0CKI INT C1OUT)], |
123
|
|
|
|
|
|
|
18 => [qw(RA1 C12IN0- ICSPCLK)], |
124
|
|
|
|
|
|
|
19 => [qw(RA0 C1N+ ICSPDAT ULPWU)], |
125
|
|
|
|
|
|
|
20 => [qw(Vss)], |
126
|
|
|
|
|
|
|
}; |
127
|
|
|
|
|
|
|
foreach my $k (keys %$h) { |
128
|
|
|
|
|
|
|
my $v = $h->{$k}; |
129
|
|
|
|
|
|
|
foreach (@$v) { |
130
|
|
|
|
|
|
|
$h->{$_} = $k; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
return $h; |
134
|
|
|
|
|
|
|
}); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
has clock_pins => (is => 'ro', default => sub { |
137
|
|
|
|
|
|
|
{ |
138
|
|
|
|
|
|
|
out => 'CLKOUT', |
139
|
|
|
|
|
|
|
in => 'CLKIN', |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
}); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
has oscillator_pins => (is => 'ro', default => sub { |
144
|
|
|
|
|
|
|
{ |
145
|
|
|
|
|
|
|
1 => 'OSC1', |
146
|
|
|
|
|
|
|
2 => 'OSC2', |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
}); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
has program_pins => (is => 'ro', default => sub { |
151
|
|
|
|
|
|
|
{ |
152
|
|
|
|
|
|
|
clock => 'ICSPCLK', |
153
|
|
|
|
|
|
|
data => 'ICSPDAT', |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
}); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
has io_ports => (is => 'ro', default => sub { |
158
|
|
|
|
|
|
|
{ |
159
|
|
|
|
|
|
|
#port => tristate, |
160
|
|
|
|
|
|
|
PORTA => 'TRISA', |
161
|
|
|
|
|
|
|
PORTB => 'TRISB', |
162
|
|
|
|
|
|
|
PORTC => 'TRISC', |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
}); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
has input_pins => (is => 'ro', default => sub { |
167
|
|
|
|
|
|
|
{ |
168
|
|
|
|
|
|
|
#I/O => [port, tristate, bit] |
169
|
|
|
|
|
|
|
RA0 => ['PORTA', 'TRISA', 0], |
170
|
|
|
|
|
|
|
RA1 => ['PORTA', 'TRISA', 1], |
171
|
|
|
|
|
|
|
RA2 => ['PORTA', 'TRISA', 2], |
172
|
|
|
|
|
|
|
RA3 => ['PORTA', 'TRISA', 3], # input only |
173
|
|
|
|
|
|
|
RA4 => ['PORTA', 'TRISA', 4], |
174
|
|
|
|
|
|
|
RA5 => ['PORTA', 'TRISA', 5], |
175
|
|
|
|
|
|
|
RB4 => ['PORTB', 'TRISB', 4], |
176
|
|
|
|
|
|
|
RB5 => ['PORTB', 'TRISB', 5], |
177
|
|
|
|
|
|
|
RB6 => ['PORTB', 'TRISB', 6], |
178
|
|
|
|
|
|
|
RB7 => ['PORTB', 'TRISB', 7], |
179
|
|
|
|
|
|
|
RC0 => ['PORTC', 'TRISC', 0], |
180
|
|
|
|
|
|
|
RC1 => ['PORTC', 'TRISC', 1], |
181
|
|
|
|
|
|
|
RC2 => ['PORTC', 'TRISC', 2], |
182
|
|
|
|
|
|
|
RC3 => ['PORTC', 'TRISC', 3], |
183
|
|
|
|
|
|
|
RC4 => ['PORTC', 'TRISC', 4], |
184
|
|
|
|
|
|
|
RC5 => ['PORTC', 'TRISC', 5], |
185
|
|
|
|
|
|
|
RC6 => ['PORTC', 'TRISC', 6], |
186
|
|
|
|
|
|
|
RC7 => ['PORTC', 'TRISC', 7], |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
}); |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
has output_pins => (is => 'ro', default => sub { |
191
|
|
|
|
|
|
|
{ |
192
|
|
|
|
|
|
|
#I/O => [port, tristate, bit] |
193
|
|
|
|
|
|
|
RA0 => ['PORTA', 'TRISA', 0], |
194
|
|
|
|
|
|
|
RA1 => ['PORTA', 'TRISA', 1], |
195
|
|
|
|
|
|
|
RA2 => ['PORTA', 'TRISA', 2], |
196
|
|
|
|
|
|
|
RA4 => ['PORTA', 'TRISA', 4], |
197
|
|
|
|
|
|
|
RA5 => ['PORTA', 'TRISA', 5], |
198
|
|
|
|
|
|
|
RB4 => ['PORTB', 'TRISB', 4], |
199
|
|
|
|
|
|
|
RB5 => ['PORTB', 'TRISB', 5], |
200
|
|
|
|
|
|
|
RB6 => ['PORTB', 'TRISB', 6], |
201
|
|
|
|
|
|
|
RB7 => ['PORTB', 'TRISB', 7], |
202
|
|
|
|
|
|
|
RC0 => ['PORTC', 'TRISC', 0], |
203
|
|
|
|
|
|
|
RC1 => ['PORTC', 'TRISC', 1], |
204
|
|
|
|
|
|
|
RC2 => ['PORTC', 'TRISC', 2], |
205
|
|
|
|
|
|
|
RC3 => ['PORTC', 'TRISC', 3], |
206
|
|
|
|
|
|
|
RC4 => ['PORTC', 'TRISC', 4], |
207
|
|
|
|
|
|
|
RC5 => ['PORTC', 'TRISC', 5], |
208
|
|
|
|
|
|
|
RC6 => ['PORTC', 'TRISC', 6], |
209
|
|
|
|
|
|
|
RC7 => ['PORTC', 'TRISC', 7], |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
}); |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
has analog_pins => (is => 'ro', default => sub { {} }); |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
has timer_prescaler => (is => 'ro', default => sub { |
216
|
|
|
|
|
|
|
{ |
217
|
|
|
|
|
|
|
2 => '000', |
218
|
|
|
|
|
|
|
4 => '001', |
219
|
|
|
|
|
|
|
8 => '010', |
220
|
|
|
|
|
|
|
16 => '011', |
221
|
|
|
|
|
|
|
32 => '100', |
222
|
|
|
|
|
|
|
64 => '101', |
223
|
|
|
|
|
|
|
128 => '110', |
224
|
|
|
|
|
|
|
256 => '111', |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
}); |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
has wdt_prescaler => (is => 'ro', default => sub { |
229
|
|
|
|
|
|
|
{ |
230
|
|
|
|
|
|
|
1 => '000', |
231
|
|
|
|
|
|
|
2 => '001', |
232
|
|
|
|
|
|
|
4 => '010', |
233
|
|
|
|
|
|
|
8 => '011', |
234
|
|
|
|
|
|
|
16 => '100', |
235
|
|
|
|
|
|
|
32 => '101', |
236
|
|
|
|
|
|
|
64 => '110', |
237
|
|
|
|
|
|
|
128 => '111', |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
}); |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
has timer_pins => (is => 'ro', default => sub { |
242
|
|
|
|
|
|
|
{ |
243
|
|
|
|
|
|
|
#reg #reg #ireg #flag #enable |
244
|
|
|
|
|
|
|
TMR0 => { reg => 'TMR0', freg => 'INTCON', flag => 'T0IF', enable => 'T0IE', ereg => 'INTCON' }, |
245
|
|
|
|
|
|
|
TMR1 => { reg => ['TMR1H', 'TMR1L'], freg => 'PIR1', ereg => 'PIE1', flag => 'TMR1IF', enable => 'TMR1E' }, |
246
|
|
|
|
|
|
|
T0CKI => 17, |
247
|
|
|
|
|
|
|
T1CKI => 2, |
248
|
|
|
|
|
|
|
T1G => 3, |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
}); |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
#external interrupt |
253
|
|
|
|
|
|
|
has eint_pins => (is => 'ro', default => sub { |
254
|
|
|
|
|
|
|
{ |
255
|
|
|
|
|
|
|
INT => 17, |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
}); |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
has ioc_pins => (is => 'ro', default => sub { |
260
|
|
|
|
|
|
|
{ |
261
|
|
|
|
|
|
|
#pin, #ioc-bit #ioc-reg |
262
|
|
|
|
|
|
|
RA0 => [19, 'IOCA0', 'IOCA'], |
263
|
|
|
|
|
|
|
RA1 => [18, 'IOCA1', 'IOCA'], |
264
|
|
|
|
|
|
|
RA2 => [17, 'IOCA2', 'IOCA'], |
265
|
|
|
|
|
|
|
RA3 => [4, 'IOCA3', 'IOCA'], |
266
|
|
|
|
|
|
|
RA4 => [3, 'IOCA4', 'IOCA'], |
267
|
|
|
|
|
|
|
RA5 => [2, 'IOCA5', 'IOCA'], |
268
|
|
|
|
|
|
|
RB4 => [13, 'IOCB4', 'IOCB'], |
269
|
|
|
|
|
|
|
RB5 => [12, 'IOCB5', 'IOCB'], |
270
|
|
|
|
|
|
|
RB6 => [11, 'IOCB6', 'IOCB'], |
271
|
|
|
|
|
|
|
RB7 => [10, 'IOCB7', 'IOCB'], |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
}); |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
has ioc_ports => (is => 'ro', default => sub { |
276
|
|
|
|
|
|
|
{ |
277
|
|
|
|
|
|
|
PORTA => 'IOCA', |
278
|
|
|
|
|
|
|
PORTB => 'IOCB', |
279
|
|
|
|
|
|
|
FLAG => 'RABIF', |
280
|
|
|
|
|
|
|
ENABLE => 'RABIE', |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
}); |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
has cmp_input_pins => (is => 'ro', default => sub { |
285
|
|
|
|
|
|
|
{ |
286
|
|
|
|
|
|
|
'C1IN+' => 'C1IN+', |
287
|
|
|
|
|
|
|
'C12IN0-' => 'C12IN0-', |
288
|
|
|
|
|
|
|
'C2IN+' => 'C2IN+', |
289
|
|
|
|
|
|
|
'C12IN1-' => 'C12IN1-', |
290
|
|
|
|
|
|
|
'C12IN2-' => 'C12IN2-', |
291
|
|
|
|
|
|
|
'C12IN3-' => 'C12IN3-', |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
}); |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
has cmp_output_pins => (is => 'ro', default => sub { |
296
|
|
|
|
|
|
|
{ |
297
|
|
|
|
|
|
|
C1OUT => 'C1OUT', |
298
|
|
|
|
|
|
|
C2OUT => 'C2OUT', |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
}); |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
my @rolenames = qw(CodeGen Operators Chip GPIO ISR Timer Operations Comparator); |
303
|
|
|
|
|
|
|
my @roles = map (("VIC::PIC::Roles::$_", "VIC::PIC::Functions::$_"), @rolenames); |
304
|
|
|
|
|
|
|
with @roles; |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
sub list_roles { |
307
|
1
|
|
|
1
|
0
|
799
|
my @arr = grep {!/CodeGen|Oper|Chip|ISR/} @rolenames; |
|
8
|
|
|
|
|
20
|
|
308
|
1
|
50
|
|
|
|
10
|
return wantarray ? @arr : [@arr]; |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
1; |
312
|
|
|
|
|
|
|
__END__ |