3
Copyright (C) 2010,2015 Roy R. Rankin
5
This file is part of the libgpsim library of gpsim
7
This library is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Lesser General Public
9
License as published by the Free Software Foundation; either
10
version 2.1 of the License, or (at your option) any later version.
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Lesser General Public License for more details.
17
You should have received a copy of the GNU Lesser General Public
18
License along with this library; if not, see
19
<http://www.gnu.org/licenses/lgpl-2.1.html>.
26
// This file supports:
40
#include "pic-ioports.h"
44
#define Dprintf(arg) {printf("%s:%d-%s() ",__FILE__,__LINE__, __FUNCTION__); printf arg; }
46
#define Dprintf(arg) {}
49
//========================================================================
51
// Configuration Memory for the 16F8X devices.
53
class Config188x : public ConfigWord
56
Config188x(P16F88x *pCpu)
57
: ConfigWord("CONFIG188x", 0x3fff, pCpu, 0x2007)
78
virtual void set(int64_t v)
81
Dprintf(("Config188x set %x\n", (int)v));
84
m_pCpu->wdt.initialize((v & WDTEN) == WDTEN);
90
//========================================================================
92
P16F88x::P16F88x(const char *_name)
93
: _14bit_processor(_name ),
94
intcon_reg(this,"intcon" ),
95
t1con(this, "t1con" ),
98
t2con(this, "t2con" ),
101
tmr1l(this, "tmr1l" ),
102
tmr1h(this, "tmr1h" ),
103
ccp1con(this, "ccp1con" ),
104
ccpr1l(this, "ccpr1l" ),
105
ccpr1h(this, "ccpr1h" ),
106
ccp2con(this, "ccp2con" ),
107
ccpr2l(this, "ccpr2l" ),
108
ccpr2h(this, "ccpr2h" ),
112
osctune(this, "osctune" ),
113
wdtcon(this, "wdtcon", 1),
116
vrcon(this, "vrcon" ),
117
srcon(this, "srcon" ),
118
ansel(this,"ansel" ),
119
anselh(this,"anselh" ),
120
adcon0(this,"adcon0" ),
121
adcon1(this,"adcon1" ),
122
eccpas(this, "eccpas" ),
123
pwm1con(this, "pwm1con" ),
124
pstrcon(this, "pstrcon" ),
125
adresh(this,"adresh" ),
126
adresl(this,"adresl" )
129
m_porta = new PicPortRegister(this,"porta", 8,0x1f);
130
m_trisa = new PicTrisRegister(this,"trisa", m_porta, false);
131
m_ioc = new IOC(this, "iocb" );
132
m_portb = new PicPortGRegister(this,"portb", &intcon_reg, m_ioc,8,0xff);
133
m_trisb = new PicTrisRegister(this,"trisb", m_portb, false);
134
m_portc = new PicPortRegister(this,"portc", 8,0xff);
135
m_trisc = new PicTrisRegister(this,"trisc", m_portc, false);
136
m_porte = new PicPortRegister(this,"porte", 8,0x0f);
137
m_trise = new PicPSP_TrisRegister(this,"trise", m_porte, false);
139
pir1_2_reg = new PIR1v2(this,"pir1", &intcon_reg,&pie1);
140
pir2_2_reg = new PIR2v3(this,"pir2", &intcon_reg,&pie2);
143
m_wpu = new WPU(this, "wpub", m_portb, 0xff);
145
tmr0.set_cpu(this, m_porta, 4, option_reg);
147
comparator.cmxcon0[0] = new CMxCON0_V2(this, "cm1con0", 0, &comparator);
148
comparator.cmxcon0[1] = new CMxCON0_V2(this, "cm2con0", 1, &comparator);
149
comparator.cmxcon1[0] = new CM2CON1_V3(this, "cm2con1", 0, &comparator);
150
comparator.cmxcon1[1] = comparator.cmxcon1[0];
156
delete_file_registers(0x20, 0x7f);
157
delete_file_registers(0xa0, 0xbf);
159
remove_SfrReg(&tmr0);
160
remove_SfrReg(&intcon_reg);
161
remove_SfrReg(&pie2);
162
remove_SfrReg(&pie1);
163
remove_SfrReg(&tmr1l);
164
remove_SfrReg(&tmr1h);
165
remove_SfrReg(&pcon);
166
remove_SfrReg(&t1con);
167
remove_SfrReg(&tmr2);
168
remove_SfrReg(&t2con);
170
remove_SfrReg(get_eeprom()->get_reg_eedata());
171
remove_SfrReg(get_eeprom()->get_reg_eeadr());
172
remove_SfrReg(get_eeprom()->get_reg_eedatah());
173
remove_SfrReg(get_eeprom()->get_reg_eeadrh());
174
remove_SfrReg(get_eeprom()->get_reg_eecon1());
175
remove_SfrReg(get_eeprom()->get_reg_eecon2());
178
remove_SfrReg(&intcon_reg);
179
remove_SfrReg(osccon);
180
remove_SfrReg(&osctune);
181
remove_SfrReg(&usart.rcsta);
182
remove_SfrReg(&usart.txsta);
183
remove_SfrReg(&usart.spbrg);
184
remove_SfrReg(&usart.spbrgh);
185
remove_SfrReg(&usart.baudcon);
186
remove_SfrReg(&vrcon);
187
remove_SfrReg(&srcon);
188
remove_SfrReg(&wdtcon);
189
remove_SfrReg(&ccpr2l);
190
remove_SfrReg(&ccpr2h);
191
remove_SfrReg(&ccp2con);
192
remove_SfrReg(&adresl);
193
remove_SfrReg(&adresh);
194
remove_SfrReg(&ansel);
195
remove_SfrReg(&anselh);
196
remove_SfrReg(&adcon0);
197
remove_SfrReg(&adcon1);
198
remove_SfrReg(&ccpr1l);
199
remove_SfrReg(&ccpr1h);
200
remove_SfrReg(&ccp1con);
201
remove_SfrReg(&ccpr2l);
202
remove_SfrReg(&ccpr2h);
203
remove_SfrReg(&ccp2con);
204
remove_SfrReg(&pwm1con);
205
remove_SfrReg(&pstrcon);
206
remove_SfrReg(&eccpas);
207
remove_SfrReg(&ssp.sspcon2);
208
remove_SfrReg(&ssp.sspbuf);
209
remove_SfrReg(&ssp.sspcon);
210
remove_SfrReg(&ssp.sspadd);
211
remove_SfrReg(&ssp.sspstat);
212
delete_SfrReg(usart.txreg);
213
delete_SfrReg(usart.rcreg);
214
remove_SfrReg(comparator.cmxcon0[0]);
215
remove_SfrReg(comparator.cmxcon0[1]);
216
remove_SfrReg(comparator.cmxcon1[1]);
218
delete_SfrReg(m_porta);
219
delete_SfrReg(m_trisa);
220
delete_SfrReg(m_portb);
221
delete_SfrReg(m_trisb);
222
delete_SfrReg(m_porte);
223
delete_SfrReg(m_trise);
224
delete_SfrReg(m_portc);
225
delete_SfrReg(m_trisc);
229
delete_SfrReg(m_wpu);
230
delete_SfrReg(m_ioc);
233
void P16F88x::create_iopin_map()
235
fprintf(stderr, "%s should be defined at a higer level\n", __FUNCTION__);
238
void P16F88x::create_sfr_map()
240
add_SfrReg(indf, 0x00);
241
alias_file_registers(0x00,0x00,0x80);
243
add_SfrReg(&tmr0, 0x01);
244
add_SfrReg(option_reg, 0x81, RegisterValue(0xff,0));
246
add_SfrReg(pcl, 0x02, RegisterValue(0,0));
247
add_SfrReg(status, 0x03, RegisterValue(0x18,0));
248
add_SfrReg(fsr, 0x04);
249
alias_file_registers(0x02,0x04,0x80);
251
add_SfrReg(m_porta, 0x05);
252
add_SfrReg(m_trisa, 0x85, RegisterValue(0x3f,0));
254
add_SfrReg(m_portb, 0x06);
255
add_SfrReg(m_trisb, 0x86, RegisterValue(0xff,0));
257
add_SfrReg(pclath, 0x0a, RegisterValue(0,0));
259
add_SfrReg(&intcon_reg, 0x0b, RegisterValue(0,0));
260
//alias_file_registers(0x0a,0x0b,0x80); //Already donw
262
intcon = &intcon_reg;
264
pir_set_2_def.set_pir1(pir1);
265
pir_set_2_def.set_pir2(pir2);
267
add_SfrReg(m_porte, 0x09);
268
add_SfrReg(m_trise, 0x89, RegisterValue(0xff,0));
269
add_SfrReg(m_portc, 0x07);
270
add_SfrReg(m_trisc, 0x87, RegisterValue(0xff,0));
272
add_file_registers(0x20, 0x7f, 0);
273
add_file_registers(0xa0, 0xbf, 0);
275
alias_file_registers(0x70,0x7f,0x80);
276
alias_file_registers(0x70,0x7f,0x100);
277
alias_file_registers(0x70,0x7f,0x180);
279
add_SfrReg(get_pir2(), 0x0d, RegisterValue(0,0),"pir2");
280
add_SfrReg(&pie2, 0x8d, RegisterValue(0,0));
282
pir_set_2_def.set_pir2(pir2);
284
pie2.setPir(get_pir2());
285
alias_file_registers(0x00,0x04,0x100);
286
alias_file_registers(0x80,0x84,0x100);
287
alias_file_registers(0x06,0x06,0x100);
288
alias_file_registers(0x86,0x86,0x100);
290
add_SfrReg(pir1, 0x0c, RegisterValue(0,0),"pir1");
291
add_SfrReg(&pie1, 0x8c, RegisterValue(0,0));
293
add_SfrReg(&tmr1l, 0x0e, RegisterValue(0,0),"tmr1l");
294
add_SfrReg(&tmr1h, 0x0f, RegisterValue(0,0),"tmr1h");
296
add_SfrReg(&pcon, 0x8e, RegisterValue(0,0),"pcon");
298
add_SfrReg(&t1con, 0x10, RegisterValue(0,0));
299
add_SfrReg(&tmr2, 0x11, RegisterValue(0,0));
300
add_SfrReg(&t2con, 0x12, RegisterValue(0,0));
301
add_SfrReg(&pr2, 0x92, RegisterValue(0xff,0));
303
get_eeprom()->get_reg_eedata()->new_name("eedat");
304
get_eeprom()->get_reg_eedatah()->new_name("eedath");
305
add_SfrReg(get_eeprom()->get_reg_eedata(), 0x10c);
306
add_SfrReg(get_eeprom()->get_reg_eeadr(), 0x10d);
307
add_SfrReg(get_eeprom()->get_reg_eedatah(), 0x10e);
308
add_SfrReg(get_eeprom()->get_reg_eeadrh(), 0x10f);
309
add_SfrReg(get_eeprom()->get_reg_eecon1(), 0x18c, RegisterValue(0,0));
310
get_eeprom()->get_reg_eecon1()->set_bits(EECON1::EEPGD);
311
add_SfrReg(get_eeprom()->get_reg_eecon2(), 0x18d);
313
alias_file_registers(0x0a,0x0b,0x080);
314
alias_file_registers(0x0a,0x0b,0x100);
315
alias_file_registers(0x0a,0x0b,0x180);
317
intcon_reg.set_pir_set(get_pir_set());
319
add_SfrReg(osccon, 0x8f, RegisterValue(0x60,0),"osccon");
320
add_SfrReg(&osctune, 0x90, RegisterValue(0,0),"osctune");
322
osccon->set_osctune(&osctune);
323
osctune.set_osccon(osccon);
325
usart.initialize(pir1,&(*m_portc)[6], &(*m_portc)[7],
326
new _TXREG(this,"txreg", &usart),
327
new _RCREG(this,"rcreg", &usart));
329
add_SfrReg(&usart.rcsta, 0x18, RegisterValue(0,0),"rcsta");
330
add_SfrReg(&usart.txsta, 0x98, RegisterValue(2,0),"txsta");
331
add_SfrReg(&usart.spbrg, 0x99, RegisterValue(0,0),"spbrg");
332
add_SfrReg(&usart.spbrgh, 0x9a, RegisterValue(0,0),"spbrgh");
333
add_SfrReg(&usart.baudcon, 0x187,RegisterValue(0x40,0),"baudctl");
334
add_SfrReg(usart.txreg, 0x19, RegisterValue(0,0),"txreg");
335
add_SfrReg(usart.rcreg, 0x1a, RegisterValue(0,0),"rcreg");
336
usart.set_eusart(true);
337
comparator.assign_tmr1l(&tmr1l);
338
comparator.cmxcon1[1]->set_vrcon(&vrcon);
340
add_SfrReg(comparator.cmxcon0[0], 0x107, RegisterValue(0,0), "cm1con0");
341
add_SfrReg(comparator.cmxcon0[1], 0x108, RegisterValue(0,0), "cm2con0");
342
add_SfrReg(comparator.cmxcon1[1], 0x109, RegisterValue(2,0), "cm2con1");
343
add_SfrReg(&vrcon, 0x97, RegisterValue(0,0),"vrcon");
344
add_SfrReg(&srcon, 0x185, RegisterValue(0,0),"srcon");
345
add_SfrReg(&wdtcon, 0x105, RegisterValue(0x08,0),"wdtcon");
346
add_SfrReg(&adresl, 0x9e, RegisterValue(0,0));
347
add_SfrReg(&adresh, 0x1e, RegisterValue(0,0));
348
add_SfrReg(&ansel, 0x188, RegisterValue(0xff,0));
349
add_SfrReg(&anselh, 0x189, RegisterValue(0xff,0));
350
add_SfrReg(&adcon0, 0x1f, RegisterValue(0,0));
351
add_SfrReg(&adcon1, 0x9f, RegisterValue(0,0));
352
add_SfrReg(m_wpu, 0x95, RegisterValue(0xff,0));
353
add_SfrReg(m_ioc, 0x96, RegisterValue(0,0));
355
ansel.setAdcon1(&adcon1);
356
ansel.setAnselh(&anselh);
357
anselh.setAdcon1(&adcon1);
358
anselh.setAnsel(&ansel);
359
adcon0.setAdresLow(&adresl);
360
adcon0.setAdres(&adresh);
361
adcon0.setAdcon1(&adcon1);
362
adcon0.setIntcon(&intcon_reg);
363
adcon0.setA2DBits(10);
365
adcon0.setChannel_Mask(0xf);
366
adcon0.setChannel_shift(2);
369
adcon1.setValidBits(0xb0);
370
adcon1.setNumberOfChannels(14);
371
adcon1.setValidCfgBits(ADCON1::VCFG0 | ADCON1::VCFG1 , 4);
372
adcon1.setIOPin(0, &(*m_porta)[0]);
373
adcon1.setIOPin(1, &(*m_porta)[1]);
374
adcon1.setIOPin(2, &(*m_porta)[2]);
375
adcon1.setIOPin(3, &(*m_porta)[3]);
376
adcon1.setIOPin(4, &(*m_porta)[4]);
377
adcon1.setIOPin(8, &(*m_portb)[2]);
378
adcon1.setIOPin(9, &(*m_portb)[3]);
379
adcon1.setIOPin(10, &(*m_portb)[1]);
380
adcon1.setIOPin(11, &(*m_portb)[4]);
381
adcon1.setIOPin(12, &(*m_portb)[0]);
382
adcon1.setIOPin(13, &(*m_portb)[5]);
384
// set a2d modes where an3 is Vref+
385
adcon1.setVrefHiConfiguration(1, 3);
386
adcon1.setVrefHiConfiguration(3, 3);
388
// set a2d modes where an2 is Vref-
389
adcon1.setVrefLoConfiguration(2, 2);
390
adcon1.setVrefLoConfiguration(3, 2);
392
vrcon.setValidBits(0xff); // All bits settable
394
add_SfrReg(&ccpr1l, 0x15, RegisterValue(0,0));
395
add_SfrReg(&ccpr1h, 0x16, RegisterValue(0,0));
396
add_SfrReg(&ccp1con, 0x17, RegisterValue(0,0));
397
add_SfrReg(&ccpr2l, 0x1b, RegisterValue(0,0));
398
add_SfrReg(&ccpr2h, 0x1c, RegisterValue(0,0));
399
add_SfrReg(&ccp2con, 0x1d, RegisterValue(0,0));
400
add_SfrReg(&pwm1con, 0x9b, RegisterValue(0,0));
401
add_SfrReg(&pstrcon, 0x9d, RegisterValue(1,0));
402
add_SfrReg(&eccpas, 0x9c, RegisterValue(0,0));
403
eccpas.setIOpin(0, 0, &(*m_portb)[0]);
404
eccpas.link_registers(&pwm1con, &ccp1con);
405
ssp.sspmsk = new _SSPMSK(this, "ssp1msk");
406
add_SfrReg(&ssp.sspbuf, 0x13, RegisterValue(0,0),"sspbuf");
407
add_SfrReg(&ssp.sspcon, 0x14, RegisterValue(0,0),"sspcon");
408
add_SfrReg(&ssp.sspcon2, 0x91, RegisterValue(0,0),"sspcon2");
409
add_SfrReg(&ssp.sspadd, 0x93, RegisterValue(0,0),"sspadd");
410
add_SfrReg(ssp.sspmsk, 0x93, RegisterValue(0xff,0), "sspmsk", false);
411
add_SfrReg(&ssp.sspstat, 0x94, RegisterValue(0,0),"sspstat");
412
tmr2.ssp_module[0] = &ssp;
415
get_pir_set(), // PIR
416
&(*m_portc)[3], // SCK
417
&(*m_porta)[5], // SS
418
&(*m_portc)[5], // SDO
419
&(*m_portc)[4], // SDI
420
m_trisc, // i2c tris port
424
tmr1l.t1con = &t1con;
430
tmr2.pir_set = get_pir_set();
433
tmr2.add_ccp ( &ccp1con );
434
tmr2.add_ccp ( &ccp2con );
437
tmr1l.setIOpin(&(*m_portc)[0]);
438
ccp1con.setBitMask(0xff);
439
ccp1con.pstrcon = &pstrcon;
440
ccp1con.pwm1con = &pwm1con;
441
ccp1con.setCrosslinks(&ccpr1l, pir1, PIR1v2::CCP1IF, &tmr2, &eccpas);
442
ccpr1l.ccprh = &ccpr1h;
443
ccpr1l.tmrl = &tmr1l;
444
ccpr1h.ccprl = &ccpr1l;
446
ccp2con.setIOpin(&(*m_portc)[1]);
447
ccp2con.setCrosslinks(&ccpr2l, pir2, PIR2v3::CCP2IF, &tmr2);
448
ccpr2l.ccprh = &ccpr2h;
449
ccpr2l.tmrl = &tmr1l;
450
ccpr2h.ccprl = &ccpr2l;
453
pir1->set_intcon(&intcon_reg);
454
pir1->set_pie(&pie1);
458
comparator.cmxcon1[0]->set_OUTpin(&(*m_porta)[4], &(*m_porta)[5]);
459
comparator.cmxcon1[0]->set_INpinNeg(&(*m_porta)[0], &(*m_porta)[1],
460
&(*m_portb)[3],&(*m_portb)[1]);
461
comparator.cmxcon1[0]->set_INpinPos(&(*m_porta)[3], &(*m_porta)[2]);
462
comparator.cmxcon1[0]->setBitMask(0x33);
463
comparator.cmxcon0[0]->setBitMask(0xb7);
464
comparator.cmxcon0[0]->setIntSrc(new InterruptSource(pir2, PIR2v2::C1IF));
465
comparator.cmxcon0[1]->setBitMask(0xb7);
466
comparator.cmxcon0[1]->setIntSrc(new InterruptSource(pir2, PIR2v2::C2IF));
469
void P16F88x::option_new_bits_6_7(uint bits)
471
Dprintf(("P18F88x::option_new_bits_6_7 bits=%x\n", bits));
472
m_portb->setIntEdge ( (bits & OPTION_REG::BIT6) == OPTION_REG::BIT6);
473
m_wpu->set_wpu_pu ( (bits & OPTION_REG::BIT7) != OPTION_REG::BIT7);
476
void P16F88x::set_out_of_range_pm(uint address, uint value)
478
if( (address>= 0x2100) && (address < 0x2100 + get_eeprom()->get_rom_size()))
480
get_eeprom()->change_rom(address - 0x2100, value);
484
bool P16F88x::set_config_word(uint address, uint cfg_word)
493
// Let the base class do most of the work:
494
if (address == 0x2007)
496
pic_processor::set_config_word(address, cfg_word);
498
uint valid_pins = m_porta->getEnableMask();
501
// Careful these bits not adjacent
502
switch(cfg_word & (CFG_FOSC0 | CFG_FOSC1 | CFG_FOSC2)) {
504
case 0: // LP oscillator: low power crystal is on RA6 and RA7
505
case 1: // XT oscillator: crystal/resonator is on RA6 and RA7
506
case 2: // HS oscillator: crystal/resonator is on RA6 and RA7
509
case 0x13: // ER oscillator: RA6 is CLKOUT, resistor (?) on RA7
512
case 3: // EC: RA6 is an I/O, RA7 is a CLKIN
513
case 0x12: // ER oscillator: RA6 is an I/O, RA7 is a CLKIN
514
valid_pins = (valid_pins & 0x7f)|0x40;
517
case 0x10: // INTRC: Internal Oscillator, RA6 and RA7 are I/O's
522
case 0x11: // INTRC: Internal Oscillator, RA7 is an I/O, RA6 is CLKOUT
524
valid_pins = (valid_pins & 0xbf)|0x80;
528
// If the /MCLRE bit is set then RE3 is the MCLR pin, otherwise it's
529
// a general purpose I/O pin.
531
if ((cfg_word & CFG_MCLRE))
540
if (valid_pins != m_porta->getEnableMask()) // enable new pins for IO
542
m_porta->setEnableMask(valid_pins);
543
m_porta->setTris(m_trisa);
547
else if (address == 0x2008 )
549
//cout << "p16f88x 0x" << hex << address << " config word2 0x" << cfg_word << '\n';
554
void P16F88x::create_config_memory()
556
m_configMemory = new ConfigMemory(this,2);
557
m_configMemory->addConfigWord(0,new Config188x(this));
558
m_configMemory->addConfigWord(1,new ConfigWord("CONFIG2", 0, this,0x2008));
559
wdt.initialize(true); // default WDT enabled
560
wdt.set_timeout(0.000035);
561
set_config_word(0x2007, 0x3fff);
565
void P16F88x::create(int eesize)
569
_14bit_processor::create();
570
osccon = new OSCCON(this, "osccon" );
573
e = new EEPROM_WIDE(this,pir2);
574
e->initialize(eesize);
575
e->set_intcon(&intcon_reg);
578
status->rp_mask = 0x60; // rp0 and rp1 are valid.
579
indf->base_address_mask1 = 0x80; // used for indirect accesses above 0x100
580
indf->base_address_mask2 = 0x1ff; // used for indirect accesses above 0x100
582
P16F88x::create_sfr_map();
585
//========================================================================
587
Processor * P16F882::construct(const char *name)
589
P16F882 *p = new P16F882(name);
591
p->P16F88x::create(128);
592
p->P16F882::create_sfr_map();
593
p->create_invalid_registers ();
598
P16F882::P16F882(const char *_name )
601
m_porta->setEnableMask(0xff);
604
void P16F882::create_iopin_map(void)
606
assign_pin(1, m_porte->addPin(new IO_bi_directional("porte3"),3));
607
assign_pin( 2, m_porta->addPin(new IO_bi_directional("porta0"),0));
608
assign_pin( 3, m_porta->addPin(new IO_bi_directional("porta1"),1));
609
assign_pin( 4, m_porta->addPin(new IO_bi_directional("porta2"),2));
610
assign_pin( 5, m_porta->addPin(new IO_bi_directional("porta3"),3));
611
assign_pin( 6, m_porta->addPin( new IOPIN("porta4", OPEN_COLLECTOR),4) );
612
assign_pin( 7, m_porta->addPin(new IO_bi_directional("porta5"),5));
614
assign_pin( 9, m_porta->addPin(new IO_bi_directional("porta7"),7));
615
assign_pin( 10, m_porta->addPin(new IO_bi_directional("porta6"),6));
616
assign_pin(11, m_portc->addPin(new IO_bi_directional("portc0"),0));
617
assign_pin(12, m_portc->addPin(new IO_bi_directional("portc1"),1));
618
assign_pin(13, m_portc->addPin(new IO_bi_directional("portc2"),2));
619
assign_pin(14, m_portc->addPin(new IO_bi_directional("portc3"),3));
620
assign_pin(15, m_portc->addPin(new IO_bi_directional("portc4"),4));
621
assign_pin(16, m_portc->addPin(new IO_bi_directional("portc5"),5));
622
assign_pin(17, m_portc->addPin(new IO_bi_directional("portc6"),6));
623
assign_pin(18, m_portc->addPin(new IO_bi_directional("portc7"),7));
626
assign_pin(21, m_portb->addPin(new IO_bi_directional_pu("portb0"),0));
627
assign_pin(22, m_portb->addPin(new IO_bi_directional_pu("portb1"),1));
628
assign_pin(23, m_portb->addPin(new IO_bi_directional_pu("portb2"),2));
629
assign_pin(24, m_portb->addPin(new IO_bi_directional_pu("portb3"),3));
630
assign_pin(25, m_portb->addPin(new IO_bi_directional_pu("portb4"),4));
631
assign_pin(26, m_portb->addPin(new IO_bi_directional_pu("portb5"),5));
632
assign_pin(27, m_portb->addPin(new IO_bi_directional_pu("portb6"),6));
633
assign_pin(28, m_portb->addPin(new IO_bi_directional_pu("portb7"),7));
637
void P16F882::create_sfr_map()
639
ccp1con.setIOpin(&(*m_portc)[2], &(*m_portb)[2], &(*m_portb)[1], &(*m_portb)[4]);
641
//========================================================================
645
Processor * P16F883::construct(const char *name)
647
P16F883 *p = new P16F883(name);
649
p->P16F88x::create(256);
650
p->P16F883::create_sfr_map();
651
p->create_invalid_registers ();
656
P16F883::P16F883(const char *_name )
659
m_porta->setEnableMask(0xff);
664
delete_file_registers(0xc0,0xef);
665
delete_file_registers(0x120,0x16f);
668
void P16F883::create_sfr_map()
670
add_file_registers(0xc0,0xef,0);
671
add_file_registers(0x120,0x16f,0);
672
ccp1con.setIOpin(&(*m_portc)[2], &(*m_portb)[2], &(*m_portb)[1], &(*m_portb)[4]);
674
//========================================================================
679
Processor * P16F886::construct(const char *name)
681
P16F886 *p = new P16F886(name);
683
p->P16F88x::create(256);
684
p->P16F886::create_sfr_map();
685
p->create_invalid_registers ();
690
P16F886::P16F886(const char *_name )
693
m_porta->setEnableMask(0xff);
698
delete_file_registers(0xc0,0xef);
699
delete_file_registers(0x120,0x16f);
700
delete_file_registers(0x190,0x1ef);
703
void P16F886::create_sfr_map()
705
add_file_registers(0xc0,0xef,0);
706
add_file_registers(0x120,0x16f,0);
707
add_file_registers(0x190,0x1ef,0);
708
ccp1con.setIOpin(&(*m_portc)[2], &(*m_portb)[2], &(*m_portb)[1], &(*m_portb)[4]);
710
//========================================================================
715
Processor * P16F887::construct(const char *name)
717
P16F887 *p = new P16F887(name);
719
p->P16F88x::create(256);
720
p->P16F887::create_sfr_map();
721
p->create_invalid_registers ();
726
P16F887::P16F887(const char *_name )
733
delete_file_registers(0x110,0x11f);
734
delete_file_registers(0x190,0x1ef);
737
void P16F887::create_sfr_map()
739
add_file_registers(0xc0,0xef,0);
740
add_file_registers(0x110,0x16f,0);
741
//add_file_registers(0x110,0x11f,0);
742
add_file_registers(0x190,0x1ef,0);
744
add_SfrReg(m_portd, 0x08);
745
add_SfrReg(m_trisd, 0x88, RegisterValue(0xff,0));
747
ccp1con.setIOpin(&(*m_portc)[2], &(*m_portd)[5], &(*m_portd)[6], &(*m_portd)[7]);
748
adcon1.setIOPin(5, &(*m_porte)[0]);
749
adcon1.setIOPin(6, &(*m_porte)[1]);
750
adcon1.setIOPin(7, &(*m_porte)[2]);
753
//========================================================================
755
Processor * P16F884::construct(const char *name)
757
P16F884 *p = new P16F884(name);
759
p->P16F88x::create(256);
760
p->P16F884::create_sfr_map();
761
p->create_invalid_registers ();
766
P16F884::P16F884(const char *_name )
769
m_porta->setEnableMask(0xff);
771
// trisa5 is an input only pin
772
m_trisa->setEnableMask(0xdf);
774
m_portd = new PicPSP_PortRegister(this,"portd", 8,0xff);
775
m_trisd = new PicTrisRegister(this,"trisd", (PicPortRegister *)m_portd, false);
780
delete_file_registers(0xc0,0xef);
781
delete_file_registers(0x120,0x16f);
783
delete_SfrReg(m_portd);
784
delete_SfrReg(m_trisd);
787
//------------------------------------------------------------------------
789
void P16F884::create_iopin_map(void)
791
assign_pin(1, m_porte->addPin(new IO_bi_directional("porte3"),3));
792
assign_pin( 2, m_porta->addPin(new IO_bi_directional("porta0"),0));
793
assign_pin( 3, m_porta->addPin(new IO_bi_directional("porta1"),1));
794
assign_pin( 4, m_porta->addPin(new IO_bi_directional("porta2"),2));
795
assign_pin( 5, m_porta->addPin(new IO_bi_directional("porta3"),3));
796
assign_pin( 6, m_porta->addPin( new IOPIN("porta4", OPEN_COLLECTOR),4) );
797
assign_pin( 7, m_porta->addPin(new IO_bi_directional("porta5"),5));
798
assign_pin( 8, m_porte->addPin(new IO_bi_directional("porte0"),0));
799
assign_pin( 9, m_porte->addPin(new IO_bi_directional("porte1"),1));
800
assign_pin(10, m_porte->addPin(new IO_bi_directional("porte2"),2));
803
assign_pin( 13, m_porta->addPin(new IO_bi_directional("porta7"),7));
804
assign_pin( 14, m_porta->addPin(new IO_bi_directional("porta6"),6));
805
assign_pin(15, m_portc->addPin(new IO_bi_directional("portc0"),0));
806
assign_pin(16, m_portc->addPin(new IO_bi_directional("portc1"),1));
807
assign_pin(17, m_portc->addPin(new IO_bi_directional("portc2"),2));
808
assign_pin(18, m_portc->addPin(new IO_bi_directional("portc3"),3));
809
assign_pin(23, m_portc->addPin(new IO_bi_directional("portc4"),4));
810
assign_pin(24, m_portc->addPin(new IO_bi_directional("portc5"),5));
811
assign_pin(25, m_portc->addPin(new IO_bi_directional("portc6"),6));
812
assign_pin(26, m_portc->addPin(new IO_bi_directional("portc7"),7));
813
assign_pin(19, m_portd->addPin(new IO_bi_directional("portd0"),0));
814
assign_pin(20, m_portd->addPin(new IO_bi_directional("portd1"),1));
815
assign_pin(21, m_portd->addPin(new IO_bi_directional("portd2"),2));
816
assign_pin(22, m_portd->addPin(new IO_bi_directional("portd3"),3));
817
assign_pin(27, m_portd->addPin(new IO_bi_directional("portd4"),4));
818
assign_pin(28, m_portd->addPin(new IO_bi_directional("portd5"),5));
819
assign_pin(29, m_portd->addPin(new IO_bi_directional("portd6"),6));
820
assign_pin(30, m_portd->addPin(new IO_bi_directional("portd7"),7));
823
assign_pin(33, m_portb->addPin(new IO_bi_directional_pu("portb0"),0));
824
assign_pin(34, m_portb->addPin(new IO_bi_directional_pu("portb1"),1));
825
assign_pin(35, m_portb->addPin(new IO_bi_directional_pu("portb2"),2));
826
assign_pin(36, m_portb->addPin(new IO_bi_directional_pu("portb3"),3));
827
assign_pin(37, m_portb->addPin(new IO_bi_directional_pu("portb4"),4));
828
assign_pin(38, m_portb->addPin(new IO_bi_directional_pu("portb5"),5));
829
assign_pin(39, m_portb->addPin(new IO_bi_directional_pu("portb6"),6));
830
assign_pin(40, m_portb->addPin(new IO_bi_directional_pu("portb7"),7));
833
void P16F884::create_sfr_map()
835
add_file_registers(0xc0,0xef,0);
836
add_file_registers(0x120,0x16f,0);
838
add_SfrReg(m_portd, 0x08);
839
add_SfrReg(m_trisd, 0x88, RegisterValue(0xff,0));
841
ccp1con.setIOpin(&(*m_portc)[2], &(*m_portd)[5], &(*m_portd)[6], &(*m_portd)[7]);
842
adcon1.setIOPin(5, &(*m_porte)[0]);
843
adcon1.setIOPin(6, &(*m_porte)[1]);
844
adcon1.setIOPin(7, &(*m_porte)[2]);
846
//------------------------------------------------------------------------
850
class ConfigF631 : public ConfigWord
853
ConfigF631(P16F631 *pCpu)
854
: ConfigWord("CONFIG", 0x3fff, pCpu, 0x2007)
856
Dprintf(("ConfigF631::ConfigF631 %p\n", m_pCpu));
879
const char *OSCdesc[8] = {
883
"EC oscillator w/ OSC2 configured as I/O",
884
"INTOSC oscillator: I/O on RA4 pin, I/O on RA5",
885
"INTOSC oscillator: CLKOUT on RA4 pin, I/O on RA5",
886
"RC oscillator: I/O on RA4 pin, RC on RA5",
887
"RC oscillator: CLKOUT on RA4 pin, RC on RA5"
889
snprintf(buff,sizeof(buff),
891
" FOSC=%d - Clk source = %s\n"
892
" WDTEN=%d - WDT is %s\n"
893
" PWRTEN=%d - Power up timer is %s\n"
894
" MCLRE=%d - RA3 Pin %s\n"
895
" BODEN=%d - Brown-out Detect %s\n"
896
" CP=%d - Code Protection %s\n"
897
" CPD=%d - Data Code Protection %s\n",
899
i&(FOSC0|FOSC1|FOSC2), OSCdesc[i&(FOSC0|FOSC1|FOSC2)],
900
((i&WDTE) ? 1 : 0), ((i&WDTE) ? "enabled" : "disabled"),
901
((i&PWRTEN) ? 1 : 0), ((i&PWRTEN) ? "disabled" : "enabled"),
902
((i&MCLRE) ? 1 : 0), ((i&MCLRE) ? "MCLR" : "Input"),
903
((i&BODEN) ? 1 : 0), ((i&BODEN) ? "enabled" : "disabled"),
904
((i&CP) ? 1 : 0), ((i&CP) ? "disabled" : "enabled"),
905
((i&CPD) ? 1 : 0), ((i&CPD) ? "disabled" : "enabled")
910
P16F631::P16F631(const char *_name )
911
: _14bit_processor(_name ),
912
t1con(this, "t1con" ),
915
tmr1l(this, "tmr1l" ),
916
tmr1h(this, "tmr1h" ),
917
osctune(this, "osctune" ),
919
wdtcon(this, "wdtcon", 0x1f),
921
vrcon(this, "vrcon" ),
922
srcon(this, "srcon" ),
923
ansel(this,"ansel" ),
925
adcon0(this,"adcon0" ),
926
adcon1(this,"adcon1" ),
928
intcon_reg(this,"intcon" )
930
pir1_2_reg = new PIR1v2(this,"pir1", &intcon_reg,&pie1);
932
pir2_3_reg = new PIR2v3(this,"pir2", &intcon_reg,&pie2);
935
m_ioca = new IOC(this, "ioca" );
936
m_iocb = new IOC(this, "iocb" );
938
m_porta = new PicPortGRegister(this,"porta", &intcon_reg, m_ioca, 8,0x3f);
939
m_trisa = new PicTrisRegister(this,"trisa", m_porta, false, 0x37);
941
m_portb = new PicPortGRegister(this,"portb", &intcon_reg, m_iocb, 8,0xf0);
942
m_trisb = new PicTrisRegister(this,"trisb", m_portb, false);
944
m_wpua = new WPU(this, "wpua", m_porta, 0x37);
945
m_wpub = new WPU(this, "wpub", m_portb, 0xf0);
946
tmr0.set_cpu(this, m_porta, 4, option_reg);
949
m_portc = new PicPortRegister(this,"portc", 8,0xff);
950
m_trisc = new PicTrisRegister(this,"trisc", m_portc, false);
952
comparator.cmxcon0[0] = new CMxCON0_V2(this, "cm1con0", 0, &comparator);
953
comparator.cmxcon0[1] = new CMxCON0_V2(this, "cm2con0", 1, &comparator);
954
comparator.cmxcon1[0] = new CM2CON1_V4(this, "cm2con1", 0, &comparator);
955
comparator.cmxcon1[1] = comparator.cmxcon1[0];
961
delete_file_registers(0x40, 0x7f);
962
remove_SfrReg(comparator.cmxcon0[0]);
963
remove_SfrReg(comparator.cmxcon0[1]);
964
remove_SfrReg(comparator.cmxcon1[1]);
966
remove_SfrReg(get_eeprom()->get_reg_eedata());
967
remove_SfrReg(get_eeprom()->get_reg_eeadr());
968
remove_SfrReg(get_eeprom()->get_reg_eecon1());
969
remove_SfrReg(get_eeprom()->get_reg_eecon2());
970
remove_SfrReg(&tmr0);
971
remove_SfrReg(&vrcon);
972
remove_SfrReg(&ansel);
973
remove_SfrReg(&srcon);
974
remove_SfrReg(&tmr1l);
975
remove_SfrReg(&tmr1h);
976
remove_SfrReg(&t1con);
977
remove_SfrReg(&pcon);
978
remove_SfrReg(&wdtcon);
979
remove_SfrReg(osccon);
980
remove_SfrReg(&pie1);
981
remove_SfrReg(&pie2);
982
remove_SfrReg(&intcon_reg);
983
remove_SfrReg(&osctune);
985
delete_SfrReg(m_portc);
986
delete_SfrReg(m_trisc);
988
delete_SfrReg(m_portb);
989
delete_SfrReg(m_trisb);
990
delete_SfrReg(m_porta);
991
delete_SfrReg(m_trisa);
992
delete_SfrReg(m_ioca);
993
delete_SfrReg(m_iocb);
994
delete_SfrReg(m_wpua);
995
delete_SfrReg(m_wpub);
996
delete_SfrReg(pir1_2_reg);
999
void P16F631::create_iopin_map(void)
1001
assign_pin(1, 0); // Vdd
1002
assign_pin( 2, m_porta->addPin(new IO_bi_directional_pu("porta5"),5));
1003
assign_pin( 3, m_porta->addPin(new IO_bi_directional_pu("porta4"),4));
1004
assign_pin( 4, m_porta->addPin(new IOPIN("porta3"),3));
1005
assign_pin( 5, m_portc->addPin(new IO_bi_directional_pu("portc5"),5));
1006
assign_pin( 6, m_portc->addPin(new IO_bi_directional("portc4"),4));
1007
assign_pin( 7, m_portc->addPin(new IO_bi_directional("portc3"),3));
1008
assign_pin( 8, m_portc->addPin(new IO_bi_directional("portc6"),6));
1009
assign_pin( 9, m_portc->addPin(new IO_bi_directional("portc7"),7));
1010
assign_pin(10, m_portb->addPin(new IO_bi_directional("portb7"),7));
1011
assign_pin(11, m_portb->addPin(new IO_bi_directional_pu("portb6"),6));
1012
assign_pin(12, m_portb->addPin(new IO_bi_directional_pu("portb5"),5));
1013
assign_pin(13, m_portb->addPin(new IO_bi_directional_pu("portb4"),4));
1014
assign_pin(14, m_portc->addPin(new IO_bi_directional_pu("portc2"),2));
1015
assign_pin(15, m_portc->addPin(new IO_bi_directional_pu("portc1"),1));
1016
assign_pin(16, m_portc->addPin(new IO_bi_directional_pu("portc0"),0));
1017
assign_pin(17, m_porta->addPin(new IO_bi_directional_pu("porta2"),2));
1018
assign_pin(18, m_porta->addPin(new IO_bi_directional_pu("porta1"),1));
1019
assign_pin(19, m_porta->addPin(new IO_bi_directional_pu("porta0"),0));
1021
assign_pin(20, 0); //VSS
1023
tmr1l.setIOpin(&(*m_portc)[0]);
1025
Processor * P16F631::construct(const char *name)
1027
P16F631 *p = new P16F631(name);
1030
p->create_invalid_registers ();
1035
void P16F631::create(int eesize)
1039
_14bit_processor::create();
1040
osccon = new OSCCON(this, "osccon" );
1042
e = new EEPROM_WIDE(this,pir2);
1043
e->initialize(eesize);
1044
e->set_intcon(&intcon_reg);
1047
status->rp_mask = 0x60; // rp0 and rp1 are valid.
1048
indf->base_address_mask1 = 0x80; // used for indirect accesses above 0x100
1049
indf->base_address_mask2 = 0x1ff; // used for indirect accesses above 0x100
1051
P16F631::create_sfr_map();
1054
//-------------------------------------------------------------------
1055
void P16F631::create_sfr_map()
1057
pir_set_2_def.set_pir1(pir1);
1058
pir_set_2_def.set_pir2(pir2);
1060
add_file_registers(0x40, 0x7f, 0);
1061
alias_file_registers(0x70, 0x7f, 0x80);
1062
alias_file_registers(0x70, 0x7f, 0x100);
1063
alias_file_registers(0x70, 0x7f, 0x180);
1065
add_SfrReg(indf, 0x00);
1066
alias_file_registers(0x00,0x00,0x80);
1067
alias_file_registers(0x00,0x00,0x100);
1068
alias_file_registers(0x00,0x00,0x180);
1070
add_SfrReg(&tmr0, 0x01);
1071
alias_file_registers(0x01,0x01,0x100);
1072
add_SfrReg(option_reg, 0x81, RegisterValue(0xff,0));
1073
alias_file_registers(0x81,0x81,0x100);
1075
add_SfrReg(pcl, 0x02, RegisterValue(0,0));
1076
add_SfrReg(status, 0x03, RegisterValue(0x18,0));
1077
add_SfrReg(fsr, 0x04);
1078
alias_file_registers(0x02,0x04,0x80);
1079
alias_file_registers(0x02,0x04,0x100);
1080
alias_file_registers(0x02,0x04,0x180);
1082
add_SfrReg(m_porta, 0x05);
1083
add_SfrReg(m_trisa, 0x85, RegisterValue(0x3f,0));
1085
add_SfrReg(m_portb, 0x06);
1086
add_SfrReg(m_trisb, 0x86, RegisterValue(0xf0,0));
1088
add_SfrReg(m_portc, 0x07);
1089
add_SfrReg(m_trisc, 0x87, RegisterValue(0xff,0));
1090
alias_file_registers(0x05,0x07,0x100);
1091
alias_file_registers(0x85,0x87,0x100);
1093
add_SfrReg(pclath, 0x0a, RegisterValue(0,0));
1094
add_SfrReg(&intcon_reg, 0x00b, RegisterValue(0,0));
1096
alias_file_registers(0x0a,0x0b,0x80);
1097
alias_file_registers(0x0a,0x0b,0x100);
1098
alias_file_registers(0x0a,0x0b,0x180);
1099
add_SfrReg(pir1, 0x0c, RegisterValue(0,0));
1100
add_SfrReg(pir2, 0x0d, RegisterValue(0,0));
1101
add_SfrReg(&tmr1l, 0x0e, RegisterValue(0,0), "tmr1l");
1102
add_SfrReg(&tmr1h, 0x0f, RegisterValue(0,0), "tmr1h");
1103
add_SfrReg(&t1con, 0x10, RegisterValue(0,0));
1104
add_SfrReg(&pcon, 0x8e, RegisterValue(0,0));
1105
add_SfrReg(&wdtcon, 0x97, RegisterValue(0x08,0));
1106
add_SfrReg(osccon, 0x8f, RegisterValue(0x60,0));
1108
add_SfrReg(&vrcon, 0x118, RegisterValue(0,0),"vrcon");
1109
add_SfrReg(comparator.cmxcon0[0], 0x119, RegisterValue(0,0), "cm1con0");
1110
add_SfrReg(comparator.cmxcon0[1], 0x11a, RegisterValue(0,0), "cm2con0");
1111
add_SfrReg(comparator.cmxcon1[1], 0x11b, RegisterValue(2,0), "cm2con1");
1112
comparator.cmxcon1[0]->set_OUTpin(&(*m_porta)[2], &(*m_portc)[4]);
1113
comparator.cmxcon1[0]->set_INpinNeg(&(*m_porta)[1], &(*m_portc)[1],
1114
&(*m_portc)[2], &(*m_portc)[3]);
1115
comparator.cmxcon1[0]->set_INpinPos(&(*m_porta)[0], &(*m_portc)[0]);
1116
comparator.cmxcon1[0]->setBitMask(0x03);
1117
comparator.cmxcon0[0]->setBitMask(0xb7);
1118
comparator.cmxcon0[0]->setIntSrc(new InterruptSource(pir2, PIR2v2::C1IF));
1119
comparator.cmxcon0[1]->setBitMask(0xb7);
1120
comparator.cmxcon0[1]->setIntSrc(new InterruptSource(pir2, PIR2v2::C2IF));
1121
comparator.cmxcon1[0]->set_vrcon(&vrcon);
1122
comparator.cmxcon1[1] = comparator.cmxcon1[0];
1123
comparator.assign_tmr1l(&tmr1l);
1125
add_SfrReg(&ansel, 0x11e, RegisterValue(0xff,0));
1126
add_SfrReg(&srcon, 0x19e, RegisterValue(0,0),"srcon");
1128
ansel.setAdcon1(&adcon1);
1129
ansel.setValidBits(0xff);
1131
adcon1.setNumberOfChannels(12);
1132
adcon1.setIOPin(0, &(*m_porta)[0]);
1133
adcon1.setIOPin(1, &(*m_porta)[1]);
1134
adcon1.setIOPin(4, &(*m_portc)[0]);
1136
adcon1.setIOPin(5, &(*m_portc)[1]);
1137
adcon1.setIOPin(6, &(*m_portc)[2]);
1138
adcon1.setIOPin(7, &(*m_portc)[3]);
1139
intcon = &intcon_reg;
1140
intcon_reg.set_pir_set(get_pir_set());
1142
tmr1l.tmrh = &tmr1h;
1143
tmr1l.t1con = &t1con;
1144
// FIXME -- can't delete this new'd item
1145
tmr1l.setInterruptSource(new InterruptSource(pir1, PIR1v3::TMR1IF));
1146
tmr1h.tmrl = &tmr1l;
1147
t1con.tmrl = &tmr1l;
1149
tmr1l.setIOpin(&(*m_porta)[5]);
1150
tmr1l.setGatepin(&(*m_porta)[4]);
1152
add_SfrReg(&pie1, 0x8c, RegisterValue(0,0));
1153
add_SfrReg(&pie2, 0x8d, RegisterValue(0,0));
1155
pir1->set_intcon(&intcon_reg);
1156
pir1->set_pie(&pie1);
1161
get_eeprom()->get_reg_eedata()->new_name("eedat");
1162
add_SfrReg(get_eeprom()->get_reg_eedata(), 0x10c);
1163
add_SfrReg(get_eeprom()->get_reg_eeadr(), 0x10d);
1164
add_SfrReg(get_eeprom()->get_reg_eecon1(), 0x18c, RegisterValue(0,0));
1165
add_SfrReg(get_eeprom()->get_reg_eecon2(), 0x18d);
1166
add_SfrReg(m_wpua, 0x95, RegisterValue(0x37,0),"wpua");
1167
add_SfrReg(m_wpub, 0x115, RegisterValue(0xf0,0),"wpub");
1168
add_SfrReg(m_ioca, 0x96, RegisterValue(0,0),"ioca");
1169
add_SfrReg(m_iocb, 0x116, RegisterValue(0,0),"iocb");
1170
add_SfrReg(&osctune, 0x90, RegisterValue(0,0),"osctune");
1172
osccon->set_osctune(&osctune);
1173
osctune.set_osccon(osccon);
1175
//-------------------------------------------------------------------
1176
void P16F631::option_new_bits_6_7(uint bits)
1178
m_wpua->set_wpu_pu( (bits & OPTION_REG::BIT7) != OPTION_REG::BIT7);
1179
m_wpub->set_wpu_pu( (bits & OPTION_REG::BIT7) != OPTION_REG::BIT7);
1180
m_porta->setIntEdge((bits & OPTION_REG::BIT6) == OPTION_REG::BIT6);
1182
//-------------------------------------------------------------------
1183
void P16F631::create_config_memory()
1185
m_configMemory = new ConfigMemory(this,1);
1186
m_configMemory->addConfigWord(0,new ConfigF631(this));
1187
wdt.initialize(true); // default WDT enabled
1188
wdt.set_timeout(0.000035);
1189
set_config_word(0x2007, 0x3fff);
1193
//-------------------------------------------------------------------
1194
bool P16F631::set_config_word(uint address, uint cfg_word)
1205
if(address == config_word_address())
1207
uint valid_pins = m_porta->getEnableMask();
1209
if ((cfg_word & CFG_MCLRE) == CFG_MCLRE)
1218
wdt.initialize((cfg_word & CFG_WDTE) == CFG_WDTE);
1222
// AnalogReq is used so ADC does not change clock names
1223
// set_config_word is first called with default and then
1224
// often called a second time. the following call is to
1225
// reset porta so next call to AnalogReq sill set the pin name
1227
(&(*m_porta)[4])->AnalogReq((Register *)this, false, "porta4");
1230
uint fosc = cfg_word & (CFG_FOSC0 | CFG_FOSC1 | CFG_FOSC2);
1233
osccon->set_config_xosc(fosc < 3);
1234
osccon->set_config_irc(fosc == 4 || fosc == 5);
1235
osccon->set_config_ieso(cfg_word & CFG_IESO);
1240
case 0: // LP oscillator: low power crystal is on RA4 and RA5
1241
case 1: // XT oscillator: crystal/resonator is on RA4 and RA5
1242
case 2: // HS oscillator: crystal/resonator is on RA4 and RA5
1243
(&(*m_porta)[4])->AnalogReq((Register *)this, true, "OSC2");
1248
case 3: // EC I/O on RA4 pin, CLKIN on RA5
1252
case 5: // INTOSC CLKOUT on RA4 pin
1253
(&(*m_porta)[4])->AnalogReq((Register *)this, true, "CLKOUT");
1256
osccon->set_rc_frequency();
1259
case 6: //RC oscillator: I/O on RA4 pin, RC on RA5
1263
case 7: // RC oscillator: CLKOUT on RA4 pin, RC on RA5
1264
(&(*m_porta)[4])->AnalogReq((Register *)this, true, "CLKOUT");
1270
if (valid_pins != m_porta->getEnableMask()) // enable new pins for IO
1272
m_porta->setEnableMask(valid_pins);
1273
m_trisa->setEnableMask(valid_pins & 0xf7);
1280
//========================================================================
1284
P16F684::P16F684(const char *_name )
1285
: _14bit_processor(_name ),
1287
t1con(this, "t1con" ),
1288
t2con(this, "t2con" ),
1291
tmr2(this, "tmr2" ),
1292
tmr1l(this, "tmr1l" ),
1293
tmr1h(this, "tmr1h" ),
1294
osctune(this, "osctune" ),
1295
pcon(this, "pcon" ),
1296
wdtcon(this, "wdtcon", 0x1f),
1298
ansel(this, "ansel" ),
1299
adcon0(this, "adcon0" ),
1300
adcon1(this, "adcon1" ),
1301
adresh(this, "adresh" ),
1302
adresl(this, "adresl" ),
1303
ccp1con(this, "ccp1con" ),
1304
ccpr1l(this, "ccpr1l" ),
1305
ccpr1h(this, "ccpr1h" ),
1306
eccpas(this, "eccpas" ),
1307
pwm1con(this, "pwm1con" ),
1308
pstrcon(this, "pstrcon" ),
1309
intcon_reg(this,"intcon" )
1311
pir1_3_reg = new PIR1v3(this,"pir1", &intcon_reg,&pie1);
1313
pir1->valid_bits = pir1->writable_bits = 0xff;
1315
m_ioca = new IOC(this, "ioca" );
1317
m_porta = new PicPortGRegister(this,"porta", &intcon_reg, m_ioca, 8,0x3f);
1318
m_trisa = new PicTrisRegister(this,"trisa", m_porta, false);
1320
m_wpua = new WPU(this, "wpua", m_porta, 0x37);
1321
tmr0.set_cpu(this, m_porta, 4, option_reg);
1324
m_portc = new PicPortRegister(this,"portc", 8,0x3f);
1325
m_trisc = new PicTrisRegister(this,"trisc", m_portc, false);
1332
delete_file_registers(0x20, 0x7f);
1333
delete_file_registers(0xa0, 0xbf);
1335
remove_SfrReg(&tmr0);
1336
remove_SfrReg(&intcon_reg);
1337
remove_SfrReg(pir1);
1338
remove_SfrReg(&tmr1l);
1339
remove_SfrReg(&tmr1h);
1340
remove_SfrReg(&t1con);
1341
remove_SfrReg(&tmr2);
1342
remove_SfrReg(&t2con);
1343
remove_SfrReg(&ccpr1l);
1344
remove_SfrReg(&ccpr1h);
1345
remove_SfrReg(&ccp1con);
1346
remove_SfrReg(&pwm1con);
1347
remove_SfrReg(&eccpas);
1348
remove_SfrReg(&wdtcon);
1349
remove_SfrReg(&comparator.cmcon);
1350
remove_SfrReg(&comparator.cmcon1);
1351
remove_SfrReg(&adresh);
1352
remove_SfrReg(&adcon0);
1353
remove_SfrReg(&pie1);
1354
remove_SfrReg(&pcon);
1355
remove_SfrReg(osccon);
1356
remove_SfrReg(&osctune);
1357
remove_SfrReg(&ansel);
1358
remove_SfrReg(&pr2);
1359
remove_SfrReg(&comparator.vrcon);
1360
remove_SfrReg(get_eeprom()->get_reg_eedata());
1361
remove_SfrReg(get_eeprom()->get_reg_eeadr());
1362
remove_SfrReg(get_eeprom()->get_reg_eecon1());
1363
remove_SfrReg(get_eeprom()->get_reg_eecon2());
1364
remove_SfrReg(&adresl);
1365
remove_SfrReg(&adcon1);
1367
delete_SfrReg(m_portc);
1368
delete_SfrReg(m_trisc);
1370
delete_SfrReg(m_porta);
1371
delete_SfrReg(m_trisa);
1372
delete_SfrReg(m_ioca);
1373
delete_SfrReg(m_wpua);
1374
delete_SfrReg(pir1_3_reg);
1378
void P16F684::create_iopin_map(void)
1380
assign_pin(1, 0); // Vdd
1382
assign_pin( 2, m_porta->addPin(new IO_bi_directional_pu("porta5"),5));
1383
assign_pin( 3, m_porta->addPin(new IO_bi_directional_pu("porta4"),4));
1384
assign_pin( 4, m_porta->addPin(new IOPIN("porta3"),3));
1385
assign_pin( 5, m_portc->addPin(new IO_bi_directional_pu("portc5"),5));
1386
assign_pin( 6, m_portc->addPin(new IO_bi_directional("portc4"),4));
1387
assign_pin( 7, m_portc->addPin(new IO_bi_directional("portc3"),3));
1389
assign_pin( 8, m_portc->addPin(new IO_bi_directional("portc2"),2));
1390
assign_pin( 9, m_portc->addPin(new IO_bi_directional("portc1"),1));
1391
assign_pin(10, m_portc->addPin(new IO_bi_directional("portc0"),0));
1393
assign_pin(11, m_porta->addPin(new IO_bi_directional_pu("porta2"),2));
1394
assign_pin(12, m_porta->addPin(new IO_bi_directional_pu("porta1"),1));
1395
assign_pin(13, m_porta->addPin(new IO_bi_directional_pu("porta0"),0));
1397
assign_pin(14, 0); //VSS
1399
tmr1l.setIOpin(&(*m_portc)[0]);
1402
Processor * P16F684::construct(const char *name)
1404
P16F684 *p = new P16F684(name);
1407
p->create_invalid_registers ();
1412
void P16F684::create(int eesize)
1416
_14bit_processor::create();
1418
osccon = new OSCCON(this, "osccon" );
1420
e = new EEPROM_WIDE(this,pir1);
1421
e->initialize(eesize);
1422
e->set_intcon(&intcon_reg);
1425
status->rp_mask = 0x60; // rp0 and rp1 are valid.
1426
indf->base_address_mask1 = 0x80; // used for indirect accesses above 0x100
1427
indf->base_address_mask2 = 0x1ff; // used for indirect accesses above 0x100
1429
P16F684::create_sfr_map();
1432
void P16F684::create_sfr_map()
1434
pir_set_def.set_pir1(pir1);
1436
add_file_registers(0x20, 0x7f, 0);
1437
add_file_registers(0xa0, 0xbf, 0);
1438
alias_file_registers(0x70, 0x7f, 0x80);
1440
add_SfrReg(indf, 0x00);
1441
alias_file_registers(0x00,0x00,0x80);
1443
add_SfrReg(&tmr0, 0x01);
1444
add_SfrReg(option_reg, 0x81, RegisterValue(0xff,0));
1446
add_SfrReg(pcl, 0x02, RegisterValue(0,0));
1447
add_SfrReg(status, 0x03, RegisterValue(0x18,0));
1448
add_SfrReg(fsr, 0x04);
1449
alias_file_registers(0x02,0x04,0x80);
1451
add_SfrReg(m_porta, 0x05);
1452
add_SfrReg(m_trisa, 0x85, RegisterValue(0x3f,0));
1454
add_SfrReg(m_portc, 0x07);
1455
add_SfrReg(m_trisc, 0x87, RegisterValue(0xff,0));
1457
add_SfrReg(pclath, 0x0a, RegisterValue(0,0));
1458
add_SfrReg(&intcon_reg, 0x00b, RegisterValue(0,0));
1460
alias_file_registers(0x0a,0x0b,0x80);
1461
add_SfrReg(pir1, 0x0c, RegisterValue(0,0));
1462
add_SfrReg(&tmr1l, 0x0e, RegisterValue(0,0), "tmr1l");
1463
add_SfrReg(&tmr1h, 0x0f, RegisterValue(0,0), "tmr1h");
1464
add_SfrReg(&t1con, 0x10, RegisterValue(0,0));
1465
add_SfrReg(&tmr2, 0x11, RegisterValue(0,0));
1466
add_SfrReg(&t2con, 0x12, RegisterValue(0,0));
1467
add_SfrReg(&ccpr1l, 0x13, RegisterValue(0,0));
1468
add_SfrReg(&ccpr1h, 0x14, RegisterValue(0,0));
1469
add_SfrReg(&ccp1con, 0x15, RegisterValue(0,0));
1470
add_SfrReg(&pwm1con, 0x16, RegisterValue(0,0));
1471
add_SfrReg(&eccpas, 0x17, RegisterValue(0,0));
1472
add_SfrReg(&wdtcon, 0x18, RegisterValue(0x08,0));
1473
add_SfrReg(&comparator.cmcon, 0x19, RegisterValue(0,0), "cmcon0");
1474
add_SfrReg(&comparator.cmcon1, 0x1a, RegisterValue(0,0), "cmcon1");
1475
add_SfrReg(&adresh, 0x1e, RegisterValue(0,0));
1476
add_SfrReg(&adcon0, 0x1f, RegisterValue(0,0));
1478
add_SfrReg(&pie1, 0x8c, RegisterValue(0,0));
1479
add_SfrReg(&pcon, 0x8e, RegisterValue(0,0));
1480
add_SfrReg(osccon, 0x8f, RegisterValue(0x60,0));
1482
add_SfrReg(&osctune, 0x90, RegisterValue(0,0),"osctune");
1483
add_SfrReg(&ansel, 0x91, RegisterValue(0xff,0));
1484
add_SfrReg(&pr2, 0x92, RegisterValue(0xff,0));
1485
add_SfrReg(m_wpua, 0x95, RegisterValue(0x37,0),"wpua");
1486
add_SfrReg(m_ioca, 0x96, RegisterValue(0,0),"ioca");
1487
add_SfrReg(&comparator.vrcon, 0x99, RegisterValue(0,0),"vrcon");
1488
add_SfrReg(get_eeprom()->get_reg_eedata(), 0x9a);
1489
add_SfrReg(get_eeprom()->get_reg_eeadr(), 0x9b);
1490
add_SfrReg(get_eeprom()->get_reg_eecon1(), 0x9c, RegisterValue(0,0));
1491
add_SfrReg(get_eeprom()->get_reg_eecon2(), 0x9d);
1492
add_SfrReg(&adresl, 0x9e, RegisterValue(0,0));
1493
add_SfrReg(&adcon1, 0x9f, RegisterValue(0,0));
1495
ansel.setAdcon1(&adcon1);
1496
ansel.setValidBits(0xff);
1498
// Link the comparator and voltage ref to porta
1499
comparator.initialize(&pir_set_def, NULL,
1500
&(*m_porta)[0], &(*m_porta)[1], // AN0 AN1
1502
&(*m_porta)[2], &(*m_portc)[4]); //OUT0 OUT1
1504
comparator.cmcon.setINpin(2, &(*m_portc)[0], "an4"); //AN4
1505
comparator.cmcon.setINpin(3, &(*m_portc)[1], "an5"); //AN5
1507
comparator.cmcon.set_tmrl(&tmr1l);
1508
comparator.cmcon1.set_tmrl(&tmr1l);
1510
comparator.cmcon.set_configuration(1, 0, AN0, AN1, AN0, AN1, ZERO);
1511
comparator.cmcon.set_configuration(2, 0, AN2, AN3, AN2, AN3, ZERO);
1512
comparator.cmcon.set_configuration(1, 1, AN1, AN2, AN0, AN2, NO_OUT);
1513
comparator.cmcon.set_configuration(2, 1, AN3, AN2, AN3, AN2, NO_OUT);
1514
comparator.cmcon.set_configuration(1, 2, AN1, VREF, AN0, VREF, NO_OUT);
1515
comparator.cmcon.set_configuration(2, 2, AN3, VREF, AN2, VREF, NO_OUT);
1516
comparator.cmcon.set_configuration(1, 3, AN1, AN2, AN1, AN2, NO_OUT);
1517
comparator.cmcon.set_configuration(2, 3, AN3, AN2, AN3, AN2, NO_OUT);
1518
comparator.cmcon.set_configuration(1, 4, AN1, AN0, AN1, AN0, NO_OUT);
1519
comparator.cmcon.set_configuration(2, 4, AN3, AN2, AN3, AN2, NO_OUT);
1520
comparator.cmcon.set_configuration(1, 5, NO_IN, NO_IN, NO_IN, NO_IN, ZERO);
1521
comparator.cmcon.set_configuration(2, 5, AN3, AN2, AN3, AN2, NO_OUT);
1522
comparator.cmcon.set_configuration(1, 6, AN1, AN2, AN1, AN2, OUT0);
1523
comparator.cmcon.set_configuration(2, 6, AN3, AN2, AN3, AN2, OUT1);
1524
comparator.cmcon.set_configuration(1, 7, NO_IN, NO_IN, NO_IN, NO_IN, ZERO);
1525
comparator.cmcon.set_configuration(2, 7, NO_IN, NO_IN, NO_IN, NO_IN, ZERO);
1526
comparator.vrcon.setValidBits(0xaf);
1528
adcon0.setAdresLow(&adresl);
1529
adcon0.setAdres(&adresh);
1530
adcon0.setAdcon1(&adcon1);
1531
adcon0.setIntcon(&intcon_reg);
1532
adcon0.setA2DBits(10);
1533
adcon0.setPir(pir1);
1534
adcon0.setChannel_Mask(7);
1535
adcon0.setChannel_shift(2);
1537
adcon1.setAdcon0(&adcon0); // VCFG0, VCFG1 in adcon0
1538
adcon1.setNumberOfChannels(8);
1539
adcon1.setIOPin(0, &(*m_porta)[0]);
1540
adcon1.setIOPin(1, &(*m_porta)[1]);
1541
adcon1.setIOPin(2, &(*m_porta)[2]);
1542
adcon1.setIOPin(3, &(*m_porta)[4]);
1543
adcon1.setIOPin(4, &(*m_portc)[0]);
1544
adcon1.setIOPin(5, &(*m_portc)[1]);
1545
adcon1.setIOPin(6, &(*m_portc)[2]);
1546
adcon1.setIOPin(7, &(*m_portc)[3]);
1547
adcon1.setVrefHiConfiguration(2, 1);
1548
intcon = &intcon_reg;
1549
intcon_reg.set_pir_set(get_pir_set());
1551
tmr1l.tmrh = &tmr1h;
1552
tmr1l.t1con = &t1con;
1553
// FIXME -- can't delete this new'd item
1554
tmr1l.setInterruptSource(new InterruptSource(pir1, PIR1v3::TMR1IF));
1555
tmr1h.tmrl = &tmr1l;
1556
t1con.tmrl = &tmr1l;
1558
tmr1l.setIOpin(&(*m_porta)[5]);
1559
tmr1l.setGatepin(&(*m_porta)[4]);
1563
pir1->set_intcon(&intcon_reg);
1564
pir1->set_pie(&pie1);
1569
tmr2.pir_set = get_pir_set();
1571
tmr2.t2con = &t2con;
1572
tmr2.add_ccp ( &ccp1con );
1575
eccpas.setIOpin(0, 0, &(*m_portc)[5]);
1576
eccpas.link_registers(&pwm1con, &ccp1con);
1578
ccp1con.setIOpin(&(*m_portc)[5], &(*m_portc)[4], &(*m_portc)[3], &(*m_portc)[2]);
1579
ccp1con.setBitMask(0xff);
1580
ccp1con.pstrcon = &pstrcon;
1581
ccp1con.pwm1con = &pwm1con;
1582
ccp1con.setCrosslinks(&ccpr1l, pir1, PIR1v2::CCP1IF, &tmr2, &eccpas);
1583
ccpr1l.ccprh = &ccpr1h;
1584
ccpr1l.tmrl = &tmr1l;
1585
ccpr1h.ccprl = &ccpr1l;
1587
osccon->set_osctune(&osctune);
1588
osctune.set_osccon(osccon);
1591
void P16F684::option_new_bits_6_7(uint bits)
1593
m_wpua->set_wpu_pu( (bits & OPTION_REG::BIT7) != OPTION_REG::BIT7);
1594
m_porta->setIntEdge((bits & OPTION_REG::BIT6) == OPTION_REG::BIT6);
1597
void P16F684::create_config_memory()
1599
m_configMemory = new ConfigMemory(this,1);
1600
m_configMemory->addConfigWord(0,new ConfigF631((P16F631*)this));
1601
wdt.initialize(true); // default WDT enabled
1602
wdt.set_timeout(0.000035);
1603
set_config_word(0x2007, 0x3fff);
1606
bool P16F684::set_config_word(uint address, uint cfg_word)
1617
if(address == config_word_address())
1619
config_clock_mode = (cfg_word & (CFG_FOSC0 | CFG_FOSC1 | CFG_FOSC2));
1622
osccon->set_config_xosc(config_clock_mode < 3);
1623
osccon->set_config_irc(config_clock_mode == 4 || config_clock_mode == 5);
1624
osccon->set_config_ieso(cfg_word & CFG_IESO);
1626
uint valid_pins = m_porta->getEnableMask();
1628
if ((cfg_word & CFG_MCLRE) == CFG_MCLRE) assignMCLRPin(4);
1629
else unassignMCLRPin();
1631
wdt.initialize((cfg_word & CFG_WDTE) == CFG_WDTE);
1635
// AnalogReq is used so ADC does not change clock names
1636
// set_config_word is first called with default and then
1637
// often called a second time. the following call is to
1638
// reset porta so next call to AnalogReq sill set the pin name
1640
(&(*m_porta)[4])->AnalogReq((Register *)this, false, "porta4");
1642
switch(config_clock_mode)
1645
case 0: // LP oscillator: low power crystal is on RA4 and RA5
1646
case 1: // XT oscillator: crystal/resonator is on RA4 and RA5
1647
case 2: // HS oscillator: crystal/resonator is on RA4 and RA5
1648
(&(*m_porta)[4])->AnalogReq((Register *)this, true, "OSC2");
1652
case 3: // EC I/O on RA4 pin, CLKIN on RA5
1657
case 5: // INTOSC CLKOUT on RA4 pin
1658
(&(*m_porta)[4])->AnalogReq((Register *)this, true, "CLKOUT");
1661
osccon->set_rc_frequency();
1664
case 6: //RC oscillator: I/O on RA4 pin, RC on RA5
1668
case 7: // RC oscillator: CLKOUT on RA4 pin, RC on RA5
1669
(&(*m_porta)[4])->AnalogReq((Register *)this, true, "CLKOUT");
1674
if (valid_pins != m_porta->getEnableMask()) // enable new pins for IO
1676
m_porta->setEnableMask(valid_pins);
1677
m_trisa->setEnableMask(valid_pins);
1683
//========================================================================
1685
Processor* P16F677::construct( const char *name )
1687
P16F677* p = new P16F677( name );
1691
p->create_sfr_map();
1692
p->create_invalid_registers ();
1697
P16F677::P16F677(const char *_name )
1700
anselh(this,"anselh" ),
1701
adresh(this,"adresh" ),
1702
adresl(this,"adresl" )
1708
delete_file_registers(0x20,0x3f);
1709
delete_file_registers(0xa0,0xbf);
1711
remove_SfrReg(&anselh);
1715
remove_SfrReg(&ssp.sspbuf);
1716
remove_SfrReg(&ssp.sspcon);
1717
remove_SfrReg(&ssp.sspadd);
1718
remove_SfrReg(&ssp.sspstat);
1720
remove_SfrReg(&adresl);
1721
remove_SfrReg(&adresh);
1722
remove_SfrReg(&adcon0);
1723
remove_SfrReg(&adcon1);
1728
void P16F677::create_sfr_map()
1730
ansel.setAdcon1(&adcon1);
1731
ansel.setAnselh(&anselh);
1732
anselh.setAdcon1(&adcon1);
1733
anselh.setAnsel(&ansel);
1734
anselh.setValidBits(0x0f);
1735
ansel.setValidBits(0xff);
1736
adcon0.setAdresLow(&adresl);
1737
adcon0.setAdres(&adresh);
1738
adcon0.setAdcon1(&adcon1);
1739
adcon0.setIntcon(&intcon_reg);
1740
adcon0.setA2DBits(10);
1741
adcon0.setPir(pir1);
1742
adcon0.setChannel_Mask(0xf);
1743
adcon0.setChannel_shift(2);
1745
adcon0.setValidBits(0xff);
1747
adcon1.setValidBits(0xb0);
1748
adcon1.setAdcon0(&adcon0);
1749
adcon1.setNumberOfChannels(14);
1750
adcon1.setValidCfgBits(ADCON1::VCFG0 , 6);
1751
adcon1.setIOPin(2, &(*m_porta)[2]);
1752
adcon1.setIOPin(3, &(*m_porta)[4]);
1754
adcon1.setIOPin(8, &(*m_portc)[6]);
1755
adcon1.setIOPin(9, &(*m_portc)[7]);
1756
adcon1.setIOPin(10, &(*m_portb)[4]);
1757
adcon1.setIOPin(11, &(*m_portb)[5]);
1758
adcon1.setVoltRef(12, 0.0);
1759
adcon1.setVoltRef(13, 0.0);
1760
adcon1.setVrefHiConfiguration(2, 1); // set a2d modes where an1 is Vref+
1762
add_SfrReg(&anselh, 0x11f, RegisterValue(0x0f,0));
1763
add_file_registers(0x20,0x3f,0);
1764
add_file_registers(0xa0,0xbf,0);
1768
add_SfrReg(&ssp.sspbuf, 0x13, RegisterValue(0,0),"sspbuf");
1769
add_SfrReg(&ssp.sspcon, 0x14, RegisterValue(0,0),"sspcon");
1770
add_SfrReg(&ssp.sspadd, 0x93, RegisterValue(0,0),"sspadd");
1771
add_SfrReg(&ssp.sspstat, 0x94, RegisterValue(0,0),"sspstat");
1774
get_pir_set(), // PIR
1775
&(*m_portb)[6], // SCK
1776
&(*m_portc)[6], // SS
1777
&(*m_portc)[7], // SDO
1778
&(*m_portb)[4], // SDI
1779
m_trisb, // i2c tris port
1783
add_SfrReg(&adresl, 0x9e, RegisterValue(0,0));
1784
add_SfrReg(&adresh, 0x1e, RegisterValue(0,0));
1785
add_SfrReg(&adcon0, 0x1f, RegisterValue(0,0));
1786
add_SfrReg(&adcon1, 0x9f, RegisterValue(0,0));
1788
//========================================================================
1793
Processor* P16F685::construct(const char *name)
1795
P16F685 *p = new P16F685(name);
1798
p->create_sfr_map();
1799
p->create_invalid_registers ();
1804
P16F685::P16F685(const char *_name )
1806
t2con(this, "t2con" ),
1808
tmr2(this, "tmr2" ),
1809
tmr1l(this, "tmr1l" ),
1810
tmr1h(this, "tmr1h" ),
1811
ccp1con(this, "ccp1con" ),
1812
ccpr1l(this, "ccpr1l" ),
1813
ccpr1h(this, "ccpr1h" ),
1814
pcon(this, "pcon" ),
1815
eccpas(this, "eccpas" ),
1816
pwm1con(this, "pwm1con" ),
1817
pstrcon(this, "pstrcon" )
1824
delete_file_registers(0xc0,0xef);
1825
delete_file_registers(0x120,0x16f);
1826
remove_SfrReg(&pstrcon);
1827
remove_SfrReg(&tmr2);
1828
remove_SfrReg(&t2con);
1829
remove_SfrReg(&pr2);
1830
remove_SfrReg(&ccpr1l);
1831
remove_SfrReg(&ccpr1h);
1832
remove_SfrReg(&ccp1con);
1833
remove_SfrReg(&pwm1con);
1834
remove_SfrReg(&eccpas);
1837
void P16F685::create_sfr_map()
1839
P16F677::create_sfr_map();
1841
add_SfrReg(get_eeprom()->get_reg_eedatah(), 0x10e );
1842
add_SfrReg(get_eeprom()->get_reg_eeadrh(), 0x10f);
1844
// Enable program memory reads and writes.
1845
get_eeprom()->get_reg_eecon1()->set_bits(EECON1::EEPGD);
1848
add_SfrReg(&tmr2, 0x11, RegisterValue(0,0));
1849
add_SfrReg(&t2con, 0x12, RegisterValue(0,0));
1850
add_SfrReg(&pr2, 0x92, RegisterValue(0xff,0));
1852
tmr2.pir_set = get_pir_set();
1854
tmr2.t2con = &t2con;
1855
tmr2.add_ccp ( &ccp1con );
1858
eccpas.setIOpin(0, 0, &(*m_portb)[0]);
1859
eccpas.link_registers(&pwm1con, &ccp1con);
1860
add_SfrReg(&pstrcon, 0x19d, RegisterValue(1,0));
1862
ccp1con.setIOpin(&(*m_portc)[5], &(*m_portc)[4], &(*m_portc)[3], &(*m_portc)[2]);
1863
ccp1con.setBitMask(0xff);
1864
ccp1con.pstrcon = &pstrcon;
1865
ccp1con.pwm1con = &pwm1con;
1866
ccp1con.setCrosslinks(&ccpr1l, pir1, PIR1v2::CCP1IF, &tmr2, &eccpas);
1867
ccpr1l.ccprh = &ccpr1h;
1868
ccpr1l.tmrl = &tmr1l;
1869
ccpr1h.ccprl = &ccpr1l;
1871
add_SfrReg(&ccpr1l, 0x15, RegisterValue(0,0));
1872
add_SfrReg(&ccpr1h, 0x16, RegisterValue(0,0));
1873
add_SfrReg(&ccp1con, 0x17, RegisterValue(0,0));
1875
add_SfrReg(&pwm1con, 0x1c, RegisterValue(0,0));
1876
add_SfrReg(&eccpas, 0x1d, RegisterValue(0,0));
1877
// add_file_registers(0x20,0x3f,0);
1878
// add_file_registers(0xa0,0xef,0);
1879
add_file_registers(0xc0,0xef,0);
1880
add_file_registers(0x120,0x16f,0);
1884
//========================================================================
1889
Processor * P16F687::construct(const char *name)
1891
P16F687 *p = new P16F687(name);
1894
p->create_sfr_map();
1895
p->create_invalid_registers ();
1900
P16F687::P16F687(const char *_name )
1902
tmr1l(this, "tmr1l" ),
1903
tmr1h(this, "tmr1h" ),
1904
pcon(this, "pcon" ),
1912
remove_SfrReg(&usart.rcsta);
1913
remove_SfrReg(&usart.txsta);
1914
remove_SfrReg(&usart.spbrg);
1915
remove_SfrReg(&usart.spbrgh);
1916
remove_SfrReg(&usart.baudcon);
1917
delete_SfrReg(usart.txreg);
1918
delete_SfrReg(usart.rcreg);
1921
void P16F687::create_sfr_map()
1923
P16F677::create_sfr_map();
1925
add_SfrReg(get_eeprom()->get_reg_eedatah(), 0x10e);
1926
add_SfrReg(get_eeprom()->get_reg_eeadrh(), 0x10f);
1928
// add_file_registers(0x20,0x3f,0);
1929
// add_file_registers(0xa0,0xbf,0);
1931
usart.initialize(pir1,&(*m_portb)[7], &(*m_portb)[5],
1932
new _TXREG(this,"txreg", &usart),
1933
new _RCREG(this,"rcreg", &usart));
1935
add_SfrReg(&usart.rcsta, 0x18, RegisterValue(0,0),"rcsta");
1936
add_SfrReg(&usart.txsta, 0x98, RegisterValue(2,0),"txsta");
1937
add_SfrReg(&usart.spbrg, 0x99, RegisterValue(0,0),"spbrg");
1938
add_SfrReg(&usart.spbrgh, 0x9a, RegisterValue(0,0),"spbrgh");
1939
add_SfrReg(&usart.baudcon, 0x9b,RegisterValue(0x40,0),"baudctl");
1940
add_SfrReg(usart.txreg, 0x19, RegisterValue(0,0),"txreg");
1941
add_SfrReg(usart.rcreg, 0x1a, RegisterValue(0,0),"rcreg");
1942
usart.set_eusart(true);
1945
//========================================================================
1950
Processor * P16F689::construct(const char *name)
1952
P16F689 *p = new P16F689(name);
1955
p->create_sfr_map();
1956
p->create_invalid_registers ();
1961
P16F689::P16F689(const char *_name )
1967
//========================================================================
1969
Processor * P16F690::construct(const char *name)
1971
P16F690 *p = new P16F690(name);
1974
p->create_sfr_map();
1975
p->create_invalid_registers ();
1980
P16F690::P16F690(const char *_name )
1982
ccp2con(this, "ccp2con" ),
1983
ccpr2l(this, "ccpr2l" ),
1984
ccpr2h(this, "ccpr2h" ),
1992
remove_SfrReg(&usart.rcsta);
1993
remove_SfrReg(&usart.txsta);
1994
remove_SfrReg(&usart.spbrg);
1995
remove_SfrReg(&usart.spbrgh);
1996
remove_SfrReg(&usart.baudcon);
1997
delete_SfrReg(usart.txreg);
1998
delete_SfrReg(usart.rcreg);
2001
void P16F690::create_sfr_map()
2003
P16F685::create_sfr_map();
2005
tmr2.ssp_module[0] = &ssp;
2006
eccpas.setIOpin(0, 0, &(*m_portb)[0]);
2007
eccpas.link_registers( &pwm1con, &ccp1con );
2009
usart.initialize( pir1,&(*m_portb)[7], &(*m_portb)[5],
2010
new _TXREG( this,"txreg", &usart ),
2011
new _RCREG( this,"rcreg", &usart ));
2013
add_SfrReg( &usart.rcsta, 0x18, RegisterValue(0,0),"rcsta");
2014
add_SfrReg( &usart.txsta, 0x98, RegisterValue(2,0),"txsta");
2015
add_SfrReg( &usart.spbrg, 0x99, RegisterValue(0,0),"spbrg");
2016
add_SfrReg( &usart.spbrgh, 0x9a, RegisterValue(0,0),"spbrgh");
2017
add_SfrReg( &usart.baudcon, 0x9b,RegisterValue(0x40,0),"baudctl");
2018
add_SfrReg( usart.txreg, 0x19, RegisterValue(0,0),"txreg");
2019
add_SfrReg( usart.rcreg, 0x1a, RegisterValue(0,0),"rcreg");
2020
usart.set_eusart(true);