📄 main.lst
字号:
264 2 }
265 1
266 1 ////////////last clock////////////////////////
267 1 for(i=0; i<7; i++)
268 1 {
269 2 PGCSET(); //clk = 1
270 2 nop();
271 2 nop();
272 2 nop();
273 2 PGCCLR(); //clk = 0
274 2 }
275 1 return codedata;
276 1 }
277
278 //////////////////////////////////////////////////////////
279 void ProgWriteCode(uint codedata)
280 {
281 1 uchar i;
282 1 ProgCommandSet(PICCMD_LDPMEM);
283 1 clock_vDelay(1); //delay
284 1
285 1 ////////////first clock////////////////////////
286 1 PGDCLR(); //dat = 0
287 1 PGCSET(); //clk = 1
288 1 nop();
289 1 nop();
290 1 nop();
291 1 PGCCLR(); //clk = 0
292 1
293 1 for(i=0; i<14; i++)
294 1 {
295 2 PGCSET(); //clk = 1
296 2 if(codedata & 0x0001)
297 2 {
298 3 PGDSET(); //dat = 1
299 3 }
300 2 else
301 2 {
302 3 PGDCLR(); //dat = 0
303 3 }
C51 COMPILER V7.50 MAIN 06/11/2008 14:41:36 PAGE 6
304 2 codedata >>= 1;
305 2 PGCCLR(); //clk = 0
306 2 }
307 1
308 1 ////////////last clock////////////////////////
309 1 PGDCLR(); //dat = 0
310 1 PGCSET(); //clk = 1
311 1 nop();
312 1 nop();
313 1 nop();
314 1 PGCCLR(); //clk = 0
315 1
316 1 ProgCommandSet(PICCMD_PROGRAM);
317 1 clock_vDelay(50); //delay
318 1 }
319
320
321 //////////////////////////////////////////////////////////////////////////
322 void ProgWriteConfig(uint value)
323 {
324 1 uchar i;
325 1 ProgCommandSet(PICCMD_LDCONFIG); //send command
326 1 clock_vDelay(1); //delay
327 1 ////////////first clock////////////////////////
328 1 PGDCLR(); //dat = 0
329 1 PGCSET(); //clk = 1
330 1 nop();
331 1 nop();
332 1 nop();
333 1 PGCCLR(); //clk = 0
334 1
335 1 for(i=0; i<14; i++)
336 1 {
337 2 PGCSET(); //clk = 1
338 2 if(value & 0x0001)
339 2 {
340 3 PGDSET(); //dat = 1
341 3 }
342 2 else
343 2 {
344 3 PGDCLR(); //dat = 0
345 3 }
346 2 value >>= 1;
347 2 PGCCLR(); //clk = 0
348 2 }
349 1
350 1 PGDCLR(); //dat = 0
351 1 PGCSET(); //clk = 1
352 1 nop();
353 1 nop();
354 1 nop();
355 1 PGCCLR(); //clk = 0
356 1 }
357
358 //////////////////////////////////////////////////////////////////////////
359 void ProgWriteEEProm(uchar eedata)
360 {
361 1 uchar i;
362 1 ProgCommandSet(PICCMD_LDEEPROM);
363 1 clock_vDelay(1); //delay
364 1
365 1 ////////////first clock////////////////////////
C51 COMPILER V7.50 MAIN 06/11/2008 14:41:36 PAGE 7
366 1 PGDCLR(); //dat = 0
367 1 PGCSET(); //clk = 1
368 1 nop();
369 1 nop();
370 1 nop();
371 1 PGCCLR(); //clk = 0
372 1
373 1 for(i=0; i<8; i++)
374 1 {
375 2 PGCSET(); //clk = 1
376 2 if(eedata & 0x01)
377 2 {
378 3 PGDSET(); //dat = 1
379 3 }
380 2 else
381 2 {
382 3 PGDCLR(); //dat = 0
383 3 }
384 2 eedata >>= 1;
385 2 PGCCLR(); //clk = 0
386 2 }
387 1
388 1 for(i=0; i<7; i++)
389 1 {
390 2 PGDCLR(); //dat = 0
391 2 PGCSET(); //clk = 1
392 2 nop();
393 2 nop();
394 2 nop();
395 2 PGCCLR(); //clk = 0
396 2 }
397 1
398 1 ProgCommandSet(PICCMD_PROGRAM);
399 1 clock_vDelay(100); //delay
400 1 }
401
402
403 //////////////////////////////////////////////////////////////////////////
404 // TINY PROGRAM
405 //
406 //////////////////////////////////////////////////////////////////////////
407
408 uchar Tiny_SendByte(uchar Cmd)
409 {
410 1 uchar i;
411 1 uchar retdata = 0;
412 1
413 1 SCK_CLR();
414 1 for(i=0; i<8; i++)
415 1 {
416 2 retdata <<= 1;
417 2 if(Cmd & 0x80)
418 2 {
419 3 MOSI_SET();
420 3 }
421 2 else
422 2 {
423 3 MOSI_CLR();
424 3 }
425 2 SCK_SET();
426 2 nop();
427 2 nop();
C51 COMPILER V7.50 MAIN 06/11/2008 14:41:36 PAGE 8
428 2 if(MISO_READ() == 1) //bit=1
429 2 {
430 3 retdata |= 1;
431 3 }
432 2 Cmd <<= 1;
433 2 SCK_CLR();
434 2 }
435 1 return retdata;
436 1 }
437
438
439
440 /////////////////////////////////////////////////////////////
441 uchar Tiny_ReadProgram(uchar highlow, uint addr)
442 {
443 1 uchar cmd[3];
444 1 uint temp = addr;
445 1 uchar retdata;
446 1
447 1 highlow <<= 3;
448 1 cmd[0] = 0x20 + highlow;
449 1 cmd[1] = (uchar)(temp >> 8);
450 1 cmd[2] = (uchar)(addr);
451 1 Tiny_SendByte(cmd[0]);
452 1 Tiny_SendByte(cmd[1]);
453 1 Tiny_SendByte(cmd[2]);
454 1 retdata = Tiny_SendByte(0);
455 1 return (retdata);
456 1 }
457
458 ////////////////////////////////////////////////////////
459 uchar Tiny_ReadEepRom(uchar addr)
460 {
461 1 uchar retdata;
462 1 Tiny_SendByte(0xa0);
463 1 Tiny_SendByte(0);
464 1 Tiny_SendByte(addr);
465 1 retdata = Tiny_SendByte(0);
466 1 return retdata;
467 1 }
468
469 ////////////////////////////////////////////////////////////////
470 void Tiny_WriteEepRom(uchar addr, uchar eepdata)
471 {
472 1 Tiny_SendByte(0xc0);
473 1 Tiny_SendByte(0);
474 1 Tiny_SendByte(addr);
475 1 Tiny_SendByte(eepdata);
476 1 }
477
478 ////////////////////////////////////////////////////////////////
479 uchar Tiny_TestBusy()
480 {
481 1 uchar ret;
482 1 Tiny_SendByte(0xf0); //
483 1 Tiny_SendByte(0);
484 1 Tiny_SendByte(0);
485 1 ret = Tiny_SendByte(0); //send low byte
486 1 return ret;
487 1 }
488
489 //////////////////////////////////////////////////////////////////
C51 COMPILER V7.50 MAIN 06/11/2008 14:41:36 PAGE 9
490 void Tiny_Erase()
491 {
492 1 Tiny_SendByte(0xac); //
493 1 Tiny_SendByte(0x80);
494 1 Tiny_SendByte(0);
495 1 Tiny_SendByte(0); //send low byte
496 1 }
497
498 ////////////////////////////////////////////////////////////////
499 void Tiny_WriteProgram(uint addr, uchar* progdata)
500 {
501 1 uint temp = addr;
502 1
503 1 Tiny_SendByte(0x40); //
504 1 Tiny_SendByte(0);
505 1 Tiny_SendByte((uchar)(addr & 0x000f));
506 1 Tiny_SendByte(*progdata++); //send low byte
507 1
508 1 Tiny_SendByte(0x48); //
509 1 Tiny_SendByte(0);
510 1 Tiny_SendByte((uchar)(temp & 0x000f));
511 1 Tiny_SendByte(*progdata); //send high byte
512 1
513 1 Tiny_SendByte(0x4c); //program
514 1 Tiny_SendByte((uchar)(temp >> 8));
515 1 Tiny_SendByte((uchar)(temp & 0x00f0));
516 1 Tiny_SendByte(0); //send high byte
517 1 }
518
519 ////////////////////////////////////////////////////////////////
520 uchar Tiny_ReadLockBit(void)
521 {
522 1 uchar temp;
523 1 Tiny_SendByte(0x58);
524 1 Tiny_SendByte(0);
525 1 Tiny_SendByte(0);
526 1 temp = Tiny_SendByte(0); //send low byte
527 1 return(temp & 0x3f);
528 1 }
529
530 ////////////////////////////////////////////////////////////////
531 void Tiny_ReadFuseBit(uchar* fusebit)
532 {
533 1 Tiny_SendByte(0x50);
534 1 Tiny_SendByte(0);
535 1 Tiny_SendByte(0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -