Permalink
Browse files

No more of this class.

  • Loading branch information...
1 parent b67fbca commit 674946809a9c1b66b5eb7f32147cc64efa87eca9 @uberj committed Mar 17, 2012
Showing with 719 additions and 43 deletions.
  1. +5 −20 Labs/Lab5/Makefile
  2. +14 −0 Labs/Lab5/ece375-L5.hex
  3. +4 −0 Labs/Lab5/ece375-L5_skeleton.hex
  4. +268 −0 Labs/Lab5/test.asm
  5. +14 −0 Labs/Lab5/test.hex
  6. +6 −0 Labs/Lab6/Makefile
  7. +199 −23 Labs/Lab6/ece375-lab4.tex
  8. +209 −0 Labs/Lab6/master.bak
View
25 Labs/Lab5/Makefile
@@ -5,7 +5,7 @@ lab4-prelab:
rm $(TEXFILE).aux
evince $(TEXFILE).pdf
-FILE="ece375-L1_v2"
+FILE="ece375-L5"
build:
../../avra-1.3.0/src/avra $(FILE).asm
rm $(FILE).obj
@@ -15,30 +15,15 @@ build:
install:
/usr/local/bin/avrdude -c osuisp2 -P /dev/usb/hiddev0 -p m128 -e -U flash:w:$(FILE).hex -v
-FILE1="ece375-LCD_Test"
-build-test:
+FILE1="test"
+build1:
../../avra-1.3.0/src/avra $(FILE1).asm
rm $(FILE1).obj
rm $(FILE1).cof
rm $(FILE1).eep.hex
-install-test:
+install1:
/usr/local/bin/avrdude -c osuisp2 -P /dev/usb/hiddev0 -p m128 -e -U flash:w:$(FILE1).hex -v
clean:
- rm $(FILE1).hex
- rm $(FILE1).hex
-
-FILE2="ece375-L3_skeleton"
-lab3-build:
- ../../avra-1.3.0/src/avra $(FILE2).asm
- rm $(FILE2).obj
- rm $(FILE2).cof
- rm $(FILE2).eep.hex
-
-lab3-install:
- /usr/local/bin/avrdude -c osuisp2 -P /dev/usb/hiddev0 -p m128 -e -U flash:w:$(FILE2).hex -v
-
-clean:
- rm $(FILE2).hex
- rm $(FILE2).hex
+ rm $(FILE).hex
View
14 Labs/Lab5/ece375-L5.hex
@@ -0,0 +1,14 @@
+:020000020000FC
+:0200000045C0F9
+:0800080058D0189569D0189535
+:10008C000FEF0DBF00E10EBF00E008BB0FEF07BB89
+:10009C000FEF02BB00E001BB00E608BB0AE00ABFA1
+:1000AC0000E000936A0006E009BF7894FFCF0F933D
+:1000BC001F930FB70F9300E008BB14E61ED000E2AD
+:1000CC0008BB14E61AD000E608BB0F910FBF1F91B6
+:1000DC000F9108950F931F930FB70F9300E008BB78
+:1000EC0014E60BD000E408BB14E607D000E608BB0E
+:1000FC000F910FBF1F910F9108951F932F933F9353
+:10010C0030EE2DEE2A95F1F73A95D9F71A95C1F7FD
+:08011C003F912F911F910895FE
+:00000001FF
View
4 Labs/Lab5/ece375-L5_skeleton.hex
@@ -0,0 +1,4 @@
+:020000020000FC
+:0200000045C0F9
+:04008C00FFCF089505
+:00000001FF
View
268 Labs/Lab5/test.asm
@@ -0,0 +1,268 @@
+;***********************************************************
+;*
+;* Enter Name of file here
+;*
+;* Enter the description of the program here
+;*
+;* This is the skeleton file Lab 5 of ECE 375
+;*
+;***********************************************************
+;*
+;* Author: Enter your name
+;* Date: Enter Date
+;*
+;***********************************************************
+
+.include "m128def.inc" ; Include definition file
+
+;***********************************************************
+;* Internal Register Definitions and Constants
+;***********************************************************
+.def mpr = r16 ; Multipurpose register
+; Other register renames
+
+; Constants for interactions such as
+;.equ WskrR = 4 ; Right Whisker Input Bit
+;.equ EngEnR = 4 ; Right Engine Enable Bit
+
+; Using the constants from above, create the movement
+; commands, Forwards, Backwards, Stop, Turn Left, and Turn Right
+
+.def waitcnt = r17 ; Wait Loop Counter
+.def ilcnt = r18 ; Inner Loop Counter
+.def olcnt = r19 ; Outer Loop Counter
+
+.equ WTime = 100 ; Time to wait in wait loop
+
+.equ WskrR = 0 ; Right Whisker Input Bit
+.equ WskrL = 1 ; Left Whisker Input Bit
+.equ EngEnR = 4 ; Right Engine Enable Bit
+.equ EngEnL = 7 ; Left Engine Enable Bit
+.equ EngDirR = 5 ; Right Engine Direction Bit
+.equ EngDirL = 6 ; Left Engine Direction Bit
+
+;/////////////////////////////////////////////////////////////
+;These macros are the values to make the TekBot Move.
+;/////////////////////////////////////////////////////////////
+ ; Move Forwards Command
+.equ MovFwd = (1<<EngDirR|1<<EngDirL)
+.equ MovBck = $00 ; Move Backwards Command
+.equ TurnR = (1<<EngDirL) ; Turn Right Command
+.equ TurnL = (1<<EngDirR) ; Turn Left Command
+ ; Halt Command
+.equ Halt = (1<<EngEnR|1<<EngEnL)
+
+;/////////////////////////////////////////////////////////////
+;Interrupt register values
+;/////////////////////////////////////////////////////////////
+;EICRA All "reserved" except ISC1 and ISC2
+.equ INT_REG_A = (0<<ISC10|1<<ISC11|0<<ISC20|1<<ISC21) ;0b01101001
+.equ INT_REG_B = $00
+
+.equ INT_MASK = (1<<INT1|1<<INT2)
+
+;***********************************************************
+;* Start of Code Segment
+;***********************************************************
+.cseg ; Beginning of code segment
+
+;-----------------------------------------------------------
+; Interrupt Vectors
+;-----------------------------------------------------------
+.org $0000 ; Beginning of IVs
+ rjmp INIT ; Reset interrupt
+
+; Set up the interrupt vectors for the interrupts, .i.e
+.org $0004
+ rcall HitRight
+ reti
+
+.org $0006
+ rcall HitLeft
+ reti
+
+;.org $002E ; Analog Comparator IV
+; rcall HandleAC ; Function to handle Interupt request
+; reti ; Return from interrupt
+
+.org $0046 ; End of Interrupt Vectors
+
+;-----------------------------------------------------------
+; Program Initialization
+;-----------------------------------------------------------
+INIT: ; The initialization routine
+ ; Initialize Stack Pointer
+ ldi mpr, low(RAMEND)
+ out SPL, mpr ; Load SPL with low byte of RAMEND
+ ldi mpr, high(RAMEND)
+ out SPH, mpr ; Load SPH with high byte of RAMEND
+
+ ; Initialize Port B for output
+ ldi mpr, $00 ; Initialize Port B for outputs
+ out PORTB, mpr ; Port B outputs low
+ ldi mpr, $ff ; Set Port B Directional Register
+ out DDRB, mpr ; for output
+
+ ; Initialize Port D for inputs
+ ldi mpr, $FF ; Initialize Port D for inputs
+ out PORTD, mpr ; with Tri-State
+ ldi mpr, $00 ; Set Port D Directional Register
+ out DDRD, mpr ; for inputs
+
+ ; Initialize external interrupts
+ ; Set the Interrupt Sense Control to Rising Edge detection
+ ; NOTE: must initialize both EICRA and EICRB
+ ldi mpr, INT_REG_A
+ sts EICRA, mpr
+
+ ldi mpr, INT_REG_B
+ out EICRB, mpr
+
+ ; Set the External Interrupt Mask
+ ldi mpr, INT_MASK
+ out EIMSK, mpr
+
+ ; Turn on interrupts
+ sei
+ ; NOTE: This must be the last thing to do in the INIT function
+
+;-----------------------------------------------------------
+; Main Program
+;-----------------------------------------------------------
+MAIN: ; The Main program
+
+ ; Send command to Move Robot Forward
+ ; Initialize TekBot Foward Movement
+ ldi mpr, MovFwd ; Load Move Foward Command
+ out PORTB, mpr ; Send command to motors
+
+ rjmp MAIN ; Create an infinite while loop to signify the
+ ; end of the program.
+
+;***********************************************************
+;* Functions and Subroutines
+;***********************************************************
+
+;-----------------------------------------------------------
+; You will probably need several functions, one to handle the
+; left whisker interrupt, one to handle the right whisker
+; interrupt, and maybe a wait function
+;------------------------------------------------------------
+
+;-----------------------------------------------------------
+; Func: Template function header
+; Desc: Cut and paste this and fill in the info at the
+; beginning of your functions
+;-----------------------------------------------------------
+FUNC: ; Begin a function with a label
+ ; Save variable by pushing them to the stack
+
+ ; Execute the function here
+
+ ; Restore variable by popping them from the stack in reverse order
+ ret ; End a function with RET
+
+
+;----------------------------------------------------------------
+; Sub: HitRight
+; Desc: Handles functionality of the TekBot when the right whisker
+; is triggered.
+;----------------------------------------------------------------
+HitRight:
+ push mpr ; Save mpr register
+ push waitcnt ; Save wait register
+ in mpr, SREG ; Save program state
+ push mpr ;
+
+ ; Move Backwards for a second
+ ldi mpr, MovBck ; Load Move Backwards command
+ out PORTB, mpr ; Send command to port
+ ldi waitcnt, WTime ; Wait for 1 second
+ rcall Wait ; Call wait function
+
+ ; Turn left for a second
+ ldi mpr, TurnL ; Load Turn Left Command
+ out PORTB, mpr ; Send command to port
+ ldi waitcnt, WTime*2 ; Wait for 1 second
+ rcall Wait ; Call wait function
+
+ ; Move Forward again
+ ldi mpr, MovFwd ; Load Move Forwards command
+ out PORTB, mpr ; Send command to port
+
+ pop mpr ; Restore program state
+ out SREG, mpr ;
+ pop waitcnt ; Restore wait register
+ pop mpr ; Restore mpr
+ ret ; Return from subroutine
+
+;----------------------------------------------------------------
+; Sub: HitLeft
+; Desc: Handles functionality of the TekBot when the left whisker
+; is triggered.
+;----------------------------------------------------------------
+HitLeft:
+ push mpr ; Save mpr register
+ push waitcnt ; Save wait register
+ in mpr, SREG ; Save program state
+ push mpr ;
+
+ ; Move Backwards for a second
+ ldi mpr, MovBck ; Load Move Backwards command
+ out PORTB, mpr ; Send command to port
+ ldi waitcnt, WTime*2 ; Wait for 1 second
+ rcall Wait ; Call wait function
+
+ ; Turn right for a second
+ ldi mpr, TurnR ; Load Turn Left Command
+ out PORTB, mpr ; Send command to port
+ ldi waitcnt, WTime ; Wait for 1 second
+ rcall Wait ; Call wait function
+
+ ; Move Forward again
+ ldi mpr, MovFwd ; Load Move Forwards command
+ out PORTB, mpr ; Send command to port
+
+ pop mpr ; Restore program state
+ out SREG, mpr ;
+ pop waitcnt ; Restore wait register
+ pop mpr ; Restore mpr
+ ret ; Return from subroutine
+
+;----------------------------------------------------------------
+; Sub: Wait
+; Desc: A wait loop that is 16 + 159975*waitcnt cycles or roughly
+; waitcnt*10ms. Just initialize wait for the specific amount
+; of time in 10ms intervals. Here is the general eqaution
+; for the number of clock cycles in the wait loop:
+; ((3 * ilcnt + 3) * olcnt + 3) * waitcnt + 13 + call
+;----------------------------------------------------------------
+Wait:
+ push waitcnt ; Save wait register
+ push ilcnt ; Save ilcnt register
+ push olcnt ; Save olcnt register
+
+Loop: ldi olcnt, 224 ; load olcnt register
+OLoop: ldi ilcnt, 237 ; load ilcnt register
+ILoop: dec ilcnt ; decrement ilcnt
+ brne ILoop ; Continue Inner Loop
+ dec olcnt ; decrement olcnt
+ brne OLoop ; Continue Outer Loop
+ dec waitcnt ; Decrement wait
+ brne Loop ; Continue Wait loop
+
+ pop olcnt ; Restore olcnt register
+ pop ilcnt ; Restore ilcnt register
+ pop waitcnt ; Restore wait register
+ ret ; Return from subroutine
+
+;***********************************************************
+;* Stored Program Data
+;***********************************************************
+
+; Enter any stored data you might need here
+
+;***********************************************************
+;* Additional Program Includes
+;***********************************************************
+; There are no additional file includes for this program
View
14 Labs/Lab5/test.hex
@@ -0,0 +1,14 @@
+:020000020000FC
+:0200000045C0F9
+:0800080059D018956AD0189533
+:10008C000FEF0DBF00E10EBF00E008BB0FEF07BB89
+:10009C000FEF02BB00E001BB08E200936A0000E036
+:1000AC000ABF06E009BF789400E608BBFDCF0895AF
+:1000BC000F931F930FB70F9300E008BB14E61ED0ED
+:1000CC0000E208BB18EC1AD000E608BB0F910FBF7A
+:1000DC001F910F9108950F931F930FB70F9300E08B
+:1000EC0008BB18EC0BD000E408BB14E607D000E604
+:1000FC0008BB0F910FBF1F910F9108951F932F9362
+:10010C003F9330EE2DEE2A95F1F73A95D9F71A95E3
+:0A011C00C1F73F912F911F91089544
+:00000001FF
View
6 Labs/Lab6/Makefile
@@ -26,5 +26,11 @@ sinstall: sbuild
all: minstall sinstall
+report:
+ pdflatex ece375-lab4.tex
+ evince ece375-lab4.pdf
+ rm *.aux
+ rm *.log
+
clean:
rm *.hex
View
222 Labs/Lab6/ece375-lab4.tex
@@ -56,7 +56,6 @@ \section{Conclusion}
\section{Source Code}
MASTER Code
\begin{verbatim}
-
;***********************************************************
;*
;* Enter Name of file here
@@ -90,11 +89,12 @@ \section{Source Code}
.equ B0 = 0b11111110 ; Right Whisker Input Bit
.equ B1 = 0b11111101
-.equ B2 = 0b01010101
+.equ B2 = 0b11111011
.equ B3 = 0b11110111
.equ B4 = 0b11101111
.equ B5 = 0b11011111
.equ B6 = 0b10111111
+.equ B7 = 0b01111111
.equ FREEZE = 0b11111000
.equ WskrR = 0 ; Right Whisker Input Bit
@@ -105,7 +105,7 @@ \section{Source Code}
.equ EngDirL = 6 ; Left Engine Direction Bit
;.equ BotID = ;(Enter you group ID here (8bits)); Unique XD ID (MSB = 0)
-.equ BotID = 0b11111111 ;(Enter you group ID here (8bits)); Unique XD ID (MSB = 0)
+.equ BotID = 0b01111111 ;(Enter you group ID here (8bits))
;/////////////////////////////////////////////////////////////
;These macros are the values to make the TekBot Move.
@@ -128,6 +128,10 @@ \section{Source Code}
.org $0000 ; Beginning of IVs
rjmp INIT ; Reset interrupt
+;Should have Interrupt vectors for:
+;.org $003C
+; rcall USART_Receive
+; reti
;- Left wisker
;- Right wisker
;- USART receive
@@ -159,7 +163,8 @@ \section{Source Code}
USART_INIT:
;Set double data rate
ldi r16, (1<<U2X1)
- ; UCSR1A control register -- Bit 1 – U2Xn: Double the USART Transmission Speed
+ ; UCSR1A control register --
+ ;Bit 1 – U2Xn: Double the USART Transmission Speed
sts UCSR1A, r16
;Set baudrate at 2400bps
@@ -176,7 +181,7 @@ \section{Source Code}
;Enable both receiver and transmitter -- needed for Lab 2
; RXEN (Receiver enable) TXEN (Transmit enable)
- ldi r16, (1<<RXCIE1|1<<RXEN1|1<<TXEN1)
+ ldi r16, (1<<RXCIE1|1<<RXEN1|1<<TXEN1)
sts UCSR1B, r16
;External Interrupts
@@ -195,29 +200,61 @@ \section{Source Code}
;-----------------------------------------------------------
; Main Program
-;----------------------------------------------------------
+;-----------------------------------------------------------
+ ldi tmp, $00
MAIN:
+ ; Clear lds
+ clr mpr
+ out PORTB, mpr
+
ldi mpr, $00
+
in mpr, PIND ; Get whisker input from Port D
cpi mpr, B0
- breq BUTTON0
+ breq BUTTON0 ; Left
in mpr, PIND ; Get whisker input from Port D
cpi mpr, B1
- breq BUTTON1
+ breq BUTTON1 ; Right
in mpr, PIND ; Get whisker input from Port D
cpi mpr, B5
breq SENDFREEZE ; Button 5
+
+
+ ;in mpr, PIND ; Get whisker input from Port D
+ ;cpi mpr, B2
+ ;breq BUTTON2 ; Forward
+
+ ;in mpr, PIND ; Get whisker input from Port D
+ ;cpi mpr, B3
+ ;breq BUTTON3 ; Backward
+
+ in mpr, PIND ; Get whisker input from Port D
+ cpi mpr, B4
+ breq BUTTON4 ; Halt
+
+ in mpr, PIND ; Get whisker input from Port D
+ cpi mpr, B6
+ breq BUTTON6 ; Halt
+
+ in mpr, PIND ; Get whisker input from Port D
+ cpi mpr, B7
+ breq BUTTON7 ; Halt
+
; Clear lds
clr mpr
out PORTB, mpr
rjmp MAIN
-BUTTON0:
+ ;in mpr, PIND ; Get whisker input from Port D
+ ;cpi mpr, B6
+
+
+BUTTON0: ;Left
; Load bot id
ldi mpr, BotID
; Send bot id
@@ -227,7 +264,7 @@ \section{Source Code}
out PORTB, mpr
call USART_Transmit
jmp MAIN
-BUTTON1:
+BUTTON1: ;Right
; Load bot id
ldi mpr, BotID
; Send bot id
@@ -237,7 +274,7 @@ \section{Source Code}
out PORTB, mpr
call USART_Transmit
jmp MAIN
-SENDFREEZE:
+SENDFREEZE: ;Freeze
; Load bot id
ldi mpr, BotID
; Send bot id
@@ -247,6 +284,49 @@ \section{Source Code}
out PORTB, mpr
call USART_Transmit
jmp MAIN
+BUTTON2:
+ ; Load bot id
+ ldi mpr, BotID
+ ; Send bot id
+ call USART_Transmit
+
+ ldi mpr, 0b00000101
+ out PORTB, mpr
+ call USART_Transmit
+ jmp MAIN
+BUTTON4: ;Forward
+ ; Load bot id
+ ldi mpr, BotID
+ ; Send bot id
+ call USART_Transmit
+
+ ldi mpr, MovFwd
+ out PORTB, mpr
+ call USART_Transmit
+ jmp MAIN
+
+BUTTON6: ;Backward
+ ; Load bot id
+ ldi mpr, BotID
+ ; Send bot id
+ call USART_Transmit
+
+ ldi mpr, MovBck
+ out PORTB, mpr
+ call USART_Transmit
+ jmp MAIN
+
+BUTTON7: ;Halt
+ ; Load bot id
+ ldi mpr, BotID
+ ; Send bot id
+ call USART_Transmit
+
+ ldi mpr, Halt
+ out PORTB, mpr
+ call USART_Transmit
+ jmp MAIN
+
rjmp MAIN
@@ -282,6 +362,12 @@ \section{Source Code}
;***********************************************************
+;* Stored Program Data
+;***********************************************************
+
+
+
+;***********************************************************
;* Additional Program Includes
;***********************************************************
@@ -339,6 +425,7 @@ \section{Source Code}
.def waitcnt = r21 ; Wait Loop Counter
.def rec = r22 ; What we received Register
.def tmp = r20 ; What we received Register
+.def tmp2 = r25 ; What we received Register
.def cmd = r24 ; What we received Register
.def state = r23 ; State register.
.def ilcnt = r18 ; Inner Loop Counter
@@ -380,15 +467,26 @@ \section{Source Code}
.org $0000 ; Beginning of IVs
rjmp INIT ; Reset interrupt
+;- Right wisker
+; Reset interrupt
+.org $0004
+rcall HitRight ; Call hit right function
+reti
+
+;- Left wisker (For some reason putting this in $0006 broke stuff)
+; Return from interrupt
+.org $0002
+rcall HitLeft ; Call hit left function
+reti
+
;Should have Interrupt vectors for:
.org $003C
- rcall USART_Receive
- reti
-;- Left wisker
-;- Right wisker
+rcall USART_Receive
+reti
;- USART receive
+.org $0046 ; End of Interrupt Vectors
;-----------------------------------------------------------
; Program Initialization
;-----------------------------------------------------------
@@ -431,7 +529,8 @@ \section{Source Code}
sts UCSR1C, r16
;Enable both receiver and transmitter -- needed for Lab 2
- ldi r16, (1<<RXCIE1|1<<RXEN1|1<<TXEN1) ; RXEN (Receiver enable) TXEN (Transmit enable)
+ ; RXEN (Receiver enable) TXEN (Transmit enable)
+ ldi r16, (1<<RXCIE1|1<<RXEN1|1<<TXEN1)
sts UCSR1B, r16
;External Interrupts
@@ -440,6 +539,14 @@ \section{Source Code}
;Enable receiver and enable receive interrupts
;Set the External Interrupt Mask
+ ; Set INT4 & 5 to trigger on falling edge
+ ldi mpr, $00
+ sts EICRA, mpr
+
+ ; Use sts, EICRA in extended I/O space
+ ; Set the External Interrupt Mask
+ ldi mpr, (1 <<INT2)|(1 <<INT1)|(1 <<INT0)
+ out EIMSK, mpr
; Set the Interrupt Sense Control to falling edge
ldi mpr, (1 <<ISC41)|(0 <<ISC40)|(1 <<ISC51)|(0 <<ISC50)
@@ -456,8 +563,9 @@ \section{Source Code}
clr numFrozen
clr cmd
MAIN:
+ clr cmd
out PORTB, cmd
- ldi waitcnt, 20 ; Wait for 1 second
+ ldi waitcnt, 10 ; Wait for 1 second
call Wait
clr cmd
out PORTB, cmd
@@ -523,7 +631,7 @@ \section{Source Code}
clr mpr
out PORTB, mpr
inc numFrozen
- cpi numFrozen, $03
+ cpi numFrozen, 5
breq LOOP_FOREVER
ret
LOOP_FOREVER:
@@ -552,7 +660,6 @@ \section{Source Code}
ret
USART_Transmit:
- cli ; Disable all interrupts
lds tmp, UCSR1A
sbrs tmp, UDRE1
; Load status of USART1
@@ -561,19 +668,88 @@ \section{Source Code}
; Send data
sts UDR1, mpr
; Move data to transmit data buffer
- ldi waitcnt, 20 ; Wait for 1 second
- call Wait
- sei
+ ;ldi waitcnt, 20 ; Wait for 1 second
+ ;call Wait
ret
+;***********************************************************
+;* Stored Program Data
+;***********************************************************
+
+
;***********************************************************
;* Additional Program Includes
;***********************************************************
+;----------------------------------------------------------------
+; Sub: HitRight
+; Desc: Handles functionality of the TekBot when the right whisker
+; is triggered.
+;----------------------------------------------------------------
+HitRight:
+ push mpr ; Save mpr register
+ push waitcnt ; Save wait register
+ in mpr, SREG ; Save program state
+ push mpr ;
+
+ ; Move Backwards for a second
+ ldi mpr, MovBck ; Load Move Backwards command
+ out PORTB, mpr ; Send command to port
+ ldi waitcnt, WTime ; Wait for 1 second
+ rcall Wait ; Call wait function
+
+ ; Turn left for a second
+ ldi mpr, TurnL ; Load Turn Left Command
+ out PORTB, mpr ; Send command to port
+ ldi waitcnt, WTime ; Wait for 1 second
+ rcall Wait ; Call wait function
+
+ ; Move Forward again
+ ldi mpr, MovFwd ; Load Move Forwards command
+ out PORTB, mpr ; Send command to port
+
+ pop mpr ; Restore program state
+ out SREG, mpr ;
+ pop waitcnt ; Restore wait register
+ pop mpr ; Restore mpr
+ ret ; Return from subroutine
+
+;----------------------------------------------------------------
+; Sub: HitLeft
+; Desc: Handles functionality of the TekBot when the left whisker
+; is triggered.
+;----------------------------------------------------------------
+HitLeft:
+ push mpr ; Save mpr register
+ push waitcnt ; Save wait register
+ in mpr, SREG ; Save program state
+ push mpr ;
+
+ ; Move Backwards for a second
+ ldi mpr, MovBck ; Load Move Backwards command
+ out PORTB, mpr ; Send command to port
+ ldi waitcnt, WTime ; Wait for 1 second
+ rcall Wait ; Call wait function
+
+ ; Turn right for a second
+ ldi mpr, TurnR ; Load Turn Left Command
+ out PORTB, mpr ; Send command to port
+ ldi waitcnt, WTime ; Wait for 1 second
+ rcall Wait ; Call wait function
+
+ ; Move Forward again
+ ldi mpr, MovFwd ; Load Move Forwards command
+ out PORTB, mpr ; Send command to port
+
+ pop mpr ; Restore program state
+ ;out SREG, mpr ;
+ pop waitcnt ; Restore wait register
+ pop mpr ; Restore mpr
+ ret ; Return from subroutine
;----------------------------------------------------------------
; Sub: Wait
@@ -595,7 +771,7 @@ \section{Source Code}
dec olcnt ; decrement olcnt
brne OLoop ; Continue Outer Loop
dec waitcnt ; Decrement wait
- brne Loop ; Continue Wait loop
+ brne Loop ; Continue Wait loop
pop olcnt ; Restore olcnt register
pop ilcnt ; Restore ilcnt register
View
209 Labs/Lab6/master.bak
@@ -0,0 +1,209 @@
+;***********************************************************
+;*
+;* Enter Name of file here
+;*
+;* Enter the description of the program here
+;*
+;* This is the RECEIVE skeleton file for Lab 6 of ECE 375
+;*
+;***********************************************************
+;*
+;* Author: Enter your name
+;* Date: Enter Date
+;*
+;***********************************************************
+
+.include "m128def.inc" ; Include definition file
+
+;***********************************************************
+;* Internal Register Definitions and Constants
+;***********************************************************
+.def mpr = r16 ; Multi-Purpose Register
+.def rec = r22 ; Multi-Purpose Register
+.def waitcnt = r21 ; Wait Loop Counter
+.def ilcnt = r18 ; Inner Loop Counter
+.def olcnt = r19 ; Outer Loop Counter
+
+.equ WTime = 50 ; Time to wait in wait loop
+
+.equ WskrR = 0 ; Right Whisker Input Bit
+.equ WskrL = 1 ; Left Whisker Input Bit
+.equ EngEnR = 4 ; Right Engine Enable Bit
+.equ EngEnL = 7 ; Left Engine Enable Bit
+.equ EngDirR = 5 ; Right Engine Direction Bit
+.equ EngDirL = 6 ; Left Engine Direction Bit
+
+;.equ BotID = ;(Enter you group ID here (8bits)); Unique XD ID (MSB = 0)
+
+;/////////////////////////////////////////////////////////////
+;These macros are the values to make the TekBot Move.
+;/////////////////////////////////////////////////////////////
+
+.equ MovFwd = (1<<EngDirR|1<<EngDirL) ;0b01100000 Move Forwards Command
+.equ MovBck = $00 ;0b00000000 Move Backwards Command
+.equ TurnR = (1<<EngDirL) ;0b01000000 Turn Right Command
+.equ TurnL = (1<<EngDirR) ;0b00100000 Turn Left Command
+.equ Halt = (1<<EngEnR|1<<EngEnL) ;0b10010000 Halt Command
+
+;***********************************************************
+;* Start of Code Segment
+;***********************************************************
+.cseg ; Beginning of code segment
+
+;-----------------------------------------------------------
+; Interrupt Vectors
+;-----------------------------------------------------------
+.org $0000 ; Beginning of IVs
+ rjmp INIT ; Reset interrupt
+
+;Should have Interrupt vectors for:
+;.org $003C
+; rcall USART_Receive
+; reti
+;- Left wisker
+;- Right wisker
+;- USART receive
+
+
+;-----------------------------------------------------------
+; Program Initialization
+;-----------------------------------------------------------
+INIT:
+ ;Stack Pointer (VERY IMPORTANT!!!!)
+ ldi mpr, low(RAMEND)
+ out SPL, mpr ; Load SPL with low byte of RAMEND
+ ldi mpr, high(RAMEND)
+ out SPH, mpr ; Load SPH with high byte of RAMEND
+ ;I/O Ports
+ ; Initialize Port B for output
+ ldi mpr, $00 ; Initialize Port B for outputs
+ out PORTB, mpr ; Port B outputs low
+ ldi mpr, $ff ; Set Port B Directional Register
+ out DDRB, mpr ; for output
+
+ ; Initialize Port D for inputs
+ ldi mpr, $FF ; Initialize Port D for inputs
+ out PORTD, mpr ; with Tri-State
+ ldi mpr, $00 ; Set Port D Directional Register
+ out DDRD, mpr ; for inputs
+
+ ;USART1
+USART_INIT:
+ ;Set double data rate
+ ldi r16, (1<<U2X1)
+ ; UCSR1A control register -- Bit 1 – U2Xn: Double the USART Transmission Speed
+ sts UCSR1A, r16
+
+ ;Set baudrate at 2400bps
+ ; UBRR1H Bod rate control register
+ ldi r16, high(832)
+ sts UBRR1H, r16
+ ldi r16, low(832)
+ sts UBRR1L, r16
+
+
+ ;Set frame format: 8data bits, 2 stop bit
+ ldi r16, (0<<UMSEL1|1<<USBS1|1<<UCSZ11|1<<UCSZ10)
+ sts UCSR1C, r16
+
+ ;Enable both receiver and transmitter -- needed for Lab 2
+ ldi r16, (1<<RXCIE1|1<<RXEN1|1<<TXEN1) ; RXEN (Receiver enable) TXEN (Transmit enable)
+ sts UCSR1B, r16
+
+ ;External Interrupts
+ ; Turn on interrupts
+ sei ; This may be redundant
+
+ ;Enable receiver and enable receive interrupts
+ ;Set the External Interrupt Mask
+
+ ; Set the Interrupt Sense Control to falling edge
+ ldi mpr, (1 <<ISC41)|(0 <<ISC40)|(1 <<ISC51)|(0 <<ISC50)
+ out EICRB, mpr
+
+ ;Other
+
+
+;-----------------------------------------------------------
+; Main Program
+;-----------------------------------------------------------
+ ldi mpr, $00
+MAIN:
+ ldi r20, $01
+ add mpr, r20
+
+ out PORTB, mpr
+ call USART_Transmit
+ ldi waitcnt, WTime ; Wait for 1 second
+ rcall Wait ; Call wait function
+
+ rjmp MAIN
+
+
+;***********************************************************
+;* Functions and Subroutines
+;***********************************************************
+; USART Receive
+USART_Receive:
+ ; Wait for data to be received
+ lds rec, UCSR1A
+ sbrs rec, RXC1
+ rjmp USART_Receive
+
+ ; Get and return receive data from receive buffer
+ lds rec, UDR1
+ out PORTB, rec
+ ret
+
+USART_Transmit:
+ lds r23, UCSR1A
+ sbrs r23, UDRE1
+ ; Load status of USART1
+ ; Loop until transmit data buffer is ready
+ rjmp USART_Transmit
+
+ ; Send data
+ sts UDR1, mpr
+ ; Move data to transmit data buffer
+ ret
+
+
+
+
+
+;***********************************************************
+;* Stored Program Data
+;***********************************************************
+
+
+
+;***********************************************************
+;* Additional Program Includes
+;***********************************************************
+
+;----------------------------------------------------------------
+; Sub: Wait
+; Desc: A wait loop that is 16 + 159975*waitcnt cycles or roughly
+; waitcnt*10ms. Just initialize wait for the specific amount
+; of time in 10ms intervals. Here is the general eqaution
+; for the number of clock cycles in the wait loop:
+; ((3 * ilcnt + 3) * olcnt + 3) * waitcnt + 13 + call
+;----------------------------------------------------------------
+Wait:
+ push waitcnt ; Save wait register
+ push ilcnt ; Save ilcnt register
+ push olcnt ; Save olcnt register
+
+Loop: ldi olcnt, 224 ; load olcnt register
+OLoop: ldi ilcnt, 237 ; load ilcnt register
+ILoop: dec ilcnt ; decrement ilcnt
+ brne ILoop ; Continue Inner Loop
+ dec olcnt ; decrement olcnt
+ brne OLoop ; Continue Outer Loop
+ dec waitcnt ; Decrement wait
+ brne Loop ; Continue Wait loop
+
+ pop olcnt ; Restore olcnt register
+ pop ilcnt ; Restore ilcnt register
+ pop waitcnt ; Restore wait register
+ ret ; Return from subroutine

0 comments on commit 6749468

Please sign in to comment.