Esempio n. 1
0
void enter_ISCP_PIC24E()
{

    enablePGC_D(); //PGC/D output & PGC/D_LOW appropriate

    VPP_RUNoff(); //MCLR low
    VDDon();
    clock_delay();              // P6 100ns    DelayMs( 10 );
    VPP_RUNon(); //VPP to 4.5V
    DelayMs( 1 );               //P21 500us        // PIC24E 500us min
    VPP_RUNoff(); //and immediately back to 0...
    VPP_RSTon();
    DelayMs( 2 );               //P18 = 1ms min        PIC24E 1ms min
    //write 0x4D43, high to low, other than the rest of the commands which are low to high...
    //0x4D43 => 0100 1101 0100 0011
    //from low to high => 1100 0010 1011 0010
    //0xC2B2
    pic_send_word( 0xC2B2 );
    //write 0x4851 => 0100 1000 0101 0001 => 1000 1010 0001 0010 => 0x8A12
    pic_send_word( 0x8A12 );
                                // P19 25ns   DelayMs( 1 );
    VPP_RSToff(); //release from reset
    VPP_RUNon();

    DelayMs( 60 );              // P7 50ms  + P1*5           //PIC24E 50ms min
    pic_send_n_bits( 5, 0 );
    dspic_send_24_bits( 0x000000 );     //NOP           //PIC24E (doc 70633) says 3 nops
    dspic_send_24_bits( 0x000000 );     //NOP
    dspic_send_24_bits( 0x000000 );     //NOP
    dspic_send_24_bits( 0x040200 );     //GOTO 0x200
    dspic_send_24_bits( 0x000000 );     //NOP
    dspic_send_24_bits( 0x000000 );     //NOP
    dspic_send_24_bits( 0x000000 );     //NOP
}
Esempio n. 2
0
void enter_ISCP_PIC24K()
{
	int i;

	enablePGC_D(); //PGC/D output & PGC/D_LOW appropriate

	VPP_RUNoff(); //MCLR low
	VDDon();
	DelayMs( 10 );
	VPP_RUNon(); //VPP to 4.5V
	for( i = 0; i < 300; i++ )
		continue; //aprox 0.5ms
	//clock_delay();	//P19 = 40ns min
	//write 0x4D43, high to low, other than the rest of the commands which are low to high...
	//0x3D43 => 0100 1101 0100 0011
	//from low to high => 1100 0010 1011 0010
	//0xC2B2
	pic_send_word( 0xC2B2 );
	//write 0x4851 => 0100 1000 0101 0001 => 1000 1010 0001 0010 => 0x0A12
	pic_send_word( 0x8A12 );
	DelayMs( 1 );

	DelayMs( 25 );
	pic_send_n_bits( 5, 0 );
	dspic_send_24_bits( 0 ); //send a nop instruction with 5 additional databits
	dspic_send_24_bits( 0x000000 ); 	//NOP
	dspic_send_24_bits( 0x040200 ); 	//GOTO 0x200
	dspic_send_24_bits( 0x000000 ); 	//NOP
}
Esempio n. 3
0
void enter_ISCP_PIC18J()
{
	int i;

	enablePGC_D(); //PGC/D output & PGC/D_LOW appropriate

	VPP_RUNoff(); //MCLR low
	VDDon();
	DelayMs( 10 );
	VPP_RUNon(); //VPP to 4.5V
	for( i = 0; i < 300; i++ )
		continue; //aprox 0.5ms
	VPP_RUNoff(); //and immediately back to 0...
	VPP_RSTon();
	DelayMs( 4 );		//FIXME: should be 4ms only?
	DelayMs( 6 );
	//clock_delay();	//P19 = 40ns min
	//write 0x4D43, high to low, other than the rest of the commands which are low to high...
	//0x3D43 => 0100 1101 0100 0011
	//from low to high => 1100 0010 1011 0010
	//0xC2B2
	pic_send_word( 0xC2B2 );
	//write 0x4850 => 0100 1000 0101 0000 => 0000 1010 0001 0010 => 0x0A12
	pic_send_word( 0x0A12 );
	DelayMs( 2 );
	VPP_RSToff(); //release from reset
	VPP_RUNon();
	DelayMs( 1 );

}
Esempio n. 4
0
void write_code_P18FX220( unsigned long address, unsigned char* data, char blocksize, char lastblock )
{
	unsigned int i;
	char blockcounter;

	//FIXME: this only needs to be done on FIRST_BLOCK
	//direct access to code memory
	pic_send( 4, 0x00, 0x8EA6 ); //BSF EECON1, EEPGD
	pic_send( 4, 0x00, 0x9CA6 ); //BCF EECON1, CFGS
	set_address_P18( address );
	for( blockcounter = 0; blockcounter < (blocksize); blockcounter += 8 ) //blocks of 8 bytes
	{
		for( i = 0; i < 6; i += 2 )
		{
			//write 2 bytes and post increment by 2
			//				MSB				LSB
			pic_send( 4, 0x0D, ((unsigned int) *(data + blockcounter + i)) | (((unsigned int) *(data + 1
					+ blockcounter + i)) << 8) );
		}
		//write last 2 bytes of the block and start programming
		pic_send( 4, 0x0F, ((unsigned int) *(data + blockcounter + 6)) | (((unsigned int) *(data + 7
				+ blockcounter)) << 8) );
		pic_send_n_bits( 3, 0 );
		PGChigh(); //hold PGC high for P9 and low for P10
		DelayMs( P9 );
		PGClow();
		DelayMs( P10 );
		pic_send_word( 0x0000 );
		pic_read_byte2( 4, 0x09 ); //perform 2 reads to increase the address by 2
		pic_read_byte2( 4, 0x09 );
	}

}
Esempio n. 5
0
void write_code_P18F4XK22( unsigned long address, unsigned char* data, char blocksize, char lastblock )
{
	char blockcounter;

	//FIXME: this only needs to be done on FIRST_BLOCK
	pic_send( 4, 0x00, 0x8EA6 ); //BSF EECON1, EEPGD
	pic_send( 4, 0x00, 0x9CA6 ); //BCF EECON1, CFGS
	pic_send( 4, 0x00, 0x84A6 ); //BSF EECON1, WREN
	set_address_P18( address );
	for( blockcounter = 0; blockcounter < (blocksize - 2); blockcounter += 2 )
	{
		//write 2 bytes and post increment by 2
		//				MSB				LSB
		pic_send( 4, 0x0D, ((unsigned int) *(data + blockcounter))
				| (((unsigned int) *(data + 1 + blockcounter)) << 8) );
	}
	//write last 2 bytes of the block and start programming
	pic_send( 4, 0x0F, ((unsigned int) *(data + blockcounter)) | (((unsigned int) *(data + 1 + blockcounter)) << 8) );
	pic_send_n_bits( 3, 0 );
	PGChigh(); //hold PGC high for P9 and low for P10
	DelayMs( P9 );
	PGClow();
	DelayMs( P10 );
	pic_send_word( 0x0000 );
}
Esempio n. 6
0
void write_code_P18F6XKXX( unsigned long address, unsigned char* data, char blocksize, char lastblock )
{
	char blockcounter;

	//FIXME: this only needs to be done on FIRST_BLOCK
	if( (address & 0x20) == 0 ) //package must be 64 bytes, so only do this every two packages.
	{
		pic_send( 4, 0x00, 0x8E7F ); //BSF EECON1, EEPGD
		pic_send( 4, 0x00, 0x9C7F ); //BSF EECON1, CFGS
		pic_send( 4, 0x00, 0x847F ); //BSF EECON1, WREN
		set_address_P18( address );
	}
	for( blockcounter = 0; blockcounter < (blocksize - 2); blockcounter += 2 )
	{
		//write 2 bytes and post increment by 2
		//				MSB				LSB
		pic_send( 4, 0x0D, ((unsigned int) *(data + blockcounter))
				| (((unsigned int) *(data + 1 + blockcounter)) << 8) );
	}
	if( (address & 0x20) == 0x20 || (lastblock & BLOCKTYPE_LAST) )
	{
		//write last 2 bytes of the block and start programming
		pic_send( 4, 0x0F, ((unsigned int) *(data + blockcounter))
				| (((unsigned int) *(data + 1 + blockcounter)) << 8) );
		pic_send_n_bits( 3, 0 );
		PGChigh(); //hold PGC high for P9 and low for P10
		DelayMs( P9 );
		PGClow();
		DelayMs( P10 );
		pic_send_word( 0x0000 );
	}
	else
		pic_send( 4, 0x0D, ((unsigned int) *(data + blockcounter))
				| (((unsigned int) *(data + 1 + blockcounter)) << 8) );
}
Esempio n. 7
0
void write_code_P18F45J10( unsigned long address, unsigned char* data, char blocksize, char lastblock )
{

	char blockcounter;

	if( !(address & 0x20) )
	{
		pic_send( 4, 0x00, 0x84A6 ); //BSF EECON1, WREN
		set_address_P18( address ); //blocks of 64 bytes, but divided into two chunks
	}
	for( blockcounter = 0; blockcounter < (blocksize - 2); blockcounter += 2 )
	{
		//write 2 bytes and post increment by 2
		//				MSB				LSB
		pic_send( 4, 0x0D, ((unsigned int) *(data + blockcounter))
				| (((unsigned int) *(data + 1 + blockcounter)) << 8) );
	}
	//write last 2 bytes of the block and start programming
	if( address & 0x20 )
	{
		pic_send( 4, 0x0F, ((unsigned int) *(data + blockcounter))
				| (((unsigned int) *(data + 1 + blockcounter)) << 8) );
		pic_send_n_bits( 3, 0 );
		PGChigh(); //hold PGC high for P9 and low for P10
		DelayMs( 10 );
		PGClow();
		DelayMs( 1 );
		pic_send_word( 0x0000 );
	}
	else
	{
		pic_send( 4, 0x0D, ((unsigned int) *(data + blockcounter))
				| (((unsigned int) *(data + 1 + blockcounter)) << 8) );
		if( lastblock & BLOCKTYPE_LAST ) //if the last block is the first half of 64 bytes, it needs to be finished with a dummy block to finish.
		{
			for( blockcounter = 0; blockcounter < 30; blockcounter += 2 )
				pic_send( 4, 0x0D, 0xFFFF );
			pic_send( 4, 0x0F, 0xFFFF );
			pic_send_n_bits( 3, 0 );
			PGChigh(); //hold PGC high for P9 and low for P10
			DelayMs( 10 );
			PGClow();
			DelayMs( 1 );
			pic_send_word( 0x0000 );
		}
	}
}
Esempio n. 8
0
void enter_ISCP_PIC18K()
{
	int i;

	enablePGC_D(); //PGC/D output & PGC/D_LOW appropriate

	// Enter low voltage programming mode:
	// Pulse MCLR low, then high, then low
	VPP_RUNoff(); // MCLR low
	VPP_RSTon(); // Force MCLR low
	DelayMs( 1 ); // Small delay

	// Turn VDD supply on
	VDDon();
	DelayMs( 10 ); // Allow voltage to stabilize

	// MCLR high
	VPP_RSToff(); // Release from reset
	VPP_RUNon(); // VPP to 4.5V
	DelayMs( 3 ); // Allow to stabilize

	// MCLR low, and write secret word
	VPP_RUNoff(); //MCLR low (this would enter low power mode)
 	VPP_RSTon(); // Force MCLR low (this would enter low power mode)
	for( i = 0; i < 300; i++ )
		continue; //aprox 0.5ms
	//clock_delay();	//P19 = 40ns min
	//write 0x4D43, high to low, other than the rest of the commands which are low to high...
	//0x3D43 => 0100 1101 0100 0011
	//from low to high => 1100 0010 1011 0010
	//0xC2B2
	pic_send_word( 0xC2B2 );
	//write 0x4850 => 0100 1000 0101 0000 => 0000 1010 0001 0010 => 0x0A12
	pic_send_word( 0x0A12 );

	// Turn MCLR back on
	DelayMs( 1 ); // <- IF ...
	VPP_RUNon(); // ... Low power ...
	VPP_RSToff(); // ... Mode is used ...
	DelayMs( 1 ); // Some time for MCLR to rise
}
Esempio n. 9
0
void write_code_P18FXX20( unsigned long address, unsigned char* data, char blocksize, char lastblock )
{
	unsigned int i;
	char blockcounter;
	if( lastblock & BLOCKTYPE_FIRST )
	{
		pic_send( 4, 0x00, 0x8EA6);// BSF EECON1, EEPGD
		pic_send( 4, 0x00, 0x8CA6);// BSF EECON1, CFGS
		pic_send( 4, 0x00, 0x86A6);// BSF EECON1, WREN
		set_address_P18( 0x3C0006 );
		pic_send( 4, 0x0C, 0x0040 ); //Write 40h to 3C0006h to enable multi-panel writes.
		//direct access to code memory
		pic_send( 4, 0x00, 0x8EA6 ); //BSF EECON1, EEPGD
		pic_send( 4, 0x00, 0x9CA6 ); //BCF EECON1, CFGS

	}
	
	set_address_P18( address );
	for( blockcounter = 0; blockcounter < (blocksize); blockcounter += 8 ) //blocks of 8 bytes
	{
		for( i = 0; i < 6; i += 2 )
		{
			//write 2 bytes and post increment by 2
			//				MSB				LSB
			pic_send( 4, 0x0D, ((unsigned int) *(data + blockcounter + i)) | (((unsigned int) *(data + 1
					+ blockcounter + i)) << 8) );
		}
		if((lastblock & BLOCKTYPE_LAST)&& (blockcounter==(blocksize-8)))
		{
			//write last 2 bytes of the block and start programming
			pic_send( 4, 0x0F, ((unsigned int) *(data + blockcounter + 6)) | (((unsigned int) *(data + 7
					+ blockcounter)) << 8) );
		}
		else
		{
			//write last 2 bytes of the block and start programming
			pic_send( 4, 0x0C, ((unsigned int) *(data + blockcounter + 6)) | (((unsigned int) *(data + 7
					+ blockcounter)) << 8) );
			pic_send_n_bits( 3, 0 );
			PGChigh(); //hold PGC high for P9 and low for P10
			DelayMs( P9 );
			PGClow();
			DelayMs( P10 );
			pic_send_word( 0x0000 );
		}
		pic_read_byte2( 4, 0x09 ); //perform 2 reads to increase the address by 2
		pic_read_byte2( 4, 0x09 );
	}

}