line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package VIC::PIC::P18F242; |
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.31'; |
5
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
6
|
1
|
|
|
1
|
|
3
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
extends 'VIC::PIC::Base'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# role CodeGen |
10
|
|
|
|
|
|
|
has type => (is => 'ro', default => 'p18f242'); |
11
|
|
|
|
|
|
|
has include => (is => 'ro', default => 'p18f242.inc'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#role Chip |
14
|
|
|
|
|
|
|
has f_osc => (is => 'ro', default => 4e6); # 4MHz internal oscillator |
15
|
|
|
|
|
|
|
has pcl_size => (is => 'ro', default => 21); # program counter (PCL) size |
16
|
|
|
|
|
|
|
has stack_size => (is => 'ro', default => 31); # 31 levels of 21-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 => 8192, # words |
22
|
|
|
|
|
|
|
SRAM => 768, |
23
|
|
|
|
|
|
|
EEPROM => 256, |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
}); |
26
|
|
|
|
|
|
|
has address => (is => 'ro', default => sub { |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
# high # low |
29
|
|
|
|
|
|
|
isr => [ 0x0008, 0x0018 ], |
30
|
|
|
|
|
|
|
reset => [ 0x0000 ], |
31
|
|
|
|
|
|
|
range => [ 0x0000, 0x3FFF ], |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
}); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has pin_counts => (is => 'ro', default => sub { { |
36
|
|
|
|
|
|
|
pdip => 28, ## PDIP or DIP ? |
37
|
|
|
|
|
|
|
soic => 28, |
38
|
|
|
|
|
|
|
total => 28, |
39
|
|
|
|
|
|
|
io => 22, |
40
|
|
|
|
|
|
|
}}); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has banks => (is => 'ro', default => sub { |
43
|
|
|
|
|
|
|
{ |
44
|
|
|
|
|
|
|
count => 16, |
45
|
|
|
|
|
|
|
size => 0x100, |
46
|
|
|
|
|
|
|
gpr => { |
47
|
|
|
|
|
|
|
0 => [ 0x000, 0x0FF], |
48
|
|
|
|
|
|
|
1 => [ 0x100, 0x1FF], |
49
|
|
|
|
|
|
|
2 => [ 0x200, 0x2FF], |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
# remapping of these addresses automatically done by chip |
52
|
|
|
|
|
|
|
common => [ [0x000, 0x07F], [0xF80, 0xFFF] ], |
53
|
|
|
|
|
|
|
remap => [], |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
}); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has registers => (is => 'ro', default => sub { |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
TOSU => [0xFFF], |
60
|
|
|
|
|
|
|
TOSH => [0xFFE], |
61
|
|
|
|
|
|
|
TOSL => [0xFFD], |
62
|
|
|
|
|
|
|
STKPTR => [0xFFC], |
63
|
|
|
|
|
|
|
PCLATU => [0xFFB], |
64
|
|
|
|
|
|
|
PCLATH => [0xFFA], |
65
|
|
|
|
|
|
|
PCL => [0xFF9], |
66
|
|
|
|
|
|
|
TBLPTRU => [0xFF8], |
67
|
|
|
|
|
|
|
TBLPTRH => [0xFF7], |
68
|
|
|
|
|
|
|
TBLPTRL => [0xFF6], |
69
|
|
|
|
|
|
|
TABLAT => [0xFF5], |
70
|
|
|
|
|
|
|
PRODH => [0xFF4], |
71
|
|
|
|
|
|
|
PRODL => [0xFF3], |
72
|
|
|
|
|
|
|
INTCON => [0xFF2], |
73
|
|
|
|
|
|
|
INTCON2 => [0xFF1], |
74
|
|
|
|
|
|
|
INTCON3 => [0xFF0], |
75
|
|
|
|
|
|
|
INDF0 => [0xFEF], |
76
|
|
|
|
|
|
|
POSTINC0 => [0xFEE], |
77
|
|
|
|
|
|
|
POSTDEC0 => [0xFED], |
78
|
|
|
|
|
|
|
PREINC0 => [0xFEC], |
79
|
|
|
|
|
|
|
PLUSW0 => [0xFEB], |
80
|
|
|
|
|
|
|
FSR0H => [0xFEA], |
81
|
|
|
|
|
|
|
FSR0L => [0xFE9], |
82
|
|
|
|
|
|
|
WREG => [0xFE8], |
83
|
|
|
|
|
|
|
INDF1 => [0xFE7], |
84
|
|
|
|
|
|
|
POSTINC1 => [0xFE6], |
85
|
|
|
|
|
|
|
POSTDEC1 => [0xFE5], |
86
|
|
|
|
|
|
|
PREINC1 => [0xFE4], |
87
|
|
|
|
|
|
|
PLUSW1 => [0xFE3], |
88
|
|
|
|
|
|
|
FSR1H => [0xFE2], |
89
|
|
|
|
|
|
|
FSR1L => [0xFE1], |
90
|
|
|
|
|
|
|
BSR => [0xFE0], |
91
|
|
|
|
|
|
|
INDF2 => [0xFDF], |
92
|
|
|
|
|
|
|
POSTINC2 => [0xFDE], |
93
|
|
|
|
|
|
|
POSTDEC2 => [0xFDD], |
94
|
|
|
|
|
|
|
PREINC2 => [0xFDC], |
95
|
|
|
|
|
|
|
PLUSW2 => [0xFDB], |
96
|
|
|
|
|
|
|
FSR2H => [0xFDA], |
97
|
|
|
|
|
|
|
FSR2L => [0xFD9], |
98
|
|
|
|
|
|
|
STATUS => [0xFD8], |
99
|
|
|
|
|
|
|
TMR0H => [0xFD7], |
100
|
|
|
|
|
|
|
TMR0L => [0xFD6], |
101
|
|
|
|
|
|
|
T0CON => [0xFD5], |
102
|
|
|
|
|
|
|
OSCCON => [0xFD3], |
103
|
|
|
|
|
|
|
LVDCON => [0xFD2], |
104
|
|
|
|
|
|
|
WDTCON => [0xFD1], |
105
|
|
|
|
|
|
|
RCON => [0xFD0], |
106
|
|
|
|
|
|
|
TMR1H => [0xFCF], |
107
|
|
|
|
|
|
|
TMR1L => [0xFCE], |
108
|
|
|
|
|
|
|
T1CON => [0xFCD], |
109
|
|
|
|
|
|
|
TMR2 => [0xFCC], |
110
|
|
|
|
|
|
|
PR2 => [0xFCB], |
111
|
|
|
|
|
|
|
T2CON => [0xFCA], |
112
|
|
|
|
|
|
|
SSPBUF => [0xFC9], |
113
|
|
|
|
|
|
|
SSPADD => [0xFC8], |
114
|
|
|
|
|
|
|
SSPSTAT => [0xFC7], |
115
|
|
|
|
|
|
|
SSPCON1 => [0xFC6], |
116
|
|
|
|
|
|
|
SSPCON2 => [0xFC5], |
117
|
|
|
|
|
|
|
ADRESH => [0xFC4], |
118
|
|
|
|
|
|
|
ADRESL => [0xFC3], |
119
|
|
|
|
|
|
|
ADCON0 => [0xFC2], |
120
|
|
|
|
|
|
|
ADCON1 => [0xFC1], |
121
|
|
|
|
|
|
|
CCPR1H => [0xFBF], |
122
|
|
|
|
|
|
|
CCPR1L => [0xFBE], |
123
|
|
|
|
|
|
|
CCP1CON => [0xFBD], |
124
|
|
|
|
|
|
|
CCPR2H => [0xFBC], |
125
|
|
|
|
|
|
|
CCPR2L => [0xFBB], |
126
|
|
|
|
|
|
|
CCP2CON => [0xFBA], |
127
|
|
|
|
|
|
|
TMR3H => [0xFB3], |
128
|
|
|
|
|
|
|
TMR3L => [0xFB2], |
129
|
|
|
|
|
|
|
T3CON => [0xFB1], |
130
|
|
|
|
|
|
|
SPBRG => [0xFAF], |
131
|
|
|
|
|
|
|
RCREG => [0xFAE], |
132
|
|
|
|
|
|
|
TXREG => [0xFAD], |
133
|
|
|
|
|
|
|
TXSTA => [0xFAC], |
134
|
|
|
|
|
|
|
RCSTA => [0xFAB], |
135
|
|
|
|
|
|
|
EEADR => [0xFA9], |
136
|
|
|
|
|
|
|
EEDATA => [0xFA8], |
137
|
|
|
|
|
|
|
EECON2 => [0xFA7], |
138
|
|
|
|
|
|
|
EECON1 => [0xFA6], |
139
|
|
|
|
|
|
|
IPR2 => [0xFA2], |
140
|
|
|
|
|
|
|
PIR2 => [0xFA1], |
141
|
|
|
|
|
|
|
PIE2 => [0xFA0], |
142
|
|
|
|
|
|
|
IPR1 => [0xF9F], |
143
|
|
|
|
|
|
|
PIR1 => [0xF9E], |
144
|
|
|
|
|
|
|
PIE1 => [0xF9D], |
145
|
|
|
|
|
|
|
TRISC => [0xF94], |
146
|
|
|
|
|
|
|
TRISB => [0xF93], |
147
|
|
|
|
|
|
|
TRISA => [0xF92], |
148
|
|
|
|
|
|
|
LATC => [0xF8B], |
149
|
|
|
|
|
|
|
LATB => [0xF8A], |
150
|
|
|
|
|
|
|
LATA => [0xF89], |
151
|
|
|
|
|
|
|
PORTC => [0xF82], |
152
|
|
|
|
|
|
|
PORTB => [0xF81], |
153
|
|
|
|
|
|
|
PORTA => [0xF80], |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
}); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
has pins => (is => 'ro', default => sub { |
158
|
|
|
|
|
|
|
my $h = |
159
|
|
|
|
|
|
|
{ |
160
|
|
|
|
|
|
|
1 => [qw(MCLR Vpp)], |
161
|
|
|
|
|
|
|
2 => [qw(RA0 AN0)], |
162
|
|
|
|
|
|
|
3 => [qw(RA1 AN1)], |
163
|
|
|
|
|
|
|
4 => [qw(RA2 AN2 Vref-)], |
164
|
|
|
|
|
|
|
5 => [qw(RA3 AN3 Vref+)], |
165
|
|
|
|
|
|
|
6 => [qw(RA4 T0CKI)], |
166
|
|
|
|
|
|
|
7 => [qw(RA5 AN4 SS LVDIN)], |
167
|
|
|
|
|
|
|
8 => [qw(Vss)], |
168
|
|
|
|
|
|
|
9 => [qw(OSC1 CLKI)], |
169
|
|
|
|
|
|
|
10 => [qw(OSC2 CLKO RA6)], |
170
|
|
|
|
|
|
|
11 => [qw(RC0 T1OSO T1CKI)], |
171
|
|
|
|
|
|
|
12 => [qw(RC1 T1OSI CCP2)], |
172
|
|
|
|
|
|
|
13 => [qw(RC2 CCP1)], |
173
|
|
|
|
|
|
|
14 => [qw(RC3 SCK SCL)], |
174
|
|
|
|
|
|
|
15 => [qw(RC4 SDI SDA)], |
175
|
|
|
|
|
|
|
16 => [qw(RC5 SDO)], |
176
|
|
|
|
|
|
|
17 => [qw(RC6 TX CK)], |
177
|
|
|
|
|
|
|
18 => [qw(RC7 RX DT)], |
178
|
|
|
|
|
|
|
19 => [qw(Vss)], |
179
|
|
|
|
|
|
|
20 => [qw(Vdd)], |
180
|
|
|
|
|
|
|
21 => [qw(RB0 INT0)], |
181
|
|
|
|
|
|
|
22 => [qw(RB1 INT1)], |
182
|
|
|
|
|
|
|
23 => [qw(RB2 INT2)], |
183
|
|
|
|
|
|
|
24 => [qw(RB3 CCP2)], |
184
|
|
|
|
|
|
|
25 => [qw(RB4)], |
185
|
|
|
|
|
|
|
26 => [qw(RB5 PGM)], |
186
|
|
|
|
|
|
|
27 => [qw(RB6 PGC)], |
187
|
|
|
|
|
|
|
28 => [qw(RB7 PGD)], |
188
|
|
|
|
|
|
|
}; |
189
|
|
|
|
|
|
|
foreach my $k (keys %$h) { |
190
|
|
|
|
|
|
|
my $v = $h->{$k}; |
191
|
|
|
|
|
|
|
foreach (@$v) { |
192
|
|
|
|
|
|
|
$h->{$_} = $k; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
return $h; |
196
|
|
|
|
|
|
|
}); |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
has clock_pins => (is => 'ro', default => sub { |
199
|
|
|
|
|
|
|
{ |
200
|
|
|
|
|
|
|
out => 'CLKO', |
201
|
|
|
|
|
|
|
in => 'CLKI', |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
}); |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
has oscillator_pins => (is => 'ro', default => sub { |
206
|
|
|
|
|
|
|
{ |
207
|
|
|
|
|
|
|
in => 'OSC1', |
208
|
|
|
|
|
|
|
out => 'OSC2', |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
}); |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
has program_pins => (is => 'ro', default => sub { |
213
|
|
|
|
|
|
|
{ |
214
|
|
|
|
|
|
|
clock => 'PGC', |
215
|
|
|
|
|
|
|
data => 'PGD', |
216
|
|
|
|
|
|
|
enable => 'PGM', |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
}); |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
has io_ports => (is => 'ro', default => sub { |
221
|
|
|
|
|
|
|
{ |
222
|
|
|
|
|
|
|
#port => tristate, |
223
|
|
|
|
|
|
|
PORTA => 'TRISA', |
224
|
|
|
|
|
|
|
PORTB => 'TRISB', |
225
|
|
|
|
|
|
|
PORTC => 'TRISC', |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
}); |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
has input_pins => (is => 'ro', default => sub { |
230
|
|
|
|
|
|
|
{ |
231
|
|
|
|
|
|
|
#I/O => [port, tristate, bit] |
232
|
|
|
|
|
|
|
RA0 => ['PORTA', 'TRISA', 0], |
233
|
|
|
|
|
|
|
RA1 => ['PORTA', 'TRISA', 1], |
234
|
|
|
|
|
|
|
RA2 => ['PORTA', 'TRISA', 2], |
235
|
|
|
|
|
|
|
RA3 => ['PORTA', 'TRISA', 3], # input only |
236
|
|
|
|
|
|
|
RA4 => ['PORTA', 'TRISA', 4], |
237
|
|
|
|
|
|
|
RA5 => ['PORTA', 'TRISA', 5], |
238
|
|
|
|
|
|
|
RB0 => ['PORTB', 'TRISB', 0], |
239
|
|
|
|
|
|
|
RB1 => ['PORTB', 'TRISB', 1], |
240
|
|
|
|
|
|
|
RB2 => ['PORTB', 'TRISB', 2], |
241
|
|
|
|
|
|
|
RB3 => ['PORTB', 'TRISB', 3], |
242
|
|
|
|
|
|
|
RB4 => ['PORTB', 'TRISB', 4], |
243
|
|
|
|
|
|
|
RB5 => ['PORTB', 'TRISB', 5], |
244
|
|
|
|
|
|
|
RB6 => ['PORTB', 'TRISB', 6], |
245
|
|
|
|
|
|
|
RB7 => ['PORTB', 'TRISB', 7], |
246
|
|
|
|
|
|
|
RC0 => ['PORTC', 'TRISC', 0], |
247
|
|
|
|
|
|
|
RC1 => ['PORTC', 'TRISC', 1], |
248
|
|
|
|
|
|
|
RC2 => ['PORTC', 'TRISC', 2], |
249
|
|
|
|
|
|
|
RC3 => ['PORTC', 'TRISC', 3], |
250
|
|
|
|
|
|
|
RC4 => ['PORTC', 'TRISC', 4], |
251
|
|
|
|
|
|
|
RC5 => ['PORTC', 'TRISC', 5], |
252
|
|
|
|
|
|
|
RC6 => ['PORTC', 'TRISC', 6], |
253
|
|
|
|
|
|
|
RC7 => ['PORTC', 'TRISC', 7], |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
}); |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
has output_pins => (is => 'ro', default => sub { |
258
|
|
|
|
|
|
|
{ |
259
|
|
|
|
|
|
|
#I/O => [port, tristate, bit] |
260
|
|
|
|
|
|
|
RA0 => ['PORTA', 'TRISA', 0], |
261
|
|
|
|
|
|
|
RA1 => ['PORTA', 'TRISA', 1], |
262
|
|
|
|
|
|
|
RA2 => ['PORTA', 'TRISA', 2], |
263
|
|
|
|
|
|
|
RA3 => ['PORTA', 'TRISA', 3], # input only |
264
|
|
|
|
|
|
|
RA4 => ['PORTA', 'TRISA', 4], |
265
|
|
|
|
|
|
|
RA5 => ['PORTA', 'TRISA', 5], |
266
|
|
|
|
|
|
|
RB0 => ['PORTB', 'TRISB', 0], |
267
|
|
|
|
|
|
|
RB1 => ['PORTB', 'TRISB', 1], |
268
|
|
|
|
|
|
|
RB2 => ['PORTB', 'TRISB', 2], |
269
|
|
|
|
|
|
|
RB3 => ['PORTB', 'TRISB', 3], |
270
|
|
|
|
|
|
|
RB4 => ['PORTB', 'TRISB', 4], |
271
|
|
|
|
|
|
|
RB5 => ['PORTB', 'TRISB', 5], |
272
|
|
|
|
|
|
|
RB6 => ['PORTB', 'TRISB', 6], |
273
|
|
|
|
|
|
|
RB7 => ['PORTB', 'TRISB', 7], |
274
|
|
|
|
|
|
|
RC0 => ['PORTC', 'TRISC', 0], |
275
|
|
|
|
|
|
|
RC1 => ['PORTC', 'TRISC', 1], |
276
|
|
|
|
|
|
|
RC2 => ['PORTC', 'TRISC', 2], |
277
|
|
|
|
|
|
|
RC3 => ['PORTC', 'TRISC', 3], |
278
|
|
|
|
|
|
|
RC4 => ['PORTC', 'TRISC', 4], |
279
|
|
|
|
|
|
|
RC5 => ['PORTC', 'TRISC', 5], |
280
|
|
|
|
|
|
|
RC6 => ['PORTC', 'TRISC', 6], |
281
|
|
|
|
|
|
|
RC7 => ['PORTC', 'TRISC', 7], |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
}); |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
has analog_pins => (is => 'ro', default => sub { |
286
|
|
|
|
|
|
|
{ |
287
|
|
|
|
|
|
|
# use ANSEL for pins AN0-AN7 and ANSELH for AN8-AN11 |
288
|
|
|
|
|
|
|
#pin => number, bit |
289
|
|
|
|
|
|
|
AN0 => [2, 0], |
290
|
|
|
|
|
|
|
AN1 => [3, 1], |
291
|
|
|
|
|
|
|
AN2 => [4, 2], |
292
|
|
|
|
|
|
|
AN3 => [5, 3], |
293
|
|
|
|
|
|
|
AN4 => [7, 4], |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
}); |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
has adc_channels => (is => 'ro', default => 5); |
298
|
|
|
|
|
|
|
has adcs_bits => (is => 'ro', default => sub { |
299
|
|
|
|
|
|
|
{ |
300
|
|
|
|
|
|
|
2 => '000', |
301
|
|
|
|
|
|
|
4 => '100', |
302
|
|
|
|
|
|
|
8 => '001', |
303
|
|
|
|
|
|
|
16 => '101', |
304
|
|
|
|
|
|
|
32 => '010', |
305
|
|
|
|
|
|
|
64 => '110', |
306
|
|
|
|
|
|
|
internal => '111', |
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
}); |
309
|
|
|
|
|
|
|
has adc_chs_bits => (is => 'ro', default => sub { |
310
|
|
|
|
|
|
|
{ |
311
|
|
|
|
|
|
|
#pin => chsbits |
312
|
|
|
|
|
|
|
AN0 => '0000', |
313
|
|
|
|
|
|
|
AN1 => '0001', |
314
|
|
|
|
|
|
|
AN2 => '0010', |
315
|
|
|
|
|
|
|
AN3 => '0011', |
316
|
|
|
|
|
|
|
AN4 => '0100', |
317
|
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
|
}); |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
has timer_prescaler => (is => 'ro', default => sub { |
321
|
|
|
|
|
|
|
{ |
322
|
|
|
|
|
|
|
2 => '000', |
323
|
|
|
|
|
|
|
4 => '001', |
324
|
|
|
|
|
|
|
8 => '010', |
325
|
|
|
|
|
|
|
16 => '011', |
326
|
|
|
|
|
|
|
32 => '100', |
327
|
|
|
|
|
|
|
64 => '101', |
328
|
|
|
|
|
|
|
128 => '110', |
329
|
|
|
|
|
|
|
256 => '111', |
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
}); |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
has wdt_prescaler => (is => 'ro', default => sub { |
334
|
|
|
|
|
|
|
{ |
335
|
|
|
|
|
|
|
1 => '000', |
336
|
|
|
|
|
|
|
2 => '001', |
337
|
|
|
|
|
|
|
4 => '010', |
338
|
|
|
|
|
|
|
8 => '011', |
339
|
|
|
|
|
|
|
16 => '100', |
340
|
|
|
|
|
|
|
32 => '101', |
341
|
|
|
|
|
|
|
64 => '110', |
342
|
|
|
|
|
|
|
128 => '111', |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
}); |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
has timer_pins => (is => 'ro', default => sub { |
347
|
|
|
|
|
|
|
{ |
348
|
|
|
|
|
|
|
TMR0 => { reg => 'TMR0', freg => 'INTCON', flag => 'TMR0IF', enable => 'TMR0IE', ereg => 'INTCON' }, |
349
|
|
|
|
|
|
|
TMR1 => { reg => ['TMR1H', 'TMR1L'], freg => 'PIR1', ereg => 'PIE1', flag => 'TMR1IF', enable => 'TMR1E' }, |
350
|
|
|
|
|
|
|
TMR2 => { reg => 'TMR2', freg => 'PIR1', flag => 'TMR2IF', enable => 'TMR2IE', ereg => 'PIE1' }, |
351
|
|
|
|
|
|
|
TMR3 => { reg => ['TMR3H', 'TMR3L'], freg => 'PIR2', ereg => 'PIE2', flag => 'TMR3IF', enable => 'TMR3E' }, |
352
|
|
|
|
|
|
|
T0CKI => 6, |
353
|
|
|
|
|
|
|
T1OSO => 11, |
354
|
|
|
|
|
|
|
T1CKI => 11, |
355
|
|
|
|
|
|
|
T1OSI => 12, |
356
|
|
|
|
|
|
|
} |
357
|
|
|
|
|
|
|
}); |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
has ccp_pins => (is => 'ro', default => sub { |
360
|
|
|
|
|
|
|
{ |
361
|
|
|
|
|
|
|
# multiple pins for multiplexing |
362
|
|
|
|
|
|
|
CCP2 => [12, 24], |
363
|
|
|
|
|
|
|
CCP1 => 13, |
364
|
|
|
|
|
|
|
} |
365
|
|
|
|
|
|
|
}); |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
#external interrupt |
368
|
|
|
|
|
|
|
has eint_pins => (is => 'ro', default => sub { |
369
|
|
|
|
|
|
|
{ |
370
|
|
|
|
|
|
|
INT0 => 21, |
371
|
|
|
|
|
|
|
INT1 => 22, |
372
|
|
|
|
|
|
|
INT2 => 23, |
373
|
|
|
|
|
|
|
} |
374
|
|
|
|
|
|
|
}); |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
has ioc_pins => (is => 'ro', default => sub { |
377
|
|
|
|
|
|
|
{ |
378
|
|
|
|
|
|
|
RB4 => [25], |
379
|
|
|
|
|
|
|
RB5 => [26], |
380
|
|
|
|
|
|
|
RB6 => [27], |
381
|
|
|
|
|
|
|
RB7 => [28], |
382
|
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
}); |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
has ioc_ports => (is => 'ro', default => sub { |
386
|
|
|
|
|
|
|
{ |
387
|
|
|
|
|
|
|
FLAG => 'RBIF', |
388
|
|
|
|
|
|
|
ENABLE => 'RBIE', |
389
|
|
|
|
|
|
|
} |
390
|
|
|
|
|
|
|
}); |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
has usart_pins => (is => 'ro', default => sub { |
393
|
|
|
|
|
|
|
{ |
394
|
|
|
|
|
|
|
async_in => 'RX', |
395
|
|
|
|
|
|
|
async_out => 'TX', |
396
|
|
|
|
|
|
|
sync_clock => 'CK', |
397
|
|
|
|
|
|
|
sync_data => 'DT', |
398
|
|
|
|
|
|
|
#TODO |
399
|
|
|
|
|
|
|
rx_int => {}, |
400
|
|
|
|
|
|
|
tx_int => {}, |
401
|
|
|
|
|
|
|
# this defines the port names that the user can use |
402
|
|
|
|
|
|
|
# validly. The port names define whether the user wants to use them in |
403
|
|
|
|
|
|
|
# synchronous or asynchronous mode |
404
|
|
|
|
|
|
|
UART => 'async', |
405
|
|
|
|
|
|
|
USART => 'sync', |
406
|
|
|
|
|
|
|
} |
407
|
|
|
|
|
|
|
}); |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
0
|
0
|
|
sub usart_baudrates {} |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
has selector_pins => (is => 'ro', default => sub { |
412
|
|
|
|
|
|
|
{ |
413
|
|
|
|
|
|
|
'spi_or_i2c' => 'SS', |
414
|
|
|
|
|
|
|
} |
415
|
|
|
|
|
|
|
}); |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
has spi_pins => (is => 'ro', default => sub { |
418
|
|
|
|
|
|
|
{ |
419
|
|
|
|
|
|
|
data_out => 'SDO', |
420
|
|
|
|
|
|
|
data_in => 'SDI', |
421
|
|
|
|
|
|
|
clock => 'SCK', |
422
|
|
|
|
|
|
|
} |
423
|
|
|
|
|
|
|
}); |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
has i2c_pins => (is => 'ro', default => sub { |
426
|
|
|
|
|
|
|
{ |
427
|
|
|
|
|
|
|
data => 'SDA', |
428
|
|
|
|
|
|
|
clock => 'SCL', |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
}); |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
my @rolenames = qw(CodeGen Operators Chip GPIO ADC ISR Timer Operations CCP |
433
|
|
|
|
|
|
|
USART SPI I2C); |
434
|
|
|
|
|
|
|
my @roles = map (("VIC::PIC::Roles::$_", "VIC::PIC::Functions::$_"), @rolenames); |
435
|
|
|
|
|
|
|
with @roles; |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
sub list_roles { |
438
|
2
|
|
|
2
|
0
|
3268
|
my @arr = grep {!/CodeGen|Oper|Chip|ISR/} @rolenames; |
|
24
|
|
|
|
|
68
|
|
439
|
2
|
50
|
|
|
|
12
|
return wantarray ? @arr : [@arr]; |
440
|
|
|
|
|
|
|
} |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
1; |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
=encoding utf8 |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
=head1 NAME |
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
VIC::PIC::P18F242 |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
=head1 SYNOPSIS |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
A class that describes the code to be generated for each specific |
453
|
|
|
|
|
|
|
microcontroller that maps the VIC syntax back into assembly. This is the |
454
|
|
|
|
|
|
|
back-end to VIC's front-end. |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
=head1 DESCRIPTION |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
INTERNAL CLASS. |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
=head1 AUTHOR |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
Vikas N Kumar |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
=head1 COPYRIGHT |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
Copyright (c) 2014. Vikas N Kumar |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
469
|
|
|
|
|
|
|
under the same terms as Perl itself. |
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
See http://www.perl.com/perl/misc/Artistic.html |
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
=cut |