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

📄 isojtag_avr910_3.8.s

📁 GCC source code for do it yoursel a avr programer and jtagice debuger.
💻 S
📖 第 1 页 / 共 4 页
字号:
//**************************************************************************//// Title		: AVR ISP (Auto adr inc, supports AVR109 commands)// Version		: 3.8// Last updated	: Apr 23 2007 // Target		: ATmega16 in IsoJtagISP// File			: isojtag_avr910_3.8.S // Author(s)	: andrew@floppyspongeonline.com// last Filename: avr910_2313_V38b.asm, Author: klaus@mikrocontroller-projekte.de, source: www.mikrocontroller-projekte.de
// 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. //**************************************************************************#if #cpu (atmega16).arch atmega16
#elif #cpu (atmega32)
.arch atmega16
#endif
#define __SFR_OFFSET 0#include <avr/io.h>//#include <avr/iom16.h>#include "crystal.h"
#include "memory.h".list//**************************************************************************//// CONSTANTS////**************************************************************************//**** Revision Codes ****#define	SW_MAJOR  '3'		// Major SW revision number#define	SW_MINOR  '8'		// Minor SW revision number#define	HW_MAJOR  '2'		// Major HW revision number#define	HW_MINOR  '2'		// Minor HW revision number//******* Frequency Dependant#define	XTAL  14000		//XTAL frequency, Khz#define	BAUD  19200		//Data rate, bauds#define	N  	N19200//*******#define RAMSTART  0x60		// first SRAM Adress of M16#define PAGESIZE  0x10		// default Page size for Programming#define 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.////**************************************************************************//#define LEDH	 PB3		// dual color LED output, anode green  (output)//#define LED		 PB0		// LED output, active low, dual color LED Kathode green  (output)//#define MISO	 PB6		// MISO  pin of the target (input)//#define MOSI	 PB5		// MOSI  pin of the target (output)#define RESET	 PB1		// RESET pin of the target (output)//#define SCK		 PB7		// SCK   pin of the target (output)#define RXD		 PD0		// UART RXD line#define TXD		 PD1		// UART TXD line#define LEDDDR		DDRB#define LEDPORT		PORTB#define LEDBIT		3#define MOSI	 5		// Bit number on PORTB#define MISO	 6		// Bit number on PORTB#define SCK		 7		// Bit number on PORTB//**************************************************************************//// 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.////**************************************************************************#define set_LED		sbi LEDPORT,LEDBIT		// set LED Port -> Standart LED off, dual LED green#define clr_LED		cbi LEDPORT,LEDBIT		// clear LED Port --> Standart LED on, dual LED red#define sbic_MISO	sbic PINB,MISO		// skip if MISO cleared#define set_MOSI	sbi	PORTB,MOSI		// set MOSI#define clr_MOSI	cbi	PORTB,MOSI		// clear MOSI#define clr_SCK		cbi	PORTB,SCK		// clear SCK//**************************************************************************//// Global Register Variables////**************************************************************************//r0 used with lpm instruction#define cmd1		 	r1	// Universal commands params#define cmd2			r2	// ..#define cmd3			r3	// ..#define pol_al		 	r4	// Polling address low#define pol_ah		 	r5	// Polling address high#define Bcnt1		 	r6	// Block Mode Counter1#define Bcnt2		 	r7	// Block Mode Counter2#define Bcnt3		 	r8	// Block Mode Counter2#define B_Flag			r9	// Flag for ws_del Routine#define B_Mode			r10	// Marks Block Mode commands (See Note 16)#define Memtype			r11	// Flag for Memorytype for Block Commands (See Note 16)#define Pagewords	 	r12	// Size of Controller page to program in Page Mode (Words!) #define PollcodeF		r13	// Code for Polling Flash#define temp1 r16	// Temporary register 1#define temp2		 	r17	// Temporary register 2#define temp3		 	r18	// Temporary register 3#define s_data		 	r19	// SPI data#define u_data		 	r20	// UART data#define device		 	r21	// Device code//.#define	lockmode	r22	// Param to set correct lockbit read/write mode #define rd_s_data	 	r23	// Read data on SPI#define pol_cmd		 	r24	// Polling command#define p_data		 	r25	// Polling data//r26,r27 used as X register#define addrl		 	r28	// (YL) Low order byte of address#define addrh		 	r29	// (YH) High order byte of address//r30,r31 used as Z register//**************************************************************************//// Interrupt Vectors////**************************************************************************	.section .text	.global isp_startisp_start:		rjmp	INIT			// Reset Handle		//*******************// Converted Macros//*******************init_ports:			// init ports	ldi	temp2,0xff		out	PORTD,temp2	ldi	temp2,0xff	out	PORTB,temp2	retcatch_ports:			// catch ports	ldi	temp2,(1<<TXD)	out	DDRD,temp2	ldi	temp2,(1<<RESET) | (1<<MOSI) | (1<<SCK) | (1<<LEDBIT)	out	DDRB,temp2	retrelease_ports:		// release ports	ldi	temp2,(1<<TXD)	out	DDRD,temp2	ldi	temp2,(1<<LEDBIT)	out	DDRB,temp2	retpas_RESET:			// set RESET passive	tst	device	brmi	m2				// S89 device	sbi	PORTB,RESET	rjmp	m3m2:	cbi	PORTB,RESETm3:			retact_RESET:			// set RESET active	tst	device	brmi	m4				// S89 device	cbi	PORTB,RESET	rjmp	m5m4:	sbi	PORTB,RESETm5:			ret		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	ret//table:				// load Z pointer//	ldi	ZL,lo8(pm(@0*2))		// low//	ldi	ZH,hi8(pm(@0*2))		// high//	ret//**************************************************************************//// FUNCTION//	u_init//// DESCRIPTION//	Initialize UART.////**************************************************************************u_init:		ldi	temp1,N				// set baud rate	out	UBRRL,temp1	ldi	temp1,(1<<TXEN)|(1<<RXEN) // initialize UART for TX and RX	out	UCSRB,temp1	ret//**************************************************************************//// FUNCTION//	getc//// DESCRIPTION//	Wait for start bit and receive a character on the UART Rx line.////**************************************************************************getc:	sbis	UCSRA,RXC			// wait until a character has been received	rjmp	getc	in	u_data,UDR			// Read byte from the UART	ret//**************************************************************************//// FUNCTION//	putc//// DESCRIPTION//	Send a character on the UART Tx line.////**************************************************************************putc:	sbis	UCSRA,UDRE		// test for TX register empty	rjmp	putc			// loop until TX empty	out	UDR,u_data			// send the byte	ret//**************************************************************************//// FUNCTION//	put_string//// DESCRIPTION//	Send Z - pointed null-terminated string on the UART Tx line.////**************************************************************************	put_string:	lpm	tst	r0	breq	ps_ret			// check for end of string (0x00)	mov	u_data,r0	rcall	putc			// putc(char)

⌨️ 快捷键说明

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