??? 07/03/05 16:37 Read: times |
#96473 - My Code Responding to: ???'s previous message |
unsigned char __api_wr_code_page (word16 add_flash, word16 add_xram, unsigned char nb_data_lc) small
{ //bit ea_save; byte save_auxr1,temp_lc,temp1_lc; word16 temp_lw; // ea_save = EA; EA = 0; save_auxr1 = AUXR1; P2_0 = ~P2_0; // watch dog strobe AUXR1 &= ~0x01; // Set DPTR0 to Destination Address DPL = (byte)add_flash; DPH = (byte)(add_flash >> 8); AUXR1 |= 0x01; // Set DPTR Addr. to DPTR1 DPL = (byte)add_xram; // Set DPTR1 to Source Address DPH = (byte)(add_xram >> 8); temp_lc = (K_FPAGE_MAX - (add_flash %K_FPAGE_MAX)); while(nb_data_lc) { P2_0 = ~P2_0; //Watch Dog Strobe if (nb_data_lc <temp_lc) // to test page boundary temp_lc = nb_data_lc; nb_data_lc -= temp_lc; #pragma asm MOV A,#0x09 MOV R1,A #pragma endasm ACC = temp_lc; AUXR1 &= ~0x01; // Set DPTR = DPTR0 MAP_BOOT; // Set ENBOOT bit in AUXR1 API_Flash_Start(); // Jump to API calls (FFF0h) if(nb_data_lc != 0) { AUXR1 &= ~0x01; // Set DPTR = DPTR0 temp_lw = add_flash + temp_lc; DPL = (byte) temp_lw; DPH = (byte)(temp_lw >> 8); temp1_lc = (K_FPAGE_MAX - (temp_lw % K_FPAGE_MAX)); AUXR1 |= 0x01; // Switch DPTR0 to DPTR1 temp_lw = add_xram + temp_lc; DPL = (byte)temp_lw; DPH = (byte)(temp_lw >> 8); temp_lc = temp1_lc; } UNMAP_BOOT; } AUXR1 = save_auxr1; EA = 1; // restore interrupt state return (ACC); } |