-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathM_input_2.asm
More file actions
173 lines (139 loc) · 4.72 KB
/
Copy pathM_input_2.asm
File metadata and controls
173 lines (139 loc) · 4.72 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
#include p18f87k22.inc
extern LCD_Write_Hex, ADC_Setup, ADC_Read, add_check_setup, eight_bit_by_sixteen,sixteen_bit_by_sixteen,eight_bit_by_twentyfour, ADC_convert ; external ADC routines
extern UART_Setup, UART_Transmit_Message ; external UART subroutines
extern LCD_Setup, LCD_Write_Message, LCD_clear, LCD_move,LCD_delay_ms,LCD_Send_Byte_D,LCD_shiftright,LCD_delay_x4us ; external LCD subroutines
extern Pad_Setup, Pad_Read, sampling_delay_input
global Input_store2, Store_Input_2_Setup,Storage_Clear2
;global in2_storage_low,in2_storage_high,in2_storage_highest,first_storage_low,first_storage_high,first_storage_highest,last_storage_low,last_storage_high,last_storage_highest
acs0 udata_acs ; reserve data space in access ram
in2_storage_low res 1
in2_storage_high res 1
in2_storage_highest res 1
input_lower res 1
input_upper res 1
first_storage_low res 1
first_storage_high res 1
first_storage_highest res 1
last_storage_low res 1
last_storage_high res 1
last_storage_highest res 1
MIC code
Store_Input_2_Setup ;setup of serial output
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
movlw 0x02
movwf in2_storage_low
movlw 0xE8
movwf in2_storage_high
movlw 0x03
movwf in2_storage_highest
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
Input_store2
call sampling_delay_input
bcf PORTE, RE1 ;set cs pin low to active so can write
movlw 0x06
call SPI_MasterTransmitInput
bsf PORTE, RE1
call ADC_Read
movff ADRESL,input_lower
movff ADRESH,input_upper
bcf PORTE, RE1
movlw 0x02
call SPI_MasterTransmitInput
movf in2_storage_highest, W
call SPI_MasterTransmitInput
movf in2_storage_high, W
call SPI_MasterTransmitInput
movf in2_storage_low, W
call SPI_MasterTransmitInput
movf input_upper, W
call SPI_MasterTransmitInput
movf input_lower, W
call SPI_MasterTransmitInput
bsf PORTE, RE1 ;set cs pin high to inactive so cant write
call increment_file ;have to increment file number twice as two bytes written
call increment_file
call File_check2
return
increment_file
infsnz in2_storage_low, f ;increment number in lowest byte
bra inc_high ;if not zero it will return else increment next byte
return
inc_high
infsnz in2_storage_high, f ;increment number in middle byte
bra inc_highest ;if not zero it will return else increment next byte
return
inc_highest
infsnz in2_storage_highest, f ;increment number in highest byte and return
retlw 0xFF
return
SPI_MasterTransmitInput ; Start transmission of data (held in W)
movwf SSP1BUF
Wait_TransmitInput ; Wait for transmission to complete
btfss PIR1, SSP1IF
bra Wait_TransmitInput
bcf PIR1, SSP1IF ; clear interrupt flag
return
File_check2
movlw 0xFE
cpfseq in2_storage_low
return
movlw 0xFF
cpfseq in2_storage_high
return
movlw 0x07
cpfseq in2_storage_highest
return
movlw 0x03
movwf in2_storage_highest
movlw 0xE8
movwf in2_storage_high
movlw 0x02
movwf in2_storage_low
return
Storage_Clear2
movlw 0x03
movwf in2_storage_highest
movlw 0xE8
movwf in2_storage_high
movlw 0x02
movwf in2_storage_low
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 in2_storage_highest, W
call SPI_MasterTransmitInput
movf in2_storage_high, W
call SPI_MasterTransmitInput
movf in2_storage_low, W
call SPI_MasterTransmitInput
movlw 0x00
call SPI_MasterTransmitInput
movlw 0x00
call SPI_MasterTransmitInput
bsf PORTE, RE1 ;set cs pin high to inactive so cant write
call increment_file ;have to increment file number twice as two bytes written
call increment_file
movlw 0xFE;WILL IT LOOP BACK AROUND?;NUMBERS CORRESPOND TO THE MAX FILE I THINK
cpfseq in2_storage_low
bra Storage_Clear2
movlw 0xFF
cpfseq in2_storage_high
bra Storage_Clear2
movlw 0x07
cpfseq in2_storage_highest
bra Storage_Clear2
return
end