⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 串口isp下载器avr910的 c 原代码.txt

📁 串口ISP下载器AVR910的 C 原代码.txt
💻 TXT
📖 第 1 页 / 共 4 页
字号:
/*--------------------------------------------------------------------------*/ 
/* AVR-PRG (ATMEL Appreciation note avr910.asm conpati program)             */ 
/*--------------------------------------------------------------------------*/ 
/* 
 ********** history************************ 
 * Ver.    Date     Comments                                         By 
 * ---- ---------- ------------------------------------------------ ---------- 
 *  
 * 2.3b 2002/09/24 tiny26 added                       Terashima 
 * 
*/ 

#include <io2313.h> 
#include <progmem.h> 


/*--------------------------------------------------------------------------*/ 
/*                                     +-------------+------------+------+  */ 
/*  Commands                           | Host writes | Host reads |      |  */ 
/*  --------                           +-----+-------+------+-----+      |  */ 
/*                                     | ID  | data  | data |     | Note |  */ 
/* +-----------------------------------+-----+-------+------+-----+------+  */ 
/* | Enter programming mode            | 'P' |       |      | 13d |   1  |  */ 
/* | Report autoincrement address      | 'a' |       |      | 'Y' |      |  */ 
/* | Set address                       | 'A' | ah al |      | 13d |   2  |  */ 
/* | Write program memory, low byte    | 'c' |    dd |      | 13d |   3  |  */ 
/* | Write program memory, high byte   | 'C' |    dd |      | 13d |   3  |  */ 
/* | Issue Page Write                  | 'm' |       |      | 13d |      |  */ 
/* | Read program memory               | 'R' |       |dd(dd)|     |   4  |  */ 
/* | Write data memory                 | 'D' |    dd |      | 13d |      |  */ 
/* | Read data memory                  | 'd' |       |   dd |     |      |  */ 
/* | Chip erase                        | 'e' |       |      | 13d |      |  */ 
/* | Write lock bits                   | 'l' |    dd |      | 13d |      |  */ 
/* | Write fuse bits                   | 'f' |    dd |      | 13d |  11  |  */ 
/* | Read fuse and lock bits           | 'F' |       |   dd |     |  11  |  */ 
/* | Leave programming mode            | 'L' |       |      | 13d |   5  |  */ 
/* | Select device type                | 'T' |    dd |      | 13d |   6  |  */ 
/* | Read signature bytes              | 's' |       | 3*dd |     |      |  */ 
/* | Return supported device codes     | 't' |       | n*dd | 00d |   7  |  */ 
/* | Return software identifier        | 'S' |       | s[7] |     |   8  |  */ 
/* | Return sofware version            | 'V' |       |dd dd |     |   9  |  */ 
/* | Return hardware version           | 'v' |       |dd dd |     |   9  |  */ 
/* | Return programmer type            | 'p' |       |   dd |     |  10  |  */ 
/* | Set LED                           | 'x' |    dd |      | 13d |  12  |  */ 
/* | Clear LED                         | 'y' |    dd |      | 13d |  12  |  */ 
/* | Universial command                | ':' |  3*dd |   dd | 13d |      |  */ 
/* | New universal command             | '.' |  4*dd |   dd | 13d |      |  */ 
/* | Special test command              | 'Z' |  2*dd |   dd |     |      |  */ 
/* +-----------------------------------+-----+-------+------+-----+------+  */ 
/*                                                                          */ 
/* NOTE 1                                                                   */ 
/*      The Enter programming mode command MUST be sent one time prior to   */ 
/*      the other commands, with the exception of the 't', 'S', 'V', 'v'    */ 
/*      and 'T' commands. The 'T' command must be sent before this command  */ 
/*      (see note 6).                                                       */ 
/*      For programmers supporting both parallel and serial programming     */ 
/*      mode this command enters parallel programming mode. For programmers */ 
/*      supporting only serial programming mode, this command enters serial */ 
/*      programming mode.                                                   */ 
/* NOTE 2                                                                   */ 
/*      The ah and al are the high and low order bytes of the address. For  */ 
/*      parallel programmers this command issues the Load Address Low/High  */ 
/*      Byte command. For serial programmers the address byte is stored for */ 
/*      use by the Read/Write commands.                                     */ 
/* NOTE 3                                                                   */ 
/*      For parallel programmers this command issues the Program Flash      */ 
/*      command. For serial programmers this command iussues the Write      */ 
/*      Program Memory Command. For devices with byte-wide program memories */ 
/*      only the low byte command should be used.                           */ 
/* NOTE 4                                                                   */ 
/*      The contents of the program memory at the address given by the 'A'  */ 
/*      command are written to the serial port in binary form. For byte     */ 
/*      wide memories one byte is written. For 16 bit memories two bytes    */ 
/*      are written,MSB first.                                              */ 
/* NOTE 5                                                                   */ 
/*      This command must be executed after the programming is finished.    */ 
/* NOTE 6                                                                   */ 
/*      The select device type command must be sent before the enter        */ 
/*      programming command                                                 */ 
/* NOTE 7                                                                   */ 
/*      The supported device codes are returned in binary form terminated   */ 
/*      by 0x00.                                                            */ 
/* NOTE 8                                                                   */ 
/*      This return a 7 character ASCII string identifying the programmer.  */ 
/*      For the development board it is "AVR DEV", for the parallel         */ 
/*      programmer it is "AVR PPR" and for the in-curcuit programmer it is  */ 
/*      "AVR ICP".                                                          */ 
/* NOTE 9                                                                   */ 
/*      The software/hardware version are returned as two ASCII numbers.    */ 
/* NOTE 10                                                                  */ 
/*      This command should be used to identify the programmer type. The    */ 
/*      return value is 'S' for serial (or SPI) programmers or 'P' for      */ 
/*      parallel programmers.                                               */ 
/* NOTE 11                                                                  */ 
/*      The write fuse bits command are available only on parallel          */ 
/*      programmers and only for AVR devices (device code < 0x80). The host */ 
/*      should use the return programmer type command to determine the      */ 
/*      programmer type, do not use the  "AVR PPR" idenifier because other  */ 
/*      programmers may be available in the future.                         */ 
/* NOTE 12                                                                  */ 
/*      Currently only the AVR development board has LEDs. The other boards */ 
/*      must implement this commands as NOPs.                               */ 
/* NOTE 13                                                                  */ 
/*      Devices using Page Mode Programming write one page of flash memory  */ 
/*      before issuing a Page Mode Write Pulse.                             */ 
/* Device Support List                                                      */ 
/* +--------+----------+------+-------+------+------+------+-------+        */ 
/* | Device |Signature | Code | Flash |EEProm| Lock | Fuse | PMode |        */ 
/* +--------+----------+------+-------+------+------+------+-------+        */ 
/* | tiny12 | 1E 90 05 | 0x55 |  R/W  | R/W  | R/W  | R/W  | Byte  |        */ 
/* | tiny15 | 1E 90 06 | 0x56 |  R/W  | R/W  | R/W  | R/W  | Byte  |        */ 
/* |        |          |      |       |      |      |      |       |        */ 
/* | S1200  | 1E 90 01 | 0x13 |  R/W  | R/W  |  W   | NA   | Byte  |        */ 
/* |        |          |      |       |      |      |      |       |        */ 
/* | S2313  | 1E 91 01 | 0x20 |  R/W  | R/W  |  W   | NA   | Byte  |        */ 
/* | S2323  | 1E 91 02 | 0x48 |  R/W  | R/W  | R/W  | R/W  | Byte  |        */ 
/* | S2333  | 1E 91 05 | 0x34 |  R/W  | R/W  | R/W  | R/W  | Byte  |        */ 
/* | S2343  | 1E 91 03 | 0x4C |  R/W  | R/W  | R/W  | R/W  | Byte  |        */ 
/* |        |          |      |       |      |      |      |       |        */ 
/* | S4414  | 1E 92 01 | 0x28 |  R/W  | R/W  |  W   | NA   | Byte  |        */ 
/* | S4433  | 1E 92 03 | 0x30 |  R/W  | R/W  | R/W  | R/W  | Byte  |        */ 
/* | S4434  | 1E 92 02 | 0x6C |  R/W  | R/W  | R/W  | R/W  | Byte  |        */ 
/* |        |          |      |       |      |      |      |       |        */ 
/* | S8515  | 1E 93 01 | 0x38 |  R/W  | R/W  |  W   | NA   | Byte  |        */ 
/* | S8535  | 1E 93 03 | 0x68 |  R/W  | R/W  | R/W  | R/W  | Byte  |        */ 
/* |        |          |      |       |      |      |      |       |        */ 
/* |mega83  | 1E 93 05 | 0x65 |  R/W  | R/W  | R/W  | R/W  | Page  |        */ 
/* |mega103 | 1E 97 01 | 0x41 |  R/W  | R/W  | R/W  | R/W  | Page  |        */ 
/* |mega161 | 1E 94 01 | 0x60 |  R/W  | R/W  | R/W  | R/W  | Page  |        */ 
/* |mega163 | 1E 94 02 | 0x64 |  R/W  | R/W  | R/W  | R/W  | Page  |        */ 
/* |        |          |      |       |      |      |      |       |        */ 
/* |mega8   | 1E 93 07 | 0x76 |  R/W  | R/W  | R/W  | R/W  | Page  |        */ 
/* |mega16  | 1E 94 03 | 0x74 |  R/W  | R/W  | R/W  | R/W  | Page  |        */ 
/* |mega32  | 1E 95 02 | 0x72 |  R/W  | R/W  | R/W  | R/W  | Page  |        */ 
/* |mega128 | 1E 97 02 | 0x43 |  R/W  | R/W  | R/W  | R/W  | Page  |        */ 
/* |mega8515| 1E 93 06 | 0x3A |  R/W  | R/W  | R/W  | R/W  | Page  |        */ 
/* +--------+----------+------+-------+------+------+------+-------+        */ 
/*                                                                          */ 
/* LEGEND:                                                                  */ 
/* -------                                                                  */ 
/* Signature - Device Signature Byte                                        */ 
/* Code      - Unique device code used by AVRProg to identify device        */ 
/* Flash     - Flash size in bytes                                          */ 
/* EEProm    - EEProm size in bytes                                         */ 
/* Lock      - Lockbits                                                     */ 
/* Fuse      - Fusebits                                                     */ 
/* PMode     - Indicates if device uses byte or page programming mode       */ 
/* R/W - Read and Write Access                                              */ 
/* R   - Read Access Only                                                   */ 
/* W   - Write Access Only                                                  */ 
/* NA  - Not Accessible                                                     */ 
/*--------------------------------------------------------------------------*/ 
/* macro definition                                                         */ 
/*--------------------------------------------------------------------------*/ 
#define TRUE         (1==1) 
#define FALSE         (1==0) 

#define SYSCLK         4000000L      /* CLK = 4MHz       */ 
/*--------------------------------------------------------------------------*/ 
/* I/O port setting                                                  */ 
/* --- ---- --------------------------------------------------------------- */ 
/* PB0: OUT 8PIN_H   (When 8pin dev is selected,output 'H')                                        */ 
/* PB1: OUT GND Select (1:10斣僺儞偵GND傪嫙媼)                              */ 
/* PB2: OUT VCC Select (1:10斣僺儞偵VCC(+5V)傪嫙媼)                         */ 
/* PB3: OUT VCC Enable (1:僞乕僎僢僩偺揹尮傪ON, 0:僞乕僎僢僩偺揹尮傪OFF)    */ 
/* PB4: OUT Target RESET                                                   */ 
/* PB5: IN  Target MISO (Self MOSI)                                         */ 
/* PB6: OUT Target MOSI (Self MISO)                                         */ 
/* PB7: OUT Target SCK  (Self SCK)                                          */ 
/* --- ---- --------------------------------------------------------------- */ 
/* PD0: in  UART RxD                                                        */ 
/* PD1: out UART TxD                                                        */ 
/* PD2: OUT 8PIN_DET   (When 8pin dev is selected,output 'L')               */ 
/* PD3: OUT 廐寧AVR儔僀僞屳姺LED (1:ON, 0:OFF)                              */ 
/* PD4: OUT _28PIN_DET                                                      */ 
/* PD5: OUT _28PIN_DET                                                      */ 
/* PD6: OUT _40PIN_DET                                                      */ 
/* --- ---- --------------------------------------------------------------- */ 
/*    VCC Select and GND Select, They must not be at same time.             */ 
/*    嫙媼晹(74HC4066)偱僔儑乕僩偟偰偟傑偆丅                                */ 
/*--------------------------------------------------------------------------*/ 
#define _8PIN_H         PB0 
#define GND_SELECT      PB1 
#define VCC_SELECT      PB2 
#define VCC_ENABLE      PB3 
#define TARGET_RESET       PB4 
#define TARGET_MISO      PB5 
#define TARGET_MOSI      PB6 
#define TARGET_SCK      PB7 

#define _8PIN_DET      PD2 
#define MON_LED         PD3 
#define _20PIN_DET      PD4 
#define _28PIN_DET      PD5 
#define _40PIN_DET      PD6 
/*--------------------------------------------------------------------------*/ 
/* revision information                                                                 */ 
/*--------------------------------------------------------------------------*/ 
#define SW_MAJOR      '2'   /* Major Software revision number   */ 
#define SW_MINOR      '3'   /* Minot Software revision number   */ 
#define HW_MAJOR      '1'   /* Major Hardware revision number   */ 
#define HW_MINOR      '0'   /* Minot Hardware revision number   */ 
/*--------------------------------------------------------------------------*/ 
/* device code                                                     */ 
/*--------------------------------------------------------------------------*/ 
#define S1200A         0x10      /* AT90S1200/A rev.A (old)  */ 
#define S1200B         0x11      /* AT90S1200/A rev.B (old)  */ 
#define S1200C         0x12      /* AT90S1200/A rev.C (old)  */ 
#define S1200D         0x13      /* AT90S1200/A rev.D (current)*/ 
#define S2313A         0x20      /* AT90S2313          */ 
#define S4414A         0x28      /* AT90S4414          */ 
#define S4433A         0x30      /* AT90S4433          */ 
#define S2333A         0x34      /* AT90S2333          */ 
#define S8515A         0x38      /* AT90S8515          */ 
#define m8515         0x3A      /* ATmega8515          */ 
#define m8515b         0x3B      /* ATmega8515 BOOT       */ 
#define m103         0x41      /* ATmega103          */ 
#define m603         0x42      /* ATmega603          */ 
#define m128         0x43      /* ATmega128          */ 
#define m128b         0x44      /* ATmega128 BOOT       */ 
#define S2323A         0x48      /* AT90S2323          */ 
#define S2343A         0x4C      /* AT90S2343          */ 
#define TN11         0x50      /* ATtiny11          */ 
#define TN10         0x51      /* ATtiny10          */ 
#define TN12         0x55      /* ATtiny12          */ 
#define TN15         0x56      /* ATtiny15          */ 
#define TN19         0x58      /* ATtiny19          */ 
#define TN28         0x5C      /* ATtiny28          */ 
#define TN26         0x5E      /* ATtiny26          */ 
#define m161         0x60      /* ATmega161          */ 
#define m161b         0x61      /* ATmega161 BOOT       */ 
#define m163         0x64      /* ATmega163          */ 
#define m83         0x65      /* ATmega83          */ 
#define m163b         0x66      /* ATmega163 BOOT       */ 
#define m83b         0x67      /* ATmega83 BOOT       */ 
#define S8535         0x68      /* AT90S8535          */ 
#define S4434         0x6C      /* AT90S4434          */ 
#define C8534         0x70   /* AT90C8534 (parallel program only)   */ 
#define C8544         0x71   /* AT90C8544 (parallel program only)   */ 
#define m32         0x72      /* ATmega32          */ 
#define m32b         0x73      /* ATmega32 BOOT       */ 
#define m16         0x74      /* ATmega16          */ 
#define m16b         0x75      /* ATmega16 BOOT       */ 
#define m8         0x76      /* ATmega8          */ 
#define m8b         0x77      /* ATmega8 BOOT          */ 

//#define m64         ??      /* ATmega64          */ 
//#define m64b         ??      /* ATmega64 BOOT       */ 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -