; author: hackbard@hackdaworld.org
;
+; device specific definition file
+.include "../include/m128def.inc"
+
; defines
-.define tmp = r16
+.def tmp = r16
+.def uart_rxtx = r17
+.def tmp_motor = 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
; uart init
+ rcall UART_INIT
+
+ ; motor init
+ rcall MOTOR_INIT
+
+ ; uart interrupt enable
+ rcall UART_INT_RX_INIT
; set stackpointer
- ldi r16, high(RAMEND)
+ ldi tmp,high(RAMEND)
out SPH,r16
- ldi r16, low(RAMEND)
+ ldi tmp,low(RAMEND)
out SPL,r16
; global interrupt enable
sei
+ ; debug 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
+ rcall MOTOR_STOP
+ cpi uart_rxtx,CTRL_FWD
+ brne CTRL1
+ rcall MOTOR_FWD
+ rjmp CTRL4
+ CTRL1:
+ cpi uart_rxtx,CTRL_BWD
+ brne CTRL2
+ rcall MOTOR_BWD
+ rjmp CTRL4
+ CTRL2:
+ cpi uart_rxtx,CTRL_RIGHT
+ brne CTRL3
+ rcall MOTOR_RIGHT
+ rjmp CTRL4
+ CTRL3:
+ cpi uart_rxtx,CTRL_LEFT
+ brne CTRL4
+ rcall MOTOR_LEFT
+ CTRL4:
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
; motor functions
-;include "../include/m128def.inc"
-
.equ MOT_DIR_L = 0x02
.equ MOT_DIR_R = 0x03
.equ MOT_PWR_L = 0x04
.equ MOT_PWR_R = 0x07
-;.def tmp = r17
-
MOTOR_INIT:
; ports -> output
- in tmp,DDRB
- sbr tmp,(1<<MOT_DIR_L)|(1<<MOT_DIR_R)
- sbr tmp,(1<<MOT_PWR_L)|(1<<MOT_PWR_R)
- out DDRB,tmp
+ in tmp_motor,DDRB
+ sbr tmp_motor,(1<<MOT_DIR_L)|(1<<MOT_DIR_R)
+ sbr tmp_motor,(1<<MOT_PWR_L)|(1<<MOT_PWR_R)
+ out DDRB,tmp_motor
MOTOR_STOP:
; output zero
- in tmp,PORTB
- cbr tmp,(1<<MOT_DIR_L)|(1<<MOT_DIR_R)
- cbr tmp,(1<<MOT_PWR_L)|(1<<MOT_PWR_R)
- out PORTB,tmp
+ in tmp_motor,PORTB
+ cbr tmp_motor,(1<<MOT_DIR_L)|(1<<MOT_DIR_R)
+ cbr tmp_motor,(1<<MOT_PWR_L)|(1<<MOT_PWR_R)
+ out PORTB,tmp_motor
ret
MOTOR_FWD:
- in tmp,PORTB
- sbr tmp,(1<<MOT_DIR_L)|(1<<MOT_DIR_R)
- sbr tmp,(1<<MOT_PWR_L)|(1<<MOT_PWR_R)
- out PORTB,tmp
+ in tmp_motor,PORTB
+ sbr tmp_motor,(1<<MOT_DIR_L)|(1<<MOT_DIR_R)
+ sbr tmp_motor,(1<<MOT_PWR_L)|(1<<MOT_PWR_R)
+ out PORTB,tmp_motor
ret
MOTOR_BWD:
- in tmp,PORTB
- cbr tmp,(1<<MOT_DIR_L)|(1<<MOT_DIR_R)
- sbr tmp,(1<<MOT_PWR_L)|(1<<MOT_PWR_R)
- out PORTB,tmp
+ in tmp_motor,PORTB
+ cbr tmp_motor,(1<<MOT_DIR_L)|(1<<MOT_DIR_R)
+ sbr tmp_motor,(1<<MOT_PWR_L)|(1<<MOT_PWR_R)
+ out PORTB,tmp_motor
ret
MOTOR_RIGHT:
- in tmp,PORTB
- sbr tmp,(1<<MOT_DIR_L)
- cbr tmp,(1<<MOT_DIR_R)
- sbr tmp,(1<<MOT_PWR_L)|(1<<MOT_PWR_R)
- out PORTB,tmp
+ in tmp_motor,PORTB
+ sbr tmp_motor,(1<<MOT_DIR_L)
+ cbr tmp_motor,(1<<MOT_DIR_R)
+ sbr tmp_motor,(1<<MOT_PWR_L)|(1<<MOT_PWR_R)
+ out PORTB,tmp_motor
ret
MOTOR_LEFT:
- in tmp,PORTB
- sbr tmp,(1<<MOT_DIR_R)
- cbr tmp,(1<<MOT_DIR_L)
- sbr tmp,(1<<MOT_PWR_L)|(1<<MOT_PWR_R)
- out PORTB,tmp
+ in tmp_motor,PORTB
+ sbr tmp_motor,(1<<MOT_DIR_R)
+ cbr tmp_motor,(1<<MOT_DIR_L)
+ sbr tmp_motor,(1<<MOT_PWR_L)|(1<<MOT_PWR_R)
+ out PORTB,tmp_motor
ret
; uart functions
+; default uart settings
+; infdef UART_BR_H
+.equ UART_BR_H = 0
+; infdef UART_BR_L
+.equ UART_BR_L = 25
+
UART_INIT:
; baudrate
- ldi tmp,
- out UBRRH,tmp
- ldi tmp,
- out UBRRL,tmp
+ ldi uart_rxtx,UART_BR_H
+ sts UBRR0H,uart_rxtx
+ ldi uart_rxtx,UART_BR_L
+ out UBRR0L,uart_rxtx
; enable
- ldi tmp,(1<<RXEN)|(1<<TXEN)
- out UCSRB,tmp
+ ldi uart_rxtx,(1<<RXEN)|(1<<TXEN)
+ out UCSR0B,uart_rxtx
+
+ ; frame format -> 8n1
+ ldi uart_rxtx,(1<<UCSZ00)|(1<<UCSZ01)
+ sts UCSR0C,uart_rxtx
+
+ ret
+
+UART_INT_RX_INIT:
+
+ in uart_rxtx,UCSR0B
+ sbr uart_rxtx,(1<<RXCIE0)
+ out UCSR0B,uart_rxtx
+
+ ret
+
+UART_INT_TX_INIT:
- ; frame format
+ in uart_rxtx,UCSR0B
+ sbr uart_rxtx,(1<<TXCIE0)
+ out UCSR0B,uart_rxtx
ret
UART_RX:
; get/store received byte
- sbis UCSRA,RXC
+ sbis UCSR0A,RXC0
rjmp UART_RX
- in tmp,UDR0
+ in uart_rxtx,UDR0
ret
UART_TX:
- ; transmit content of tmp
- sbis UCSRA,UDRE
+ ; transmit content of uart_rxtx
+ sbis UCSR0A,TXC0
rjmp UART_TX
- out UDR0,tmp
+ out UDR0,uart_rxtx
ret