; author: hackbard@hackdaworld.org
;
+; device specific definition file
+.include "../include/m128def.inc"
+
; defines
-.define tmp = r16
+.def tmp1 = r16
+.def tmp2 = r17
+.def uart_rxtx = r18
; interrupts
jmp RESET
jmp TWI
jmp SPM_RDY
-; include subroutines
-.include "motor.asm"
-.include "uart.asm"
+; include control defines
+.include "ctrl.def"
RESET:
INIT:
; motor init
- call
+ rcall MOTOR_INIT
+
; uart init
+ rcall UART_INIT
+
+ ; uart interrupt enable
+ rcall UART_INT_RX_INIT
; set stackpointer
- ldi r16, high(RAMEND)
- out SPH,r16
- ldi r16, low(RAMEND)
- out SPL,r16
+ ldi tmp1,high(RAMEND)
+ out SPH,tmp1
+ ldi tmp1,low(RAMEND)
+ out SPL,tmp1
; global interrupt enable
- sei
+ ;sei
+
+ ; signal ready output
+ ldi uart_rxtx,0x23
+ rcall UART_TX
+MAIN:
+ ; loop forever
+ rjmp MAIN
+
+
+; include subroutines
+.include "motor.asm"
+.include "uart.asm"
;
;
EXT_INT0:
- nop
reti
EXT_INT1:
- nop
reti
EXT_INT2:
- nop
reti
EXT_INT3:
- nop
reti
EXT_INT4:
- nop
reti
EXT_INT5:
- nop
reti
EXT_INT6:
- nop
reti
EXT_INT7:
- nop
reti
TIM2_COMP:
- nop
reti
TIM2_OVF:
- nop
reti
TIM1_CAPT:
- nop
reti
TIM1_COMPA:
- nop
reti
TIM1_COMPB:
- nop
reti
TIM1_OVF:
- nop
reti
TIM0_COMP:
- nop
reti
TIM0_OVF:
- nop
reti
SPI_STC:
- nop
reti
USART0_RXC:
; read received byte and drive the motor
; in addition, loop it back to the host
- in UDR
+ ; receive routine (byte stored in uart_rxtx)
+ rcall UART_RX
+
+ ; loop back the received byte
+ rcall UART_TX
+
+ ;
+ ; drive the motor
+ ;
+
+ ; stop it first
+ rcall MOTOR_STOP
+
+ ; fwd
+ cpi uart_rxtx,CTRL_FWD
+ brne CTRL1
+ rcall MOTOR_FWD
+ rjmp CTRL4
+
+ ; bwd
+ CTRL1:
+ cpi uart_rxtx,CTRL_BWD
+ brne CTRL2
+ rcall MOTOR_BWD
+ rjmp CTRL4
+
+ ; right
+ CTRL2:
+ cpi uart_rxtx,CTRL_RIGHT
+ brne CTRL3
+ rcall MOTOR_RIGHT
+ rjmp CTRL4
+
+ ; left
+ CTRL3:
+ cpi uart_rxtx,CTRL_LEFT
+ brne CTRL4
+ rcall MOTOR_LEFT
+ CTRL4:
+ ; return
reti
USART0_DRE:
- nop
reti
USART0_TXC:
- nop
reti
ADC:
- nop
reti
EE_RDY:
- nop
reti
ANA_COMP:
- nop
reti
TIM1_COMPC:
- nop
reti
TIM3_CAPT:
- nop
reti
TIM3_COMPA:
- nop
reti
TIM3_COMPB:
- nop
reti
TIM3_COMPC:
- nop
reti
TIM3_OVF:
- nop
reti
USART1_RXC:
- nop
reti
USART1_DRE:
- nop
reti
USART1_TXC:
- nop
reti
TWI:
- nop
reti
SPM_RDY:
- nop
reti