-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathecho.asm
More file actions
263 lines (209 loc) · 7.04 KB
/
Copy pathecho.asm
File metadata and controls
263 lines (209 loc) · 7.04 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#include p18f87k22.inc
global Add_Start, Add_Main_loop
acs0 udata_acs ; reserve data space in access ram
storage_low_start res 1
storage_high_start res 1
storage_highest_start res 1
storage_low_og res 1
storage_high_og res 1
storage_highest_og res 1
storage_low_echo res 1
storage_high_echo res 1
storage_highest_echo res 1
output_lower_echo res 1
output_upper_echo res 1
input_lower_echo res 1
input_upper_echo res 1
multiplier res 1
MIC code
Echo_Start
call Setup_echo ;setup code, simply set starting filre register numbers
movlw 0x08
movwf multiplier
Echo_Main_loop
;Assume the audio has already been recorded
;select first 8 seconds
;put the 8 seconds at a specific file register at the end
;read the bytes, multiply them
;write them back to the FRAM
;loop over to the end of the 8 seconds
;move on to the next block, back to top but with a differnt multiplier
call move_og_to_end
move_og_to_end
call Read_Setup
call Read_og
movff output_lower_echo,input_lower_echo
movff output_upper_echo,input_upper_echo
call Write_Setup
call Write_result_end
call Increment_og
call Increment_og
call Increment_echo
call Increment_echo
movlw 0x00 ;check whether the first half register has reached 256KB, if so return
cpfseq storage_low_og
bra Read_and_write
movlw 0xD0
cpfseq storage_high_og
bra Read_and_write
movlw 0x07
cpfseq storage_highest_og
bra Read_and_write
return
Read_and_write
call Read_Setup
call Read_out_og
movff multiplier,W
mulwf output_lower_echo,input_lower_echo
mulwf output_upper_echo,input_upper_echo
call Write_Setup
call Write_result_1
call Increment_og
call Increment_og
call Increment_echo
call Increment_echo
movlw 0x00 ;check whether the first half register has reached 256KB, if so return
cpfseq storage_low_og
bra Read_and_write
movlw 0xD0
cpfseq storage_high_og
bra Read_and_write
movlw 0x07
cpfseq storage_highest_og
bra Read_and_write
return
Echo_Setup;set starting position of file registers to read the FRAM from
movlw 0x00
movwf storage_highest_og
movlw 0xD0
movwf storage_high_og
movlw 0x07
movwf storage_low_og
movlw 0x00
movwf storage_highest_echo
movlw 0x00
movwf storage_high_echo
movlw 0x01
movwf storage_low_echo
Read_Setup;setup to read from the FRAM
movlw 0x00
movwf TRISD
movwf TRISE
movwf TRISF
bsf PORTD, RD0 ;setting bit for chip select of DAC
bcf SSP2STAT, CKE
; MSSP enable; CKP=1; SPI master, clock=Fosc/64 (1MHz)
movlw (1<<SSPEN)|(1<<CKP)|(0x02)
movwf SSP2CON1
; SDO2 output; SCK2 output
bcf TRISD, SDO2
bcf TRISD, SCK2
bcf SSP1STAT, CKE
; MSSP enable; CKP=1; SPI master, clock=Fosc/64 (1MHz)
movlw (1<<SSPEN)|(1<<CKP)|(0x02)
movwf SSP1CON1
; SDO2 output; SCK2 output
bcf TRISC, SDO1
bcf TRISC, SCK1
return
Read_out_og;Read the value from the 1st clip
bcf PORTE, RE1 ;set cs pin low to active so can read from FRAM
;bcf TRISC, RC5
bsf TRISC, RC4
movlw 0x03 ;op code for reading FRAM
call SPI_MasterTransmitStore
movf storage_highest_og, W
call SPI_MasterTransmitStore
movf storage_high_og, W
call SPI_MasterTransmitStore
movf storage_low_og, W
call SPI_MasterTransmitStore
movlw 0xFF
call SPI_MasterTransmitStore
andlw 0x0F
movwf output_upper_echo
movlw 0x00
call SPI_MasterTransmitStore
movwf output_lower_echo
bsf PORTE, RE1 ;set cs pin high to inactive so cant write
bcf TRISC, RC4
return
Write_Setup;setup to write back to the FRAM
bsf PORTE, RE1 ;set cs pin high so cant write
bsf PORTA, RA4 ;set WP pin on, write protect on
bsf PORTC, RC2 ;set hold pin off so doesnt hold
bcf SSP1STAT, CKE
; MSSP enable; CKP=1; SPI master, clock=Fosc/64 (1MHz)
movlw (1<<SSPEN)|(1<<CKP)|(0x02)
movwf SSP1CON1
; SDO2 output; SCK2 output
bcf TRISC, SDI1
bcf TRISC, SCK1
return
Write_result_og;write to the FRAM 1st half, the second half is left untouched
bcf PORTE, RE1 ;set cs pin low to active so can write
bcf PORTE, RE1 ;set cs pin low to active so can write
movlw 0x06
call SPI_MasterTransmitInput
bsf PORTE, RE1
bcf PORTE, RE1
movlw 0x02
call SPI_MasterTransmitInput
movf storage_highest_echo, W
call SPI_MasterTransmitInput
movf storage_high_echo, W
call SPI_MasterTransmitInput
movf storage_low_echo, W
call SPI_MasterTransmitInput
movf input_upper_echo, W
call SPI_MasterTransmitInput
movf input_lower_echo, W
call SPI_MasterTransmitInput
bsf PORTE, RE1 ;set cs pin high to inactive so cant write
return
Write_result_1;write to the FRAM 1st half, the second half is left untouched
bcf PORTE, RE1 ;set cs pin low to active so can write
bcf PORTE, RE1 ;set cs pin low to active so can write
movlw 0x06
call SPI_MasterTransmitInput
bsf PORTE, RE1
bcf PORTE, RE1
movlw 0x02
call SPI_MasterTransmitInput
movf storage_highest_1, W
call SPI_MasterTransmitInput
movf storage_high_1, W
call SPI_MasterTransmitInput
movf storage_low_1, W
call SPI_MasterTransmitInput
movf input_upper_1, W
call SPI_MasterTransmitInput
movf input_lower_1, W
call SPI_MasterTransmitInput
bsf PORTE, RE1 ;set cs pin high to inactive so cant write
return
Increment_1;increment the value of the registers for the first half of the FRAM
infsnz storage_low_1, f ;increment number in lowest byte
bra inc_high_1 ;if not zero it will return else increment next byte
return
inc_high_1
infsnz storage_high_1, f ;increment number in middle byte
bra inc_highest_1 ;if not zero it will return else increment next byte
return
inc_highest_1
infsnz storage_highest_1, f ;increment number in highest byte and return
retlw 0xFF
return
Increment_2;increment the value of the registers for the second half of the FRAM
infsnz storage_low_2, f ;increment number in lowest byte
bra inc_high_2 ;if not zero it will return else increment next byte
return
inc_high_2
infsnz storage_high_2, f ;increment number in middle byte
bra inc_highest_2 ;if not zero it will return else increment next byte
return
inc_highest_2
infsnz storage_highest_2, f ;increment number in highest byte and return
retlw 0xFF
return
end