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

📄 8051int.h

📁 8051单片机的ucos移植
💻 H
字号:
/*
 * This macro allows you to use a 'C' function to handle an 8051 interrupt.
 *
 * The only parameter is the DECIMAL address of the interrupt vector.
 * Defines are provided for the common values.
 *
 * The macro MUST be placed IMMEDIATELY preceeding the definition of the
 * function which is to be the interrupt handler. Example:
 *
 * 		INTERRUPT(_SER_) serial_int_handler()
 * 		{
 *			/* ... Function code to handle serial interrupt ... */
 *		}
 *
 * BEFORE USING THIS MACRO... Make sure that the startup code leaves
 * room for the interrupt vectors ($0003 - $0032), Use something like
 * this at the beginning of the "prefix" file:
 *
 *					AJMP	*+$0032		Jump around vectors
 *					DS		$0032-2		Reserve space for vectors
 *
 * Unfortunately, the code generated by the compiler and in the runtime
 * library sometimes has to reference registers by address. This means
 * that we cannot simply "switch" the register bank during the interrupt,
 * but have to "push/pop" all of the registers instead.
 *
 ***NOTE 1: If you are using the -Z (2K addressing) option, which translates
 * LCALLs into ACALLs, you MUST change the offset in the LCALL instruction
 * below to 51 (instead of 52 which is required when not using -Z).
 *
 ***NOTE 2: If you are using a memory model with an EXTERNAL stack, and have
 * interrupt handlers written in C that use the external stack (ie: have local
 * variables), you must modify the runtime library functions which manipulate
 * the external stack pointer to disable interrupts during those manipulations
 * (look for references to ?stack in 8051RLP?.ASM, the main problem occurs in
 * the ?adjex1/?adjex2 routine if the interrupt happens after the low byte of
 * the stack pointer has been adjusted, but before the upper byte is updated).
 *
 * This file **REQUIRES** the extended pre-processor (MCP).
 * (CC51 ... -P, or "Preprocess" step enabled in DDSIDE)
 *
 * Copyright 1991-2000 Dave Dunfield
 * All rights reserved.
 */

/*
 * The following symbol must be set to the address of the interrupt vector
 * table. For ROM based system, this will be 0, which is the start of the
 * ROM. When running under a debugger (such as MON51 or MONICA), this must
 * be changed to the address to which the debugger re-vectors interrupts.
 */
#define INTBASE $8000           /* MONICA base program address (decimal) */

#define	INTERRUPT(vec) asm {\
$SE:0						/* Insure output in code segment */\
_/**/vec	/* This label will be the address of the "prefix" stub */\
		ORG		INTBASE+vec	/* Position to interrupt vector */\
		PUSH	PSW			/* Save Processor Status Word */\
		PUSH	A			/* Save accumulator (2 bytes) */\
		LJMP	_/**/vec	/* Don't overwrite next vector (+3 = 7) */\
		ORG		_/**/vec	/* Position back to original PC */\
		PUSH	B			/* Save B register (+2 = 4) */\
		PUSH	DPH			/* Save Data Pointer (HIGH)*/\
		PUSH	DPL			/* Save Data Pointer (LOW)*/\
		PUSH	0			/* Save R0 */\
		PUSH	1			/* Save R1 */\
		PUSH	2			/* Save R2 */\
		PUSH	3			/* Save R3 */\
		PUSH	4			/* Save R4 */\
		PUSH	5			/* Save R5 */\
		PUSH	6			/* Save R6 */\
		PUSH	7			/* Save R7 */\
		LCALL	_/**/vec+52	/* Invoke 'C' function. *SEE NOTE ABOVE*/\
		POP		7			/* Restore R7 */\
		POP		6			/* Restore R6 */\
		POP		5			/* Restore R5 */\
		POP		4			/* Restore R4 */\
		POP		3			/* Restore R3 */\
		POP		2			/* Restore R2 */\
		POP		1			/* Restore R1 */\
		POP		0			/* Restore R0 */\
		POP		DPL			/* Restore Data Pointer (LOW) */\
		POP		DPH			/* Restore Data Pointer (HIGH) */\
		POP		B			/* Restore B register */\
		POP		A			/* Restore A accumulator */\
		POP		PSW			/* Restore Processor Status Word */\
		RETI				/* End interrupt */\
}
#undef	INTBASE

/*
 * Common 8052 interrupt vector addresses (Must be decimal)
 */
#define	_IE0_	3		/* External interrupt 0 */
#define	_TF0_	11		/* Timer 0 rollover */
#define	_IE1_	19		/* External interrupt 1 */
#define	_TF1_	27		/* Timer 1 rollover */
#define	_SER_	35		/* Serial port RX or TX */
#define	_TF2_	43		/* Timer 2 rollover */
#define	_EXF2_	43		/* Timer 2 external flag */
//03079

⌨️ 快捷键说明

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