
//MEGA2560芯片寄存器地址及配置

unit register
{
	//芯片中断类型
	public unit WATCH
	{
		public const uint16 INT0 = 0x0002;
		public const uint16 INT1 = 0x0004;
		public const uint16 INT2 = 0x0006;
		public const uint16 INT3 = 0x0008;
		public const uint16 INT4 = 0x000A;
		public const uint16 INT5 = 0x000C;
		public const uint16 INT6 = 0x000E;
		public const uint16 INT7 = 0x0010;
		
		public const uint16 PCINT0 = 0x0012;
		public const uint16 PCINT1 = 0x0014;
		public const uint16 PCINT2 = 0x0016;
		
		public const uint16 WDT = 0x0018;
		
		public const uint16 TIMER2_COMPA = 0x001A;
		public const uint16 TIMER2_COMPB = 0x001C;
		public const uint16 TIMER2_OVF = 0x001E;
		
		public const uint16 TIMER1_CAPT = 0x0020;
		public const uint16 TIMER1_COMPA = 0x0022;
		public const uint16 TIMER1_COMPB = 0x0024;
		public const uint16 TIMER1_COMPC = 0x0026;
		public const uint16 TIMER1_OVF = 0x0028;
		
		public const uint16 TIMER0_COMPA = 0x002A;
		public const uint16 TIMER0_COMPB = 0x002C;
		public const uint16 TIMER0_OVF = 0x002E;
		
		public const uint16 SPI_STC = 0x0030;
		
		public const uint16 USART0_RX = 0x0032;
		public const uint16 USART0_UDRE = 0x0034;
		public const uint16 USART0_TX = 0x0036;
		
		public const uint16 ANALOG_COMP = 0x0038;
		public const uint16 ADC = 0x003A;

		public const uint16 EE_READY = 0x003C;
		
		public const uint16 TIMER3_CAPT = 0x003E;
		public const uint16 TIMER3_COMPA = 0x0040;
		public const uint16 TIMER3_COMPB = 0x0042;
		public const uint16 TIMER3_COMPC = 0x0044;
		public const uint16 TIMER3_OVF = 0x0046;
		
		public const uint16 USART1_RX = 0x0048;
		public const uint16 USART1_UDRE = 0x004A;
		public const uint16 USART1_TX = 0x004C;
		
		public const uint16 TWI = 0x004E;
		public const uint16 SPM_READY = 0x0050;
		
		public const uint16 TIMER4_CAPT = 0x0052;
		public const uint16 TIMER4_COMPA = 0x0054;
		public const uint16 TIMER4_COMPB = 0x0056;
		public const uint16 TIMER4_COMPC = 0x0058;
		public const uint16 TIMER4_OVF = 0x005A;
		
		public const uint16 TIMER5_CAPT = 0x005C;
		public const uint16 TIMER5_COMPA = 0x005E;
		public const uint16 TIMER5_COMPB = 0x0060;
		public const uint16 TIMER5_COMPC = 0x0062;
		public const uint16 TIMER5_OVF = 0x0064;
		
		public const uint16 USART2_RX = 0x0066;
		public const uint16 USART2_UDRE = 0x0068;
		public const uint16 USART2_TX = 0x006A;
		
		public const uint16 USART3_RX = 0x006C;
		public const uint16 USART3_UDRE = 0x006E;
		public const uint16 USART3_TX = 0x0070;
	}
	
	//堆栈指针
	public uint8 SP_LOW	= #addr 0x5d;
	public uint8 SP_HIGH	= #addr 0x5e;
	public uint16 SP	= #addr 0x5d;  // 16 bit access
	
	//状态寄存器
	public uint8 SREG	= #addr 0x5f;
	
	//端口
	public uint8 PINA		= #addr 0x20;
	public uint8 DDRA		= #addr 0x21;
	public uint8 PORTA	= #addr 0x22;
	
	public uint8 PINB		= #addr 0x23;
	public uint8 DDRB		= #addr 0x24;
	public uint8 PORTB	= #addr 0x25;
	
	public uint8 PINC		= #addr 0x26;
	public uint8 DDRC		= #addr 0x27;
	public uint8 PORTC	= #addr 0x28;
	
	public uint8 PIND		= #addr 0x29;
	public uint8 DDRD		= #addr 0x2A;
	public uint8 PORTD	= #addr 0x2B;
	
	public uint8 PINE		= #addr 0x2C;
	public uint8 DDRE		= #addr 0x2D;
	public uint8 PORTE	= #addr 0x2E;
	
	public uint8 PINF		= #addr 0x2F;
	public uint8 DDRF		= #addr 0x30;
	public uint8 PORTF	= #addr 0x31;
	
	public uint8 PING		= #addr 0x32;
	public uint8 DDRG		= #addr 0x33;
	public uint8 PORTG	= #addr 0x34;
	
	public uint8 PINH		= #addr 0x0100;
	public uint8 DDRH		= #addr 0x0101;
	public uint8 PORTH	= #addr 0x0102;
	
	public uint8 PINJ		= #addr 0x0103;
	public uint8 DDRJ		= #addr 0x0104;
	public uint8 PORTJ	= #addr 0x0105;
	
	public uint8 PINK		= #addr 0x0106;
	public uint8 DDRK		= #addr 0x0107;
	public uint8 PORTK	= #addr 0x0108;
	
	public uint8 PINL		= #addr 0x0109;
	public uint8 DDRL		= #addr 0x010A;
	public uint8 PORTL	= #addr 0x010B;
	
	//看门狗
	public uint8 WDTCSR 	= #addr 0x60;
	//CPU状态寄存器
	public uint8 MCUSR	= #addr 0x54;
	public uint8 MCUCR	= #addr 0x55;
	
	//定时/计数器0
	public uint8 TCCR0A	= #addr 0x44;
	public uint8 TCCR0B	= #addr 0x45;
	public uint8 TCNT0	= #addr 0x46;
	public uint8 OCR0A	= #addr 0x47;
	public uint8 OCR0B	= #addr 0x48;
	public uint8 TIMSK0	= #addr 0x6E;
	public uint8 TIFR0	= #addr 0x35;
	
	//AD转换控制
	public uint8 ADCL	= #addr 0x78;
	public uint8 ADCH	= #addr 0x79;
	public uint8 ADCSRA	= #addr 0x7A;
	public uint8 ADCSRB	= #addr 0x7B;
	public uint8 ADMUX	= #addr 0x7C;
	
	public uint8 EICRA	= #addr 0x69;
	public uint8 EIMSK	= #addr 0x3D;
	public uint8 EIFR		= #addr 0x3C;
	
	//定时/计数器1
	public uint8 OCR1AH = #addr 0x89;
	public uint8 OCR1AL = #addr 0x88;
	public uint8 TCNT1H = #addr 0x85;
	public uint8 TCNT1L = #addr 0x84;
	public uint8 TCCR1C = #addr 0x82;
	public uint8 TCCR1B = #addr 0x81;
	public uint8 TCCR1A = #addr 0x80;
	public uint8 TIMSK1 = #addr 0x6F;
	public uint8 TIFR1 = #addr 0x36;
	
	//定时/计数器2
	public uint8 TIMSK2 = #addr 0x70;
	public uint8 OCR2B	= #addr 0xB4;
	public uint8 OCR2A	= #addr 0xB3;
	public uint8 TCNT2	= #addr 0xB2;
	public uint8 TCCR2B	= #addr 0xB1;
	public uint8 TCCR2A	= #addr 0xB0;
	
	//UART0串口控制
	public uint8 UCSR0A	= #addr 0xC0;
	public uint8 UCSR0B	= #addr 0xC1;
	public uint8 UCSR0C	= #addr 0xC2;
	public uint8 UBRR0L	= #addr 0xC4;
	public uint8 UBRR0H	= #addr 0xC5;
	public uint8 UDR0		= #addr 0xC6;
	
	//UART1串口控制
	public uint8 UCSR1A	= #addr 0xC8;
	public uint8 UCSR1B	= #addr 0xC9;
	public uint8 UCSR1C	= #addr 0xCA;
	public uint8 UBRR1L	= #addr 0xCC;
	public uint8 UBRR1H	= #addr 0xCD;
	public uint8 UDR1		= #addr 0xCE;
	
	//UART2串口控制
	public uint8 UCSR2A	= #addr 0xD0;
	public uint8 UCSR2B	= #addr 0xD1;
	public uint8 UCSR2C	= #addr 0xD2;
	public uint8 UBRR2L	= #addr 0xD4;
	public uint8 UBRR2H	= #addr 0xD5;
	public uint8 UDR2		= #addr 0xD6;
	
	//UART3串口控制
	public uint8 UCSR3A	= #addr 0x0130;
	public uint8 UCSR3B	= #addr 0x0131;
	public uint8 UCSR3C	= #addr 0x0132;
	public uint8 UBRR3L	= #addr 0x0134;
	public uint8 UBRR3H	= #addr 0x0135;
	public uint8 UDR3		= #addr 0x0136;
	
	//EEPROM
	public uint8 EECR =		#addr 0x3F;
	public uint8 EEDR =		#addr 0x40;
	public uint8 EEARL =		#addr 0x41;
	public uint8 EEARH =		#addr 0x42;
	
//	//定时/计数器2
//	public uint8 ASSR	= #addr 0x42;
//	public uint8 TCCR2	= #addr 0x45;
	
//	//定时/计数器1
//	public uint8 OCR1BL	= #addr 0x48;
//	public uint8 OCR1BH	= #addr 0x49;
//	//public N16 OCR1B	= #addr 0x48;  // 16 bit access
//	public uint8 OCR1AL	= #addr 0x4a;
//	public uint8 OCR1AH	= #addr 0x4b;
//	//public N16 OCR1A	= #addr 0x4a;  // 16 bit access
//	public uint8 TCNT1L	= #addr 0x4c;
//	public uint8 TCNT1H	= #addr 0x4d;
//	//public N16 TCNT1	= #addr 0x4c;  // 16 bit access
//	public uint8 TCCR1B	= #addr 0x4e;
//	public uint8 TCCR1A	= #addr 0x4f;
	
//	//定时/计数器0
//	public uint8 TCNT0	= #addr 0x52;
//	public uint8 TCCR0	= #addr 0x53;
//	public uint8 TIFR	= #addr 0x58;
//	public uint8 OCR0	= #addr 0X5c;
	
//	//外部中断控制
//	public uint8 MCUCSR	= #addr 0x54;
//	public uint8 MCUCR	= #addr 0x55;
//	public uint8 TIMSK	= #addr 0x59;
//	public uint8 GIFR	= #addr 0x5a;
//	public uint8 GICR	= #addr 0x5b;
	
//	//TWI
//	public uint8 TWAR = #addr 0x22;
//	public uint8 TWCR = #addr 0x56;
	
//	//SPI
//	public uint8 SPCR = #addr 0x2d;
//	public uint8 SPSR = #addr 0x2e;
//	public uint8 SPDR = #addr 0x2f;
	
//	public uint8 SFIOR	= #addr 0x50;
}
















