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

unit register
{
	//芯片中断类型
	public unit WATCH
	{
		public const uint16 INT0 = 0x0002;
		public const uint16 INT1 = 0x0004;
		
		public const uint16 PCINT0 = 0x0006;
		public const uint16 PCINT1 = 0x0008;
		public const uint16 PCINT2 = 0x000A;
		
		public const uint16 WDT = 0x000C;
		
		public const uint16 TIMER2_COMPA = 0x000E;
		public const uint16 TIMER2_COMPB = 0x0010;
		public const uint16 TIMER2_OVF = 0x0012;
		
		public const uint16 TIMER1_CAPT = 0x0014;
		public const uint16 TIMER1_COMPA = 0x0016;
		public const uint16 TIMER1_COMPB = 0x0018;
		public const uint16 TIMER1_OVF = 0x001A;
		
		public const uint16 TIMER0_COMPA = 0x001C;
		public const uint16 TIMER0_COMPB = 0x001E;
		public const uint16 TIMER0_OVF = 0x0020;
		
		public const uint16 SPI_STC = 0x0022;
		
		public const uint16 USART_RX = 0x0024;
		public const uint16 USART_UDRE = 0x0026;
		public const uint16 USART_TX = 0x0028;
		
		public const uint16 ADC = 0x002A;
		public const uint16 EE_READY = 0x002C;
		public const uint16 ANALOG_COMP = 0x002E;
		public const uint16 TWI = 0x0030;
		public const uint16 SPM_READY = 0x0032;
	}
	
	//堆栈指针
	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 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 WDTCSR 	= #addr 0x60;
	//CPU状态寄存器
	public uint8 MCUSR	= #addr 0x54;
	
	//定时/计数器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 DIDR0	= #addr 0x7E;
	
	public uint8 EICRA	= #addr 0x69;
	public uint8 EIMSK	= #addr 0x3D;
	public uint8 EIFR		= #addr 0x3C;
	
	//定时/计数器1
	public uint8 OCR1BH = #addr 0x8B;
	public uint8 OCR1BL = #addr 0x8A;
	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 OCR2B = #addr 0xB4;
	public uint8 OCR2A = #addr 0xB3;
	public uint8 TCNT2 = #addr 0xB2;
	public uint8 TCCR2B = #addr 0xB1;
	public uint8 TCCR2A = #addr 0xB0;
	public uint8 TIMSK2 = #addr 0x70;
	public uint8 TIFR2 = #addr 0x37;
	
	//UART串口控制
	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;
	
	//EEPROM
	public uint8 EECR =		#addr 0x3F;
	public uint8 EEDR =		#addr 0x40;
	public uint8 EEARL =		#addr 0x41;
	public uint8 EEARH =		#addr 0x42;
	
	//SPI
	public uint8 SPCR = #addr 0x4C;
	public uint8 SPSR = #addr 0x4D;
	public uint8 SPDR = #addr 0x4E;
	
//	//定时/计数器2
//	public uint8 ASSR	= #addr 0x42;
//	public uint8 OCR2	= #addr 0x43;
//	public uint8 TCNT2	= #addr 0x44;
//	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;
	
//	public uint8 SFIOR	= #addr 0x50;
}
















