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

📄 intelhex.c

📁 AVR反汇编,对ATMEGA8有效
💻 C
字号:
#include <string.h>/*  Program: revava - Atmel Dis-Assembler  File: IntelHex.C, Copyright (C) 2001 Daniel J. Winker  2006.01.14: tightened up input screening -- john.cooper@member.fsf.org  This program is free software; you can redistribute it and/or  modify it under the terms of the GNU General Public License  as published by the Free Software Foundation; either version 2  of the License, or (at your option) any later version.  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License for more details.  You should have received a copy of the GNU General Public License  along with this program; if not, write to the Free Software  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*/// Format://     :CCAAAARR...ZZ//// where://     CC   is the number of data bytes//     AAAA is the address field//     RR   is the record type://             00 data record//             01 end record//             02 paragraph record//             03 transfer address record//     ...  is the Data field//     ZZ   is the checksum for data record//// All fields in an Intel hex record are in hexadecimal with two hex digits// representing a byte. The CC field is the actual number of bytes in the data// field (the address, record type, and checksum bytes are not included in the// count). The checksum is the two's complement of the sum of the bytes from// the number of data bytes field through the last byte of the data field.#include <stdio.h>#include "Error.h"#include "IntelHex.h"#define MSGSZ	160#define asc2x(c) ('0' <= (c) && (c) <= '9' ? (c) - '0' : \	'a' <= (c) && (c) <= 'f' ? (c) - 'a' + 10 : \	'A' <= (c) && (c) <= 'F' ? (c) - 'A' + 10 : -1) static unsigned char Ascii2Hex(const char* ps, const char *line){	signed char h, l;	if ((h = asc2x(*ps)) < 0 || (++ps, l = asc2x(*ps)) < 0) {		char buf[MSGSZ];		//snprintf(buf, MSGSZ, "Invalid hex char in line:\n%s", line);		//_snprintf(buf, MSGSZ, "Invalid hex char in line:\n%s", line);		sprintf(buf, "Invalid hex char in line:\n%s", line);		throw TGenericError(buf);	}	return (h << 4 | l);}void TIntelHexRecord::StringToRecord(const char* ps){	const char* pc;	unsigned char uc;	unsigned char cs = 0;	unsigned char n;	pc = ps;	if( *pc++ != ':' ){		char msg[MSGSZ];		/*_snprintf(msg, MSGSZ,			"StringToRecord: Invalid Record (doesn't begin with ':'):\n"			"\"%s\"", ps );*/		sprintf(msg,			"StringToRecord: Invalid Record (doesn't begin with ':'):\n"			"\"%s\"", ps );		throw TGenericError( msg );	}	nbytes = Ascii2Hex(pc, ps);	cs    -= nbytes;	pc    += 2;	uc     = Ascii2Hex(pc, ps);	cs    -= uc;	addr   = uc << 8;	pc    += 2;	uc     = Ascii2Hex(pc, ps);	cs    -= uc;	addr  |= uc;	pc    += 2;	type   = Ascii2Hex(pc, ps);	cs    -= type;	pc    += 2;	for( n = 0; n < nbytes; n++ ){		uc        = Ascii2Hex(pc, ps);		cs       -= uc;		data[ n ] = uc;		pc       += 2;	}	if( Ascii2Hex(pc, ps) != cs ){		char msg[MSGSZ];		/*_snprintf(msg, MSGSZ,			"Invalid Record (bad checksum)\n"			"%s", ps );*/		sprintf(msg,			"Invalid Record (bad checksum)\n"			"%s", ps );		throw TGenericError( msg );	}}

⌨️ 快捷键说明

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