➜Code

Manual

Instruction Manual


➜AVR IO defines

Manual

Instruction Manual

FIRMWARE.BIN➜

; .-== ATxmega128a3u ==-.

; Register alias:
	_replace __tmp_reg__, r0
	_replace __zero_reg__, r1

; Hardware constants:
	_replace RAMEND_HI, 0x3f
	_replace RAMEND_LO, 0xff

	_replace CCP_SPM_gc, 0x9d
	_replace CCP_IOREG_gc, 0xd8

; MCU IO register memory addresses
	_replace CCP, 0x0034
	_replace RAMPD, 0x0038
	_replace RAMPX, 0x0039
	_replace RAMPY, 0x003a
	_replace RAMPZ, 0x003b
	_replace EIND, 0x003c
	_replace SPL, 0x003d
	_replace SPH, 0x003e
	_replace SPH, 0x003F

; Clock System
	_replace CLK_CTRL, 0x0040
	_replace CLK_PSCTRL, 0x0041
	_replace CLK_LOCK, 0x0042
	_replace CLK_RTCCTRL, 0x0043
	_replace CLK_USBCTRL, 0x0044

; Sleep Controller
	_replace SLEEP_CTRL, 0x0048

; Oscillator
	_replace OSC_CTRL, 0x0050
	_replace OSC_STATUS, 0x0051
	_replace OSC_XOSCCTRL, 0x0052
	_replace OSC_XOSCFAIL, 0x0053
	_replace OSC_RC32KCAL, 0x0054
	_replace OSC_PLLCTRL, 0x0055
	_replace OSC_DFLLCTRL, 0x0056

; MCU Control
	_replace MCU_DEVID0, 0x0090
	_replace MCU_DEVID1, 0x0091
	_replace MCU_DEVID2, 0x0092
	_replace MCU_REVID, 0x0093
	_replace MCU_JTAGUID, 0x0094
	_replace MCU_MCUCR, 0x0096
	_replace MCU_ANAINIT, 0x0097
	_replace MCU_EVSYSLOCK, 0x0098
	_replace MCU_AWEXLOCK, 0x0099


; common IO register memory addresses
	_replace PORTA_DIR, 0x0600
	_replace PORTA_OUT, 0x0604
	_replace PORTA_IN, 0x0608
	_replace PORTB_DIR, 0x0620
	_replace PORTB_OUT, 0x0624
	_replace PORTB_IN, 0x0628
	_replace PORTC_DIR, 0x0640
	_replace PORTC_OUT, 0x0644
	_replace PORTC_IN, 0x0648
	_replace PORTD_DIR, 0x0660
	_replace PORTD_OUT, 0x0664
	_replace PORTD_IN, 0x0668
	_replace PORTE_DIR, 0x0680
	_replace PORTE_OUT, 0x0684
	_replace PORTE_IN, 0x0688
	_replace PORTF_DIR, 0x06a0
	_replace PORTF_OUT, 0x06a4
	_replace PORTF_IN, 0x06a8
	_replace PORTR_DIR, 0x07e0
	_replace PORTR_OUT, 0x07e4
	_replace PORTR_IN, 0x07e8

; Rest and Interrupt table for ATmega168
	_loc 0
	jmp __start		;   0: Reset Handler
	jmp IgnoreINT		;   1: Oscillator Failure Interrupt (NMI)
	jmp IgnoreINT		;   2: PORTC External Interrupt 0
	jmp IgnoreINT		;   3: PORTC External Interrupt 1
	jmp IgnoreINT		;   4: PORTR External Interrupt 0
	jmp IgnoreINT		;   5: PORTR External Interrupt 1
	jmp IgnoreINT		;   6: DMA Channel 0 Interrupt
	jmp IgnoreINT		;   7: DMA Channel 1 Interrupt
	jmp IgnoreINT		;   8: DMA Channel 2 Interrupt
	jmp IgnoreINT		;   9: DMA Channel 3 Interrupt
	jmp IgnoreINT		;  10: RTC Overflow Interrupt
	jmp IgnoreINT		;  11: RTC Compare Interrupt
	jmp IgnoreINT		;  12: TWIC TWI Slave Interrupt
	jmp IgnoreINT		;  13: TWIC TWI Master Interrupt
	jmp IgnoreINT		;  14: TCC0 Overflow Interrupt
	jmp IgnoreINT		;  15: TCC0 Error Interrupt
	jmp IgnoreINT		;  16: TCC0 Compare or Capture A Interrupt
	jmp IgnoreINT		;  17: TCC0 Compare or Capture B Interrupt
	jmp IgnoreINT		;  18: TCC0 Compare or Capture C Interrupt
	jmp IgnoreINT		;  19: TCC0 Compare or Capture D Interrupt
	jmp IgnoreINT		;  20: TCC1 Overflow Interrupt
	jmp IgnoreINT		;  21: TCC1 Error Interrupt
	jmp IgnoreINT		;  22: TCC1 Compare or Capture A Interrupt
	jmp IgnoreINT		;  23: TCC1 Compare or Capture B Interrupt
	jmp IgnoreINT		;  24: SPIC SPI Interrupt
	jmp IgnoreINT		;  25: USARTC0 Reception Complete Interrupt
	jmp IgnoreINT		;  26: USARTC0 Data Register Empty Interrupt
	jmp IgnoreINT		;  27: USARTC0 Transmission Complete Interrupt
	jmp IgnoreINT		;  28: USARTC1 Reception Complete Interrupt
	jmp IgnoreINT		;  29: USARTC1 Data Register Empty Interrupt
	jmp IgnoreINT		;  30: USARTC1 Transmission Complete Interrupt
	jmp IgnoreINT		;  31: AES Interrupt
	jmp IgnoreINT		;  32: NVM EE Interrupt
	jmp IgnoreINT		;  33: NVM SPM Interrupt
	jmp IgnoreINT		;  34: PORTB External Interrupt 0
	jmp IgnoreINT		;  35: PORTB External Interrupt 1
	jmp IgnoreINT		;  36: ACB AC0 Interrupt
	jmp IgnoreINT		;  37: ACB AC1 Interrupt
	jmp IgnoreINT		;  38: ACB ACW Window Mode Interrupt
	jmp IgnoreINT		;  39: ADCB Interrupt 0
	jmp IgnoreINT		;  40: ADCB Interrupt 1
	jmp IgnoreINT		;  41: ADCB Interrupt 2
	jmp IgnoreINT		;  42: ADCB Interrupt 3
	jmp IgnoreINT		;  43: PORTE External Interrupt 0
	jmp IgnoreINT		;  44: PORTE External Interrupt 1
	jmp IgnoreINT		;  45: TWIE TWI Slave Interrupt
	jmp IgnoreINT		;  46: TWIE TWI Master Interrupt
	jmp IgnoreINT		;  47: TCE0 Overflow Interrupt
	jmp IgnoreINT		;  48: TCE0 Error Interrupt
	jmp IgnoreINT		;  49: TCE0 Compare or Capture A Interrupt
	jmp IgnoreINT		;  50: TCE0 Compare or Capture B Interrupt
	jmp IgnoreINT		;  51: TCE0 Compare or Capture C Interrupt
	jmp IgnoreINT		;  52: TCE0 Compare or Capture D Interrupt
	jmp IgnoreINT		;  53: TCE1 Overflow Interrupt
	jmp IgnoreINT		;  54: TCE1 Error Interrupt
	jmp IgnoreINT		;  55: TCE1 Compare or Capture A Interrupt
	jmp IgnoreINT		;  56: TCE1 Compare or Capture B Interrupt
	jmp IgnoreINT		;  57: SPIE SPI Interrupt
	jmp IgnoreINT		;  58: USARTE0 Reception Complete Interrupt
	jmp IgnoreINT		;  59: USARTE0 Data Register Empty Interrupt
	jmp IgnoreINT		;  60: USARTE0 Transmission Complete Interrupt
	jmp IgnoreINT		;  61: USARTE1 Reception Complete Interrupt
	jmp IgnoreINT		;  62: USARTE1 Data Register Empty Interrupt
	jmp IgnoreINT		;  63: USARTE1 Transmission Complete Interrupt
	jmp IgnoreINT		;  64: PORTD External Interrupt 0
	jmp IgnoreINT		;  65: PORTD External Interrupt 1
	jmp IgnoreINT		;  66: PORTA External Interrupt 0
	jmp IgnoreINT		;  67: PORTA External Interrupt 1
	jmp IgnoreINT		;  68: ACA AC0 Interrupt
	jmp IgnoreINT		;  69: ACA AC1 Interrupt
	jmp IgnoreINT		;  70: ACA ACW Window Mode Interrupt
	jmp IgnoreINT		;  71: ADCA Interrupt 0
	jmp IgnoreINT		;  72: ADCA Interrupt 1
	jmp IgnoreINT		;  73: ADCA Interrupt 2
	jmp IgnoreINT		;  74: ADCA Interrupt 3
	jmp IgnoreINT		;  75:
	jmp IgnoreINT		;  76:
	jmp IgnoreINT		;  77: TCD0 Overflow Interrupt
	jmp IgnoreINT		;  78: TCD0 Error Interrupt
	jmp IgnoreINT		;  79: TCD0 Compare or Capture A Interrupt
	jmp IgnoreINT		;  80: TCD0 Compare or Capture B Interrupt
	jmp IgnoreINT		;  81: TCD0 Compare or Capture C Interrupt
	jmp IgnoreINT		;  82: TCD0 Compare or Capture D Interrupt
	jmp IgnoreINT		;  83: TCD1 Overflow Interrupt
	jmp IgnoreINT		;  84: TCD1 Error Interrupt
	jmp IgnoreINT		;  85: TCD1 Compare or Capture A Interrupt
	jmp IgnoreINT		;  86: TCD1 Compare or Capture B Interrupt
	jmp IgnoreINT		;  87: SPID SPI Interrupt
	jmp IgnoreINT		;  88: USARTD0 Reception Complete Interrupt
	jmp IgnoreINT		;  89: USARTD0 Data Register Empty Interrupt
	jmp IgnoreINT		;  90: USARTD0 Transmission Complete Interrupt
	jmp IgnoreINT		;  91: USARTD1 Reception Complete Interrupt
	jmp IgnoreINT		;  92: USARTD1 Data Register Empty Interrupt
	jmp IgnoreINT		;  93: USARTD1 Transmission Complete Interrupt
	jmp IgnoreINT		;  94:
	jmp IgnoreINT		;  95:
	jmp IgnoreINT		;  96:
	jmp IgnoreINT		;  97:
	jmp IgnoreINT		;  98:
	jmp IgnoreINT		;  99:
	jmp IgnoreINT		; 100:
	jmp IgnoreINT		; 101:
	jmp IgnoreINT		; 102:
	jmp IgnoreINT		; 103:
	jmp IgnoreINT		; 104: PORTF External Interrupt 0
	jmp IgnoreINT		; 105: PORTF External Interrupt 1
	jmp IgnoreINT		; 106:
	jmp IgnoreINT		; 107:
	jmp IgnoreINT		; 108: TCF0 Low Byte Underflow Interrupt
	jmp IgnoreINT		; 109: TCF0 Error Interrupt
	jmp IgnoreINT		; 110: TCF0 Compare or Capture A Interrupt
	jmp IgnoreINT		; 111: TCF0 Compare or Capture B Interrupt
	jmp IgnoreINT		; 112: TCF0 Compare or Capture C Interrupt
	jmp IgnoreINT		; 113: TCF0 Compare or Capture D Interrupt
	jmp IgnoreINT		; 114:
	jmp IgnoreINT		; 115:
	jmp IgnoreINT		; 116:
	jmp IgnoreINT		; 117:
	jmp IgnoreINT		; 118:
	jmp IgnoreINT		; 119: USARTF0 Reception Complete Interrupt
	jmp IgnoreINT		; 120: USARTF0 Data Register Empty Interrupt
	jmp IgnoreINT		; 121: USARTF0 Transmission Complete Interrupt
	jmp IgnoreINT		; 122:
	jmp IgnoreINT		; 123:
	jmp IgnoreINT		; 124:
	jmp IgnoreINT		; 125: USB SOF, suspend, resume, reset bus event interrupts, crc, underflow, overflow and stall error interrupts
	jmp IgnoreINT		; 126: USB Transaction complete interrupt

IgnoreINT:
	_loc 512
	reti

__start:
; Deactivate interrupts
	cli

; Set Stack Pointer to end of RAM
	ldi	r16, RAMEND_HI
	out	SPH, r16
	ldi	r16, RAMEND_LO
	out	SPL, r16

; clear registers
	clr	r16
	clr	__zero_reg__
	out	EIND, __zero_reg__

; call main
	call	main

; stop program execution
	cli		
	ldi	r16, 0x05
	sts	SLEEP_CTRL, r16
__exit:
	sleep
	rjmp	__exit
	
; AVR ATxmega128a3u main program

main:
	ldi	r17, 0xff
	sts	PORTB_DIR, r17
	clr	r31
	clr	r30

; disable JTAG PORT to free PB4..PB7 for blink

	ldi	r18, 1
	ldi	r17, CCP_IOREG_gc
	sts	CCP, r17
	sts	MCU_MCUCR, r18



delayloop:
	sbiw	r30, 1
	brne	delayloop

	lds	r17, PORTB_OUT
	subi	r17, 0xff
	sts	PORTB_OUT, r17

	rjmp	delayloop