Beispiel #1
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 );
	}

}
Beispiel #2
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 );
}
Beispiel #3
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) );
}
Beispiel #4
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 );
		}
	}
}
Beispiel #5
0
void enter_ISCP_I2C_EE()
{
	enablePGC_D(); //PGC/D output & PGC/D_LOW appropriate

	PGDhigh();
	PGChigh();
	clock_delay(); // dummy tempo
	VDDon(); //no VPP needed
	DelayMs( 100 );
}
Beispiel #6
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 );
	}

}