Go to the source code of this file.
Data Structures | |
| struct | ICSP_CONTROL |
Defines | |
| #define | P2 1 |
| #define | P2A 1 |
| #define | P2B 1 |
| #define | P3 1 |
| #define | P4 1 |
| #define | P5 1 |
| #define | P5A 1 |
| #define | P6 1 |
| #define | P9 10 |
| #define | P10 100 |
| #define | P11 1000 |
| #define | P12 1 |
| #define | P13 1 |
| #define | P14 1 |
| #define | P16 1 |
| #define | P19 2 |
| #define | P20 1 |
| #define | ICSP_CORE_INSTRUCTION 0x00 |
| #define | ICSP_SHIFT_OUT_TABLAT_REIGSTER 0x02 |
| #define | ICSP_TABLE_READ 0x08 |
| #define | ICSP_TABLE_READ_POST_INC 0x09 |
| #define | ICSP_TABLE_READ_POST_DEC 0x0a |
| #define | ICSP_TABLE_READ_PRE_INC 0x0b |
| #define | ICSP_TABLE_WRITE 0x0c |
| #define | ICSP_TABLE_WRITE_POST_INC2 0x0d |
| #define | ICSP_TABLE_WRITE_PROG_POST_INC2 0x0e |
| #define | ICSP_TABLE_WRITE_PROG 0x0f |
Functions | |
| void | F_IcspInit (void) |
| void | F_IcspProgramModeEnter (void) |
| void | F_IcspProgramModeExit (void) |
| void | F_IcspInstructionSend (U32 Instruction) |
| void | F_IcspSignatureSend (void) |
| void | F_IcspTest (void) |
| void | F_IcspBulkErase (void) |
| void | F_IcspPageProgram (void) |
| void | F_IcspReset (void) |
| void | F_IcspBufferDump (void) |
Variables | |
| ICSP_CONTROL | IcspCtrl |
| void F_IcspBufferDump | ( | void | ) |
| void F_IcspBulkErase | ( | void | ) |
Definition at line 168 of file icsp.c.
00168 { 00169 U32 i; 00170 U8 j; 00171 00172 i=ICSP_CORE_INSTRUCTION+0x0e3c*0x10; // movlw 3ch 00173 F_IcspInstructionSend(i); 00174 i=ICSP_CORE_INSTRUCTION+0x6ef8*0x10; // movwf tblptru 00175 F_IcspInstructionSend(i); 00176 i=ICSP_CORE_INSTRUCTION+0x0e00*0x10; // movlw 00h 00177 F_IcspInstructionSend(i); 00178 i=ICSP_CORE_INSTRUCTION+0x6ef7*0x10; // movwf tblptrh 00179 F_IcspInstructionSend(i); 00180 i=ICSP_CORE_INSTRUCTION+0x0e05*0x10; // movlw 05 00181 F_IcspInstructionSend(i); 00182 i=ICSP_CORE_INSTRUCTION+0x6ef6*0x10; // movwf tblptrl 00183 F_IcspInstructionSend(i); 00184 i=ICSP_TABLE_WRITE+0x0101*0x10; // write 01 to 3c0005 00185 F_IcspInstructionSend(i); 00186 i=ICSP_CORE_INSTRUCTION+0x0e3c*0x10; // movlw 3ch 00187 F_IcspInstructionSend(i); 00188 i=ICSP_CORE_INSTRUCTION+0x6ef8*0x10; // movwf tblptru 00189 F_IcspInstructionSend(i); 00190 i=ICSP_CORE_INSTRUCTION+0x0e00*0x10; // movlw 00h 00191 F_IcspInstructionSend(i); 00192 i=ICSP_CORE_INSTRUCTION+0x6ef7*0x10; // movwf tblptrh 00193 F_IcspInstructionSend(i); 00194 i=ICSP_CORE_INSTRUCTION+0x0e04*0x10; // movlw 05 00195 F_IcspInstructionSend(i); 00196 i=ICSP_CORE_INSTRUCTION+0x6ef6*0x10; // movwf tblptrl 00197 F_IcspInstructionSend(i); 00198 i=ICSP_TABLE_WRITE+0x8080*0x10; // write 80 to 3c0004 00199 F_IcspInstructionSend(i); 00200 i=ICSP_CORE_INSTRUCTION+0x0000*0x10; // nop 00201 F_IcspInstructionSend(i); 00202 F_IcspPgdLow(); 00203 for(j=0;j<4;j++){ 00204 F_IcspPgcHigh(); 00205 F_IcspPgcLow(); 00206 } 00207 Sleep(P11); // delay 475 ms 00208 for(j=0;j<16;j++){ 00209 F_IcspPgcHigh(); 00210 F_IcspPgcLow(); 00211 } 00212 }
| void F_IcspInit | ( | void | ) |
Definition at line 31 of file icsp.c.
00031 { 00032 IcspData=0; 00033 IcspMclrHigh(); 00034 IcspPgdLow(); 00035 IcspPgcLow(); 00036 IcspPgmLow(); 00037 OutputPpt(IcspData); 00038 OutputPpt(IcspData); 00039 OutputPpt(IcspData); 00040 }
| void F_IcspInstructionSend | ( | U32 | Instruction | ) |
Definition at line 140 of file icsp.c.
00140 { 00141 U8 i; 00142 00143 // falling edge trigger 00144 for(i=0;i<4;i++){ 00145 if(Instruction&0x1){ 00146 F_IcspPgdHigh(); 00147 } 00148 else{ 00149 F_IcspPgdLow(); 00150 } 00151 Instruction=Instruction>>1; 00152 F_IcspPgcHigh(); 00153 F_IcspPgcLow(); 00154 } 00155 //Sleep(P5); // 40 ns...no need 00156 for(i=0;i<16;i++){ 00157 if(Instruction&0x1){ 00158 F_IcspPgdHigh(); 00159 } 00160 else{ 00161 F_IcspPgdLow(); 00162 } 00163 Instruction=Instruction>>1; 00164 F_IcspPgcHigh(); 00165 F_IcspPgcLow(); 00166 } 00167 }
| void F_IcspPageProgram | ( | void | ) |
Definition at line 253 of file icsp.c.
00253 { 00254 U32 i; 00255 U8 j; 00256 U32 k; 00257 00258 // step 1. enable write 00259 i=ICSP_CORE_INSTRUCTION+0x84a6*0x10; // EECON1.WREN=1 00260 F_IcspInstructionSend(i); 00261 // step 2. set page address 00262 i=ICSP_CORE_INSTRUCTION+0x0e*0x1000+((IcspCtrl.Address>>16)&0x000000ff)*0x10; // address[23~16] 00263 F_IcspInstructionSend(i); 00264 i=ICSP_CORE_INSTRUCTION+0x6ef8*0x10; // movwf tblptru 00265 F_IcspInstructionSend(i); 00266 i=ICSP_CORE_INSTRUCTION+0x0e*0x1000+((IcspCtrl.Address>>8)&0x000000ff)*0x10; // address[23~16] 00267 F_IcspInstructionSend(i); 00268 i=ICSP_CORE_INSTRUCTION+0x6ef7*0x10; // movwf tblptrh 00269 F_IcspInstructionSend(i); 00270 i=ICSP_CORE_INSTRUCTION+0x0e*0x1000+(IcspCtrl.Address&0x000000ff)*0x10; // address[23~16] 00271 F_IcspInstructionSend(i); 00272 i=ICSP_CORE_INSTRUCTION+0x6ef6*0x10; // movwf tblptrl 00273 F_IcspInstructionSend(i); 00274 //step 3. repeat for all but the last bytes. any unused should be ff 00275 for(j=0;j<31;j++){ // 0~61 bytes 00276 k=IcspCtrl.pData[j*2]+IcspCtrl.pData[j*2+1]*0x100; 00277 i=ICSP_TABLE_WRITE_POST_INC2+k*0x10; // address[23~16] 00278 F_IcspInstructionSend(i); 00279 } 00280 k=IcspCtrl.pData[62]+IcspCtrl.pData[63]*0x100; 00281 i=ICSP_TABLE_WRITE_PROG+k*0x10; // page program start 00282 F_IcspInstructionSend(i); 00283 F_IcspPgdLow(); 00284 F_IcspPgcHigh(); 00285 F_IcspPgcLow(); 00286 F_IcspPgcHigh(); 00287 F_IcspPgcLow(); 00288 F_IcspPgcHigh(); 00289 F_IcspPgcLow(); 00290 F_IcspPgcHigh(); 00291 Sleep(P9); // delay 4 ms 00292 F_IcspPgcLow(); 00293 for(j=0;j<16;j++){ 00294 F_IcspPgcHigh(); 00295 F_IcspPgcLow(); 00296 } 00297 }
| void F_IcspProgramModeEnter | ( | void | ) |
Definition at line 99 of file icsp.c.
00099 { 00100 U8 i; 00101 00102 Signature=0xa12c2b2; // inverse bit order of signature 0x4d434850 ("MCHP") 00104 F_IcspMclrHigh(); 00105 F_IcspMclrLow(); 00106 OutputPpt(IcspData); 00107 Sleep(P19); // 1 ms 00108 for(i=0;i<32;i++){ // rising edge latch 00109 if(Signature&0x1){ 00110 F_IcspPgdHigh(); 00111 } 00112 else{ 00113 F_IcspPgdLow(); 00114 } 00115 Signature=Signature>>1; 00116 F_IcspPgcHigh(); // <10mhz 00117 F_IcspPgcLow(); // <10mhz 00118 } 00120 F_IcspMclrHigh(); 00121 Sleep(2); // 400 us 00122 }
| void F_IcspProgramModeExit | ( | void | ) |
Definition at line 123 of file icsp.c.
00123 { 00124 00125 F_IcspMclrHigh(); 00126 F_IcspPgdLow(); 00127 F_IcspPgcLow(); 00128 //Sleep(P16); // 20 ns...no need 00129 F_IcspMclrLow(); 00130 F_IcspMclrLow(); 00131 F_IcspMclrLow(); 00132 F_IcspMclrLow(); 00133 F_IcspMclrLow(); 00134 F_IcspMclrLow(); 00135 F_IcspMclrLow(); 00136 F_IcspMclrLow(); 00137 F_IcspMclrLow(); 00138 F_IcspMclrLow(); 00139 }
| void F_IcspReset | ( | void | ) |
Definition at line 41 of file icsp.c.
00041 { 00042 IcspData=0; 00043 IcspMclrHigh(); 00044 IcspPgdLow(); 00045 IcspPgcLow(); 00046 IcspPgmLow(); 00047 OutputPpt(IcspData); 00048 OutputPpt(IcspData); 00049 OutputPpt(IcspData); 00050 }
| void F_IcspSignatureSend | ( | void | ) |
| void F_IcspTest | ( | void | ) |
Definition at line 365 of file icsp.c.
00365 { 00366 U32 i; 00367 U32 j; 00368 00369 F_IcspProgramModeEnter(); 00370 /*i=ICSP_CORE_INSTRUCTION+0x0e00*0x10; // movlw 0x00 00371 F_IcspInstructionSend(i); 00372 i=ICSP_CORE_INSTRUCTION+0x6e88*0x10; // movwf PORTJ,0...access 00373 F_IcspInstructionSend(i); 00374 i=ICSP_CORE_INSTRUCTION+0x6e9a*0x10; // movwf TRISJ,0...access 00375 F_IcspInstructionSend(i); 00376 for(j=0;j<5;j++){ 00377 i=ICSP_CORE_INSTRUCTION+0x0e0e*0x10; // movlw 0x00 00378 F_IcspInstructionSend(i); 00379 i=ICSP_CORE_INSTRUCTION+0x6e88*0x10; // movwf PORTJ,0...access 00380 F_IcspInstructionSend(i); 00381 Sleep(200); 00382 i=ICSP_CORE_INSTRUCTION+0x0e0d*0x10; // movlw 0x0f 00383 F_IcspInstructionSend(i); 00384 i=ICSP_CORE_INSTRUCTION+0x6e88*0x10; // movwf PORTJ,0...access 00385 F_IcspInstructionSend(i); 00386 Sleep(200); 00387 i=ICSP_CORE_INSTRUCTION+0x0e0b*0x10; // movlw 0x0f 00388 F_IcspInstructionSend(i); 00389 i=ICSP_CORE_INSTRUCTION+0x6e88*0x10; // movwf PORTJ,0...access 00390 F_IcspInstructionSend(i); 00391 Sleep(200); 00392 i=ICSP_CORE_INSTRUCTION+0x0e07*0x10; // movlw 0x0f 00393 F_IcspInstructionSend(i); 00394 i=ICSP_CORE_INSTRUCTION+0x6e88*0x10; // movwf PORTJ,0...access 00395 F_IcspInstructionSend(i); 00396 Sleep(200); 00397 }*/ 00398 /*IcspCtrl.Address=0; 00399 IcspCtrl.pData=&IcspBuffer[0]; 00400 F_IcspPageRead(); 00401 F_IcspBufferDump(); 00402 */ 00403 for(j=0;j<0x20;j++){ 00404 IcspCtrl.Address=0+0x40*j; 00405 IcspCtrl.pData=&IcspBuffer[0]; 00406 F_IcspPageRead(); 00407 F_IcspBufferDump(); 00408 } 00409 00410 IcspCtrl.Address=0x1ffc0; 00411 IcspCtrl.pData=&IcspBuffer[0]; 00412 F_IcspPageRead(); 00413 F_IcspBufferDump(); 00414 00415 F_IcspProgramModeExit(); 00416 F_IcspReset(); 00417 }
1.5.9