예제 #1
0
void write_code_P16F87( unsigned long address, unsigned char* data, char blocksize, char lastblock )
{
	unsigned int i;
	char blockcounter;
	if( (lastblock & BLOCKTYPE_FIRST) && (address > 0) )
	{
		set_address_P16( address ); //set the initial address
	}
	//4 word programming
	for( blockcounter = 0; blockcounter < blocksize; blockcounter += 8 ) //4 words of data = 8 bytes
	{
		for( i = 0; i < 8; i += 2 )
		{
			pic_send_14_bits( 6, 0x02, (((unsigned int) data[blockcounter + i])) | //MSB
					(((unsigned int) data[blockcounter + i + 1]) << 8) );//LSB
			if( i < 6 )
				pic_send_n_bits( 6, 0x06 ); //increment address
		}
		pic_send_n_bits( 6, 0x18 ); //begin programming only, externally timed
		DelayMs( 2 );
		pic_send_n_bits( 6, 0x17 ); //end programming
		//for(i=0;i<100;i++);		//wait Tdis
		pic_send_n_bits( 6, 0x06 ); //increment address
	}
}
예제 #2
0
void write_data_P16F87( unsigned long address, unsigned char* data, char blocksize, char lastblock )
{

	char blockcounter;

	if( (lastblock & BLOCKTYPE_FIRST) && (address > 0) )
	{
		set_address_P16( address ); //set the initial address
	}
	for( blockcounter = 0; blockcounter < blocksize; blockcounter++ )
	{
		//load data
		pic_send_14_bits( 6, 0x03, ((unsigned int) data[blockcounter]) );//LSB only
		//begin programming command
		pic_send_n_bits( 6, 0x18 );// begin programming only cycle
		//wait Tprog
		// 8MS, should be 20 ms for other?
		DelayMs( Tdprog );
		pic_send_n_bits( 6, 0x17 );//end programming

		//read data from data memory (to verify) not yet impl...
		//increment address
		pic_send_n_bits( 6, 0x06 );
	}
}
예제 #3
0
void write_code_P16F54( unsigned long address, unsigned char* data, char blocksize, char lastblock )
{

	char blockcounter;
	if( lastblock & BLOCKTYPE_FIRST )
	{
		pic_send_n_bits( 6, 0x06 );//increment address to go from 1FF / 3FF to 0
		set_address_P16( address ); //set the initial address
		//pic_send_n_bits(6,0x09);//bulk erase, which is necessary anyway...
		//DelayMs(20);
	}
	for( blockcounter = 0; blockcounter < blocksize; blockcounter += 2 )
	{
		pic_send_14_bits( 6, 0x02, (((unsigned int) data[blockcounter])) | //MSB
				(((unsigned int) data[blockcounter + 1]) << 8) );//LSB
		DelayMs( 1 );
		pic_send_n_bits( 6, 0x08 ); //begin programming
		DelayMs( 3 );
		pic_send_n_bits( 6, 0x0E ); //end programming
		DelayMs( 1 );
		//payload=pic_read_14_bits(6,0x04); //read code memory
		//if(payload!=((((unsigned int)data[blockcounter]))|(((unsigned int)data[blockcounter+1])<<8)))
		//{
		//	set_vdd_vpp(pictype,picfamily,0);
		//	return 4;//verify error.
		//}
		pic_send_n_bits( 6, 0x06 ); //increment address
	}
}
예제 #4
0
void write_code_P16C6XX( unsigned long address, unsigned char* data, char blocksize, char lastblock )
{

	char blockcounter;
	char i;
	unsigned int payload;
	if( (lastblock & BLOCKTYPE_FIRST) && (address > 0) )
	{
		set_address_P16( address ); //set the initial address
	}
	for( blockcounter = 0; blockcounter < blocksize; blockcounter += 2 )
	{
		for(i=0;i<25;i++)
		{
			payload = (((unsigned int) data[blockcounter])) | //MSB
				(((unsigned int) data[blockcounter + 1]) << 8);
			pic_send_14_bits( 6, 0x02,  payload);//LSB
		
			pic_send_n_bits( 6, 0x08 ); //begin programming
			DelayUs( 100 );
			pic_send_n_bits( 6, 0x0E ); //end programming
			if(pic_read_14_bits( 6, 0x04 )==payload&&i<22)i=22; //correct? do 3 more programming cycles.
		}
		pic_send_n_bits( 6, 0x06 ); //increment address
	}
}
예제 #5
0
void write_code_P16F84A( unsigned long address, unsigned char* data, char blocksize, char lastblock )
{

	char blockcounter;

	if( lastblock & BLOCKTYPE_FIRST )
	{
		set_address_P16( address ); //set the initial address
	}

	for( blockcounter = 0; blockcounter < blocksize; blockcounter += 2 )
	{
		pic_send_14_bits( 6, 0x02, (((unsigned int) data[blockcounter])) | //MSB
				(((unsigned int) data[blockcounter + 1]) << 8) );//LSB
		pic_send_n_bits( 6, 0x08 ); //begin programming
		DelayMs( Tprog );
		DelayMs( 10 );
		pic_send_n_bits( 6, 0x06 ); //increment address
	}
	/*if(pictype==P12F629&&((lastblock&2)&&((address+blocksize)<0x3FF))) //restore osccal register
	 {
	 for(i=0;i<(0x3FF-(address+blocksize));i++)
	 pic_send_n_bits(6,0x06);	//increment address
	 pic_send_14_bits(6,0x02,osccal);
	 pic_send_n_bits(6,0x08);    //begin programming, internally timed
	 DelayMs(8);
	 //pic_send_n_bits(6,0x0A); 	//end programming
	 }*/
}
예제 #6
0
void write_code_P12F61X( unsigned long address, unsigned char* data, char blocksize, char lastblock )
{

	char blockcounter;

	if( (lastblock & BLOCKTYPE_FIRST) && (address > 0) )
	{
		set_address_P16( address ); //set the initial address
	}
	for( blockcounter = 0; blockcounter < blocksize; blockcounter += 2 )
	{
		pic_send_14_bits( 6, 0x02, (((unsigned int) data[blockcounter])) | //MSB
				(((unsigned int) data[blockcounter + 1]) << 8) );//LSB
		pic_send_n_bits( 6, 0x18 ); //begin programming
		DelayMs( Tprog );
		pic_send_n_bits( 6, 0x0A ); //end programming
		DelayMs( 10 );
		/*payload=pic_read_14_bits(6,0x04); //read code memory
		 if(payload!=((((unsigned int)data[blockcounter]))|(((unsigned int)data[blockcounter+1])<<8)))
		 {
		 set_vdd_vpp(pictype, picfamily,0);	//do a hard reset to target processor
		 set_vdd_vpp(pictype, picfamily,1);
		 DelayMs(10);		//wait a while
		 set_address(picfamily, address+(blockcounter>>1)); //go back to the address where it was

		 pic_send_14_bits(6,0x02,(((unsigned int)data[blockcounter]))|   //MSB
		 (((unsigned int)data[blockcounter+1])<<8));//LSB
		 switch(pictype)
		 {
		 case P12F61X:
		 pic_send_n_bits(6,0x18);    //begin programming
		 DelayMs(Tprog);
		 pic_send_n_bits(6,0x0A);    //end programming
		 break;
		 default:
		 pic_send_n_bits(6,0x08);    //begin programming
		 DelayMs(Tprog);
		 break;
		 }
		 payload=pic_read_14_bits(6,0x04); //read code memory
		 if(payload!=((((unsigned int)data[blockcounter]))|(((unsigned int)data[blockcounter+1])<<8)))
		 {
		 return 4; //verify error
		 }
		 }*/
		pic_send_n_bits( 6, 0x06 ); //increment address
	}
	/*if(pictype==P12F629&&((lastblock&2)&&((address+blocksize)<0x3FF))) //restore osccal register
	 {
	 for(i=0;i<(0x3FF-(address+blocksize));i++)
	 pic_send_n_bits(6,0x06);	//increment address
	 pic_send_14_bits(6,0x02,osccal);
	 pic_send_n_bits(6,0x08);    //begin programming, internally timed
	 DelayMs(8);
	 //pic_send_n_bits(6,0x0A); 	//end programming
	 }*/
}
예제 #7
0
void set_address( PICFAMILY picfamily, unsigned long address )
{
	switch( picfamily ) {
	case PIC18:
	case PIC18J:
	case PIC18K:
		set_address_P18( address );
		break;
	case PIC10:
	case PIC16:
		set_address_P16( address );
	default:
		break;
	}
}
예제 #8
0
void write_code_P16F18XX( unsigned long address, unsigned char* data, char blocksize, char lastblock )
{

	char blockcounter;

	if( lastblock & BLOCKTYPE_FIRST )
	{
		pic_send_n_bits( 6, 0x16 ); //reset address
		set_address_P16( address ); //set the initial address
	}

	for( blockcounter = 0; blockcounter < blocksize; blockcounter += 2 )
	{
		pic_send_14_bits( 6, 0x02, (((unsigned int) data[blockcounter])) | //MSB
				(((unsigned int) data[blockcounter + 1]) << 8) );//LSB
		pic_send_n_bits( 6, 0x08 ); //begin programming
		DelayMs( Tprog );
		DelayMs( 10 );
		pic_send_n_bits( 6, 0x06 ); //increment address
	}
}
예제 #9
0
void write_code_P16F87XA( unsigned long address, unsigned char* data, char blocksize, char lastblock )
{
	unsigned int i;
	char blockcounter;
	if( (lastblock & BLOCKTYPE_FIRST) && (address > 0) )
	{
		set_address_P16( address ); //set the initial address
	}
	for( blockcounter = 0; blockcounter < blocksize; blockcounter += 16 ) //8 words of data = 16 bytes
	{
		for( i = 0; i < 16; i += 2 )
		{
			pic_send_14_bits( 6, 0x02, (((unsigned int) data[blockcounter + i])) | //MSB
					(((unsigned int) data[blockcounter + i + 1]) << 8) );//LSB
			if( i < 14 )
				pic_send_n_bits( 6, 0x06 ); //increment address
		}
		pic_send_n_bits( 6, 0x08 ); //begin erase / programming
		DelayMs( 16 );
		//pic_send_n_bits(5,0x17);    //end programming
		pic_send_n_bits( 6, 0x06 ); //increment address
	}
}