📄 90stest.asm
字号:
;***************************************************************************
;*
;* Title : AVR ISP (Auto adr inc, 115200bps, supports AVR109 commands)
;* Version : 3.8
;* Last updated : Feb 26 2006
;* Target : AT90S2313
;* File : avr910_2313_v38b.asm
;* Author(s) : klaus@mikrocontroller-projekte.de
;* last Filename: avr910_2313_V38a.asm
;* initial File : avr910_31.asm, Author: wubblick@yahoo.com, source: www.mit8.ru/~mars/ )
;*
;* This Code is free for private, noncommercial use only
;*
;* DESCRIPTION
;* The firmware on all programmers now support a unified protocol for
;* program and data memory programming. The host computer do not need
;* to know if the programmer operates in serial or parallel mode.
;*
;* The following commands are supported. All commands start with a
;* single letter. The programmer returns 13d (carriage return) or the
;* data read after the command is finished.
;*
;* +-------------------+-------------+------+
;* Commands | Host writes | Host reads | |
;* -------- +-----------+-------+-------+-----+ |
;* | ID (hex ) | data | data | | Note |
;* +-----------------------------------+-----------+-------+-------+-----+------+
;* | Enter programming mode | 'P'(0x50) | | | 13d | 1 |
;* | Report autoincrement address | 'a'(0x61) | | | 'Y' | |
;* | Set address | 'A'(0x41) | ah al | | 13d | 2 |
;* | Write program memory, low byte | 'c'(0x63) | dd | | 13d | 3 |
;* | Write program memory, high byte | 'C'(0x43) | dd | | 13d | 3 |
;* | Issue Page Write | 'm'(0x6d) | | | 13d | 13 |
;* | Read program memory | 'R'(0x52) | | dd(dd)| | 4 |
;* | Write data memory | 'D'(0x44) | dd | | 13d | |
;* | Read data memory | 'd'(0x64) | | dd | | |
;* | Chip erase | 'e'(0x65) | | | 13d | |
;* | Write lock bits | 'l'(0x6c) | dd | | 13d | |
;* | Leave programming mode | 'L'(0x4c) | | | 13d | 5 |
;* | Select device type | 'T'(0x54) | dd | | 13d | 6 |
;* | Read signature bytes | 's'(0x73) | | 3*dd | | |
;* | Return supported device codes | 't'(0x74) | | n*dd | 00d | 7 |
;* | Return software identifier | 'S'(0x53) | | s[7] | | 8 |
;* | Return sofware version | 'V'(0x56) | | dd dd | | 9 |
;* | Return hardware version | 'v'(0x76) | | dd dd | | 9 |
;* | Return programmer type | 'p'(0x70) | | dd | | 10 |
;* | Set LED | 'x'(0x78) | dd | | 13d | 12 |
;* | Clear LED | 'y'(0x79) | dd | | 13d | 12 |
;* | Universial command | ':'(0x3a) | 3*dd | dd | 13d | 15 |
;* | New universal command | '.'(0x2E) | 4*dd | dd | 13d | 15 |
;* |-----------------------------------+-----------+-------+-------+-----+------|
;* | New Commands since Version 3.3 | | | | | |
;* | Exit (AVR109, Bootloader) | 'E'(0x45) | | | 13d | 15 |
;* | Return Chip ID (Terminalmode only)| 'i'(0x69) | | s[n] | | 14 |
;* +-----------------------------------+-----------+-------+-------+-----+------+
;* | New Commands since Version 3.5 | | | | | |
;* | Implemented Atmel Bootloader commands (Atmel Appl. Note 109) | | |
;* | Report Block write Mode | 'b'(0x62) | |'Y'2*nn| 13d | 16 |
;* | Block Write | 'B'(0x42) |2*nn'M'| n*dd | 13d | 16 |
;* | Block Read | 'g'(0x67) |2*nn'M'| n*dd | 13d | 16 |
;* +-----------------------------------+-----------+-------+-------+-----+------+
;* | Commands to test (fully implemented since V3.8, Unverified) | | | |
;* | Return Lockbits | 'r'(0x72) | | dd | 13d | 17 |
;* | Return High Fusebits | 'N'(0x4E) | | dd | 13d | 17 |
;* | Return extendet Fusebits | 'Q'(0x51) | | dd | 13d | 17 |
;* | Write fuse bits (reserved) | 'f'(0x66) | dd | | 13d |11,17 |
;* | Read fuse and lock bits (reserved)| 'F'(0x46) | | dd | |11,17 |
;* +-----------------------------------+-----------+-------+-------+-----+------+
;*'F
;* 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 ISP".
;*
;* 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.
;*
;* NOTE 14
;* The 'i' command is only used with a Terminal, for debug reasons.
;* Not used in any Programmer so far
;*
;* NOTE 15
;* Lock and Fuse Bits are written using the "universal command" (:) and
;* "new universal command" (.) in AVRProg and AVRDUDE.
;* AVRProg has an Exit (E) command implemented, which switches AVRProg offline
;*
;* NOTE 16
;* Atmel Bootloader commands described in Atmel Application Note 109 implemented.
;* Very useful if you use USB to serial converter.
;* AVRProg since Version 1.33 checks if Programmer supports Block Mode,
;* IF Programmer responds 'Y' and the size of the internal Buffer (nn nn), Bootloader commands
;* are used automatically from AVRProg. (faster Protocoll)
;* Block commands send size Buffersize (nn nn) and Type of Memory ('F'=Flash, 'E'=Data)
;* Compatibility to AVR Butterfly command set and Bootloader. Works with AVR911 Open Source
;* Programmer.
;* For avrdude use -c butterfly instead of -c avr910 and you get same behaviour.
;* Page Write for Data Memory (EEPROM) not implemented
;*
;* NOTE 17
;* Commands implemented in V3.8 but not completely tested yet.
;*
;* NOTE 18
;* Device 89S8252 was tested to programm with avrprog. Shows a avrprog bug in "block Mode". Works in "standart"
;* avr910 Programming Mode. To program this Device, disable the "Block Mode" by changing "w53: rjmp w6"
;*
;* HISTORY
;* V3.8b 26.02.06 (Klaus) Matched new Devices to avrdude.conf v5.1
;* V3.8a 30.12.05 (Klaus) Corrected Devic entry for ATTiny13
;* V3.8 06.11.05 (Klaus) New Devicecodes (inoffiacal) for Mega48/88/168 and others,
;* Lockbyte write enhanced for newer Devices. Commands in
;* Note 17 implemented. Not comletely tested.
;* Code cleanup to save some Bytes.
;* V3.7e 11.01.05 (Klaus) Matched Devicecodes to the new Atmel AVRProgV1.40
;* V3.7d 05.01.05 (Klaus) Removed 1200A/B/C devicecodes, Polling 0x7F for AT90S4414, default PollcodeF = 0xFF
;* V3.7c 04.01.05 (Klaus/Micha) Some devicecodes changed (Bootloader and "default" mode).
;* V3.7b 03.01.05 (Klaus/Leo) Bugfix for Block read of Flash Mamory for AT89Snnnn Controllers.
;* V3.7a 29.12.04 (Klaus/Micha) addet devicecodes for m64, m162 and m169.
;* V3.7 15.12.04 (Klaus) Rewriting polled timing for "non Page Mode" Chips, reorganised Table for
;* different polling Codes. Skip 0xFF Byte polling. (was buggy for some Controllers)
;* Added ATTiny2313 (device Code 0x23), and ATMega8535 (0x6A)Support.
;* Not Supported from avrprog, avrdude Support possible.
;* Reorganised Table for Page Mode Chips with Pagesize. Adding different Pagesizes
;* Try to fix S89 write, BUG in avrprog detected. Firmware should be OK now. (NOTE 18)
;* After 256 unsuccesful polls for Flash wait additional standart time.
;* Modified "release_ports" so that RESET is released also.
;* V3.6 10.07.04 (Klaus) Changed Block Mode Commands to AVR109 compatibility.
;* Additional AVR109 Commands, not testet yet.
;* V3.4-V3.5 unreleased (Klaus) cleaning up, tests for Block Modes
;* V3.3 25.06.04 (Klaus, Thomas) added enhanced Block write commands
; with own Protocol.
; Add 0xFF, 0x7F (2313) check for polling Mode
;* V3.2.1 18.11.03 (Klaus) Commented out some Controller Types, which are
; not really Supported by the hardware, but from
; AVRProg Software. See Comments at the end.
;* V3.2 16.11.03 (Klaus) Correctet typo in Chrystal frequency.
;* V3.2 13.10.03 (Klaus) 7,3728 Mhz chrystal for 115.200 Baud.
;* Swap MOSI <-> MISO Pinnumbers.
;* Add dual color LED Support.
;* Add some new Dewices.
;* V3.0 02.01.23 (wubble) Ported from 1200 to 2313.
;* Serial IO modified to use hardware UART.
;* Added support for multiple new devices.
;* Used data polling to short write process.
;* Added LED support to indicate R/W process.
;* V2.2 00.03.10 (pkastnes) Added support for multiple new devices.
;* V2.1 98.10.26 (mlund) New date marking.
;* Removed support for AT90S1200C.
;* Added support for AT90S4433A.
;* V2.0 98.01.06 (mlund) ATmega103 support.
;* V1.7 97.11.06 (mlund) Universial command (':') implemented.
;* Releases all pins when not in
;* programming mode.
;* V1.6e 97.11.04 (mlund) mega103 rev D support
;* V1.6c 97.10.30 (mlund) Auto incrementing / SPI sync
;* also works for mega103.
;* V1.6 97.09.09 (hskar) Created Page Mode Version (mega103)
;* V1.5 97.08.21 (mlund) Modified / Bugfix / Major cleanup
;* ... ... (no records)
;* V?.? 97.03.15 (OS) Created
;*
;*
;* Device Support List: see table "Devices" at the end of this file.
;***************************************************************************
;**** includes ****
.include "tn2313def.inc"
;.include "2313def.inc"
;***************************************************************************
;*
;* CONSTANTES
;*
;***************************************************************************
;**** Constant declarations Data Rate ****
;******** Chrystals for maximum Baudrates
;.equ XTAL = 7373 ; XTAL frequency, Khz (7.3728 Mhz)
;********
;.equ BAUD = 115200 ; Data rate, bauds
;.equ N = 3 ; for 7.3728 Mhz/115.200Baud
;********
;.equ BAUD = 38400 ; Data rate, bauds
;.equ N = 11 ; for 7.3728 Mhz/38.400Baud
;********
;.equ BAUD = 19200 ; Data rate, bauds
;.equ N = 23 ; for 7.3728 Mhz/19.200 Baud
;*********
;**** definitions for different chrystals and 115.200 baud ****
.equ XTAL = 3686 ; XTAL frequency, Khz (3.6864 Mhz)
;*********
.equ BAUD = 115200 ; Data rate, bauds
.equ N = 1 ; for 3.6864 Mhz/115.200Baud
;*********
;
;********* Baudrates for 8 Mhz Chrystal
;.equ XTAL = 8000 ; XTAL frequency, Khz (8.000 Mhz)
;*********
;.equ BAUD = 38400 ; Data rate, bauds
;.equ N = 12 ; for 8.00 Mhz/38.400 Baud
;*********
;.equ BAUD = 19200 ;Data rate, bauds
;.equ N = 25 ; for 8.00 Mhz/19.200 Baud
;*********
;.equ BAUD = 9600 ; Data rate, bauds ! Not valid for AVRProg, use for avrdude only !
;.equ N = 51 ; for 8.00 Mhz/9.600 Baud
;*********
;********* Baudrates for 4 Mhz Chrystal
;.equ XTAL = 4000 ; XTAL frequency, Khz (4.000 Mhz)
;*********
;.equ BAUD = 19200 ; Data rate, bauds
;.equ N = 12 ; for 4.00 Mhz/19.200 Baud
;*********
;.equ BAUD = 9600 ; Data rate, bauds ! Not valid for AVRProg, use for avrdude only !
;.equ N = 25 ; for 4.00 Mhz/9.600 Baud
;*********
.equ RAMSTART = 0x60 ; first SRAM Adress of 2313
;.equ PAGESIZE = 0x10 ; default Page size for Programming
.equ BUFSIZE = 0x40 ; 64 bytes internal RAM for Buffer
;***************************************************************************
;*
;* PORTS
;* Ports Definitions
;*
;* DESCRIPTION
;* Change the following definitions if the RESET pin to the
;* target moves and/or if the SCK/MISO/MISO/LED moves.
;*
;***************************************************************************
.equ LEDH = PB3 ; dual color LED output, anode green (output)
.equ LED = PB0 ; LED output, active low, dual color LED Kathode green (output)
.equ MISO = PB6 ; MISO pin of the target (input)
.equ MOSI = PB5 ; MOSI pin of the target (output)
.equ RESET = PB4 ; RESET pin of the target (output)
.equ SCK = PB7 ; SCK pin of the target (output)
.equ RXD = PD0 ; UART RXD line
.equ TXD = PD1 ; UART TXD line
;***************************************************************************
;*
;* MACROS
;* Program Macros
;*
;* DESCRIPTION
;* Change the following macros if the RESET pin to the
;* target moves and/or if the SCK/MISO/MISO/LED moves.
;*
;***************************************************************************
.macro init_ports ; init ports
ldi temp2,0xff
out PORTD,temp2
ldi temp2,0xff
out PORTB,temp2
.endm
.macro catch_ports ; catch ports
ldi temp2,(1<<TXD)
out DDRD,temp2
ldi temp2,(1<<RESET) | (1<<MOSI) | (1<<SCK) | (1<<LED) | (1<<LEDH)
out DDRB,temp2
.endm
.macro release_ports ; release ports
ldi temp2,(1<<TXD)
out DDRD,temp2
ldi temp2,(1<<LED) | (1<<LEDH)
out DDRB,temp2
.endm
.macro pas_RESET ; set RESET passive
tst device
brmi m2 ; S89 device
sbi PORTB,RESET
rjmp m3
m2: cbi PORTB,RESET
m3:
.endm
.macro act_RESET ; set RESET active
tst device
brmi m4 ; S89 device
cbi PORTB,RESET
rjmp m5
m4: sbi PORTB,RESET
m5:
.endm
.macro set_LED ; set LED Port -> Standart LED off, dual LED green
sbi PORTB,LED
cbi PORTB,LEDH ; added for dual color support
.endm
.macro clr_LED ; clear LED Port --> Standart LED on, dual LED red
cbi PORTB,LED
sbi PORTB,LEDH ; added for dual color support
.endm
.macro LED_off ; for dual color LED, not in use
cbi PORTB,LED
cbi PORTB,LEDH
.endm
.macro sbic_MISO ; skip if MISO cleared
sbic PINB,MISO
.endm
.macro set_MOSI ; set MOSI
sbi PORTB,MOSI
.endm
.macro clr_MOSI ; clear MOSI
cbi PORTB,MOSI
.endm
.macro clr_SCK ; clear SCK
cbi PORTB,SCK
.endm
.macro pulse_SCK ; pulse SCK
sbi PORTB,SCK
ldi temp2,(XTAL/750+1) ; had to slow down for ATTiny2313 (internal clock) default was (XTAL/1500+1)
m0: dec temp2
brne m0
cbi PORTB,SCK
ldi temp2,(XTAL/1500+1) ; had to slow down for ATTiny2313 (internal clock) default was (XTAL/3000+1)
m1: dec temp2
brne m1
.endm
.macro table ; load Z pointer
ldi ZL,low(@0*2) ; low
ldi ZH,high(@0*2) ; high
.endm
;***************************************************************************
;*
;* Global Register Variables
;*
;***************************************************************************
;r0 used with lpm instruction
.def cmd1 = r1 ; Universal commands params
.def cmd2 = r2 ; ..
.def cmd3 = r3 ; ..
.def pol_al = r4 ; Polling address low
.def pol_ah = r5 ; Polling address high
.def Bcnt1 = r6 ; Block Mode Counter1
.def Bcnt2 = r7 ; Block Mode Counter2
.def Bcnt3 = r8 ; Block Mode Counter2
.def B_Flag = r9 ; Flag for ws_del Routine
.def B_Mode = r10 ; Marks Block Mode commands (See Note 16)
.def Memtype = r11 ; Flag for Memorytype for Block Commands (See Note 16)
.def Pagewords = r12 ; Size of Controller page to program in Page Mode (Words!)
.def PollcodeF = r13 ; Code for Polling Flash
.def temp1 = r16 ; Temporary register 1
.def temp2 = r17 ; Temporary register 2
.def temp3 = r18 ; Temporary register 3
.def s_data = r19 ; SPI data
.def u_data = r20 ; UART data
.def device = r21 ; Device code
;.def lockmode = r22 ; Param to set correct lockbit read/write mode
.def rd_s_data = r23 ; Read data on SPI
.def pol_cmd = r24 ; Polling command
.def p_data = r25 ; Polling data
;r26,r27 used as X register
.def addrl = r28 ; (YL) Low order byte of address
.def addrh = r29 ; (YH) High order byte of address
;r30,r31 used as Z register
;***************************************************************************
;*
;* Interrupt Vectors
;*
;***************************************************************************
.CSEG
rjmp INIT ; Reset Handle
;***************************************************************************
;*
;* FUNCTION
;* u_init
;*
;* DESCRIPTION
;* Initialize UART.
;*
;***************************************************************************
u_init:
ldi temp1,N ; set baud rate
out UBRR,temp1
ldi temp1,(1<<TXEN)|(1<<RXEN) ; initialize UART for TX and RX
out UCR,temp1
ret
;***************************************************************************
;*
;* FUNCTION
;* getc
;*
;* DESCRIPTION
;* Wait for start bit and receive a character on the UART Rx line.
;*
;***************************************************************************
getc:
sbis USR,RXC ; wait until a character has been received
rjmp getc
in u_data,UDR ; Read byte from the UART
ret
;***************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -