-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab8_Tx_code.asm
executable file
·184 lines (157 loc) · 4.04 KB
/
Lab8_Tx_code.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
;***********************************************************
;*
;* Jared_Tence_and_Tyler_Farnham_Lab8_Tx_sourcecode.asm
;*
;* Lab8 code
;*
;* This is the transmitter file for Lab 8 of ECE 375
;*
;***********************************************************
;*
;* Author: Jared Tence and Tyler Farnham
;* Date: 3/11/2018
;*
;***********************************************************
.def mpr = r16 ; Multi-Purpose Register
.def mpr2 = r17
.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
; Use these action codes between the remote and robot
; MSB = 1 thus:
; control signals are shifted right by one and ORed with 0b10000000 = $80
.equ MovFwd = ($80|1<<(EngDirR-1)|1<<(EngDirL-1)) ;0b10110000 Move Forward Action Code
.equ MovBck = ($80|$00) ;0b10000000 Move Backward Action Code
.equ TurnR = ($80|1<<(EngDirL-1)) ;0b10100000 Turn Right Action Code
.equ TurnL = ($80|1<<(EngDirR-1)) ;0b10010000 Turn Left Action Code
.equ Halt = ($80|1<<(EngEnR-1)|1<<(EngEnL-1)) ;0b11001000 Halt Action Code
.equ Frz = 0b11111000 ;0b11111000
.equ ID = 0b11100111
;***********************************************************
;* Start of Code Segment
;***********************************************************
.cseg ; Beginning of code segment
;***********************************************************
;* Interrupt Vectors
;***********************************************************
.org $0000 ; Beginning of IVs
rjmp INIT ; Reset interrupt
;***********************************************************
;* Program Initialization
;***********************************************************
INIT: ; The initialization routine
; Initialize Stack Pointer
ldi mpr, high(RAMEND)
out SPH, mpr
ldi mpr, low(RAMEND)
out SPL, mpr
; Initialize Port B for output
ldi mpr, $ff
out DDRB, mpr
; Initialize Port D for input
ldi mpr, 0b00001000
out DDRD, mpr
ldi mpr, $ff
out PORTD, mpr
; Set baudrate at 2400
ldi mpr, high(416) ; Load high byte of 0x0340
sts UBRR1H, mpr ; UBRR0H in extended I/O space
ldi mpr, low(416) ; Load low byte of 0x0340
sts UBRR1L, mpr ;
; Set frame format: 8 data, 2 stop bits, asynchronous
ldi mpr, (0<<UMSEL0 | 1<<USBS0 | 1<<UCSZ01 | 1<<UCSZ00)
sts UCSR1C, mpr ; UCSR0C in extended I/O space
; Enable both transmitter and receiver, and receive interrupt
ldi mpr, (1<<TXEN0)
sts UCSR1B, mpr ;
; Turn on interrupts
; NOTE: This must be the last thing to do in the INIT function
sei
;***********************************************************
;* Main Program
;***********************************************************
MAIN: ; The Main program
in mpr, PIND
sbrs mpr, 0
rcall MOVE_FORWARD
sbrs mpr, 1
rcall MOVE_BACKWARD
sbrs mpr, 4
rcall TURN_RIGHT
sbrs mpr, 5
rcall TURN_LEFT
sbrs mpr, 6
rcall RHALT
sbrs mpr, 7
rcall FREEZE
rjmp MAIN
MOVE_FORWARD:
push mpr2
push mpr
ldi mpr2, MovFwd
rcall TRANSMIT
pop mpr
pop mpr2
ret
MOVE_BACKWARD:
push mpr2
push mpr
ldi mpr2, MovBck
rcall TRANSMIT
pop mpr
pop mpr2
ret
TURN_RIGHT:
push mpr2
push mpr
ldi mpr2, TurnR
rcall TRANSMIT
pop mpr
pop mpr2
ret
TURN_LEFT:
push mpr2
push mpr
ldi mpr2, TurnL
rcall TRANSMIT
pop mpr
pop mpr2
ret
RHALT:
push mpr2
push mpr
ldi mpr2, Halt
rcall TRANSMIT
pop mpr
pop mpr2
ret
FREEZE:
push mpr2
push mpr
ldi mpr2, FRZ
rcall TRANSMIT
pop mpr
pop mpr2
ret
TRANSMIT:
WAIT1:
lds mpr, UCSR1A
sbrs mpr, UDRE1
rjmp WAIT1
ldi mpr, ID
sts UDR1, mpr
WAIT2:
lds mpr, UCSR1A
sbrs mpr, UDRE1
rjmp WAIT2
sts UDR1, mpr2
rcall CLEAR_TRANSMITION
ret
CLEAR_TRANSMITION:
lds mpr, UCSR1A
sbrs mpr, TXC1
rjmp CLEAR_TRANSMITION
ldi mpr, (1<<TXC1)
sts UCSR1A, mpr
ret