Permalink
Browse files

Working code. Sending Freeze from slave still needs to be done.

  • Loading branch information...
uberj committed Feb 25, 2012
1 parent 9a4a1ca commit c7dd3ade8fed9599808df27f57762a186ef8077f
Showing with 49 additions and 14 deletions.
  1. +11 −10 Labs/Lab6/ece375-L6_MASTER.asm
  2. +38 −4 Labs/Lab6/ece375-L6_SLAVE.asm
@@ -23,7 +23,7 @@
.def waitcnt = r17 ; Wait Loop Counter
.def ilcnt = r18 ; Inner Loop Counter
.def olcnt = r19 ; Outer Loop Counter
-.def tmp = r30
+.def tmp = r20
.def rec = r22 ; Multi-Purpose Register
@@ -152,7 +152,7 @@ MAIN:
in mpr, PIND ; Get whisker input from Port D
cpi mpr, FREEZE
- breq FREEZE
+ breq SENDFREEZE
in mpr, PIND ; Get whisker input from Port D
cpi mpr, B3
@@ -165,7 +165,8 @@ MAIN:
in mpr, PIND ; Get whisker input from Port D
cpi mpr, B5
- breq BUTTON5
+ ;breq BUTTON5
+ breq SENDFREEZE
in mpr, PIND ; Get whisker input from Port D
cpi mpr, B6
@@ -195,7 +196,7 @@ BUTTON1:
out PORTB, mpr
call USART_Transmit
jmp MAIN
-FREEZE:
+SENDFREEZE:
; Load bot id
ldi mpr, BotID
; Send bot id
@@ -248,16 +249,16 @@ BUTTON6:
; Load bot id
- ldi mpr, BotID
+ ;ldi mpr, BotID
; Send bot id
- call USART_Transmit
+ ;call USART_Transmit
; Load tmp + 1
- adiw tmp, $1
- mov mpr, tmp
+ ;adiw tmp, $1
+ ;mov mpr, tmp
; Send bot id
- call USART_Transmit
- out PORTB, tmp
+ ;call USART_Transmit
+ ;out PORTB, tmp
ldi waitcnt, WTime ; Wait for 1 second
; -------------------------------
@@ -19,9 +19,10 @@
;* Internal Register Definitions and Constants
;***********************************************************
.def mpr = r16 ; Multi-Purpose Register
+.def numFrozen = r17 ; Multi-Purpose Register
.def waitcnt = r21 ; Wait Loop Counter
.def rec = r22 ; What we received Register
-.def tmp = r23 ; What we received Register
+.def tmp = r20 ; What we received Register
.def cmd = r24 ; What we received Register
.def state = r23 ; State register.
.def ilcnt = r18 ; Inner Loop Counter
@@ -136,6 +137,8 @@ USART_INIT:
;-----------------------------------------------------------
ldi mpr, $01
ldi state, $00
+ clr numFrozen
+ clr cmd
MAIN:
out PORTB, cmd
rjmp MAIN
@@ -162,14 +165,45 @@ USART_Receive:
; Get and return receive data from receive buffer
lds rec, UDR1
; Data is now in rec
-
+ ; if rec == FROZEN:
+ ; wait n
+ ; numFrozen++
+ ; if numFrozen == 3:
+ ; STUCK rjmp STUCK
+ ; ret
+ ; if state == 0:
+ ; if rec == BotID:
+ ; state = 1
+ ; ret
+ ; if state == 1:
+ ; cmd = rec
+ ; mov cmd, rec // Do the command
+ ; ============= The Actual Code =============
+ ; if rec == FROZEN:
+ cpi rec, FROZEN
+ breq DO_FROZEN
+ ; if state == 0:
cpi state, $00
- breq GO_STATE1
+ breq GO_STATE0
+ ; if state == 1:
cpi state, $01
breq COMMAND
ret
-GO_STATE1:
+DO_FROZEN:
+ ; wait n
+ ldi waitcnt, WTime ; Wait for 1 second
+ call Wait
+ inc numFrozen
+ cpi numFrozen, $03
+ breq LOOP_FOREVER
+ ret
+LOOP_FOREVER:
+ ldi mpr, FROZEN
+ out PORTB, mpr
+ rjmp LOOP_FOREVER
+
+GO_STATE0:
cpi rec, BotID
breq MY_ID
ret ; It wasn't our ID. Ignore it.

0 comments on commit c7dd3ad

Please sign in to comment.