目次PIC回路集リモコン


無線リモコン受信機 ソースリスト

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
;********************************************************
;
;                Remote Controller Receiver
;
;                                 Author : Seiichi Inoue
;********************************************************

        list            p=pic16f84a
        include         p16f84a.inc
        __config _hs_osc & _wdt_off & _pwrte_on & _cp_off
        errorlevel      -302    ;Eliminate bank warning


;****************  Label Definition  ********************
        cblock  h'0c'
rx_status                       ;RX status save area
rx_substatus                    ;RX substatus save area
rx_edge                         ;Input edge check flag
last_look                       ;Input last look flag
code_ck                         ;Code check flag
cont_data                       ;Control Data
relay                           ;Relay ON counter
w_save                          ;W reg save area
s_save                          ;Status reg save area
        endc

ptn1    equ     b'11110000'     ;Pattern 1 data
ptn2    equ     b'00001111'     ;Pattern 2 data
ra1     equ     d'1'            ;RA1 bit position
rb5     equ     d'5'            ;RB5 bit position
rb7     equ     d'7'            ;RB7 bit position

;****************  Program Start  ***********************
        org     0               ;Reset Vector
        goto    init
        org     4               ;Interrupt Vector
        goto    int

;******************  Initial Process  *******************
init    bsf     status,rp0      ;Change to Bank1
        movlw   b'00011111'     ;RA4-0:IN mode
        movwf   trisa           ;Set TRISA reg
        movlw   b'00000000'     ;RB7-0:OUT mode
        movwf   trisb           ;Set TRISB reg
        movlw   b'00000101'     ;RBPU/TOCS/PSA=0,PS=101
        movwf   option_reg      ;Set OPTION_REG
        bcf     status,rp0      ;Change to Bank0

        clrf    portb           ;RL1,RL2 OFF
        clrf    rx_status       ;Clear RX status
        clrf    rx_substatus    ;Clear RX substatus
        clrf    rx_edge         ;Clear Edge check flag
        incf    last_look,f     ;Set Last Look flag ON
        clrf    code_ck         ;Clear code check flag
        clrf    cont_data       ;Clear Control Data
        clrf    relay           ;Clear Relay ON counter
        movlw   d'100'          ;256-10000us/64us = 100
        movwf   tmr0            ;Set 10msec to TMR0
        movlw   h'a0'           ;GIE=1,TOIE=1
        movwf   intcon          ;Interruption enable

;***********  Initial Input check Process  **************
edge_check
        btfss   porta,ra1       ;Input signal ON ?
        goto    check1          ;No. Signal OFF
        btfsc   last_look,0     ;Last Look flag OFF ?
        goto    edge_check      ;No. Input NOT changed
        bcf     intcon,gie      ;Interruption disable
        incf    code_ck,f       ;Set code check flag ON
        incf    last_look,f     ;Set Last Look flag ON
        movlw   d'178'          ;256-5000us/64us = 178
        movwf   tmr0            ;Set 5msec to TMR0
        bsf     intcon,gie      ;Interruption enable
wait
        btfss   rx_edge,0       ;Input edge check ?
        goto    wait            ;No. Wait interruption
        clrf    rx_edge         ;Clear edge check flag
        goto    edge_check      ;Jump to Input edge check
check1
        clrf    last_look       ;Set Last Look flag OFF
        goto    edge_check      ;Jump to Input edge check

;************  Timer Interruption Process  **************
int
        movwf   w_save          ;Save W register
        movf    status,w        ;Read STATUS reg
        movwf   s_save          ;Save STATUS reg
        bcf     status,rp0      ;Change to Bank0
        bcf     intcon,t0if     ;Clear timer int flag

        movf    relay,w         ;Read Relay ON counter
        btfsc   status,z        ;Counter = 0 ?
        goto    stchk0          ;Yes
        decfsz  relay,f         ;Counter - 1 = 0 ?
        goto    stchk0          ;No
        clrf    portb           ;Relay OFF

stchk0
        movf    code_ck,w       ;Read code check flag
        btfsc   status,z        ;Flag ON ?
        goto    int_end         ;No. End of interruption
        movf    rx_status,w     ;Read RX status
        btfss   status,z        ;Status = 0 ?
        goto    stchk1          ;No. Next

;***********  Preamble data check Process  *************
        movf    rx_substatus,w  ;Read RX substatus
        btfss   status,z        ;Substatus = 0 ?
        goto    st00            ;No. Next
        goto    st_on           ;Input signal ON ?
st00    movlw   d'1'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 1 ?
        goto    st01            ;No.
        goto    st_off          ;Input signal OFF ?
st01    movlw   d'2'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 2 ?
        goto    st02            ;No.
        goto    st_on           ;Input signal ON ?
st02    movlw   d'3'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 3 ?
        goto    st03            ;No.
        goto    st_off          ;Input signal OFF ?
st03    movlw   d'4'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 4 ?
        goto    st04            ;No.
        goto    st_on           ;Input signal ON ?
st04    movlw   d'5'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 5 ?
        goto    st05            ;No.
        goto    st_off          ;Input signal OFF ?
st05    movlw   d'6'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 6 ?
        goto    st06            ;No.
        goto    st_on           ;Input signal ON ?
st06   movlw   d'7'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 7 ?
        goto    st07            ;No. Substatus=8
        goto    st_on           ;Input signal ON ?
st07    btfsc   porta,ra1       ;Input signal OFF ?
        goto    illegal         ;No. Jump to illegal
        clrf    rx_substatus    ;RX substatus = 0
        incf    rx_status,f     ;RX status = 1
        clrf    cont_data       ;Clear count data
        goto    int_end         ;End of interruption

;********************************************************
stchk1
        movlw   d'1'            ;Set check data
        subwf   rx_status,w     ;RX status - check data
        btfss   status,z        ;RX status = 1 ?
        goto    stchk2          ;No. Next

;************  Control data check Process  **************
        movf    rx_substatus,w  ;Read RX substatus
        btfss   status,z        ;Substatus = 0 ?
        goto    st10            ;No. Next
        goto    st_on           ;Input signal ON ?
st10    movlw   d'1'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 1 ?
        goto    st11            ;No.
        btfss   porta,ra1       ;B0 = 1 ?
        goto    stinc           ;Jump to Substatus + 1
        bsf     cont_data,0     ;Set B0 = 1
        goto    stinc           ;Jump to Substatus + 1
st11    movlw   d'2'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 2 ?
        goto    st12            ;No.
        goto    st_off          ;Input signal OFF ?
st12    movlw   d'3'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 3 ?
        goto    st13            ;No.
        goto    st_on           ;Input signal ON ?
st13    movlw   d'4'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 4 ?
        goto    st14            ;No.
        btfss   porta,ra1       ;B1 = 1 ?
        goto    stinc           ;Jump to Substatus + 1
        bsf     cont_data,1     ;Set B1 = 1
        goto    stinc           ;Jump to Substatus + 1
st14    movlw   d'5'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 5 ?
        goto    st15            ;No.
        goto    st_off          ;Input signal OFF ?
st15    movlw   d'6'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 6 ?
        goto    st16            ;No.
        goto    st_on           ;Input signal ON ?
st16    movlw   d'7'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 7 ?
        goto    st17            ;No.
        btfss   porta,ra1       ;B2 = 1 ?
        goto    stinc           ;Jump to Substatus + 1
        bsf     cont_data,2     ;Set B2 = 1
        goto    stinc           ;Jump to Substatus + 1
st17    movlw   d'8'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 8 ?
        goto    st18            ;No.
        goto    st_off          ;Input signal OFF ?
st18    movlw   d'9'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 9 ?
        goto    st19            ;No.
        goto    st_on           ;Input signal ON ?
st19    movlw   d'10'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 10 ?
        goto    st20            ;No.
        btfss   porta,ra1       ;B3 = 1 ?
        goto    stinc           ;Jump to Substatus + 1
        bsf     cont_data,3     ;Set B3 = 1
        goto    stinc           ;Jump to Substatus + 1
st20    movlw   d'11'           ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 11 ?
        goto    st21            ;No.
        goto    st_off          ;Input signal OFF ?
st21    movlw   d'12'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 12 ?
        goto    st22            ;No.
        goto    st_on           ;Input signal ON ?
st22    movlw   d'13'           ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 13 ?
        goto    st23            ;No.
        btfss   porta,ra1       ;B4 = 1 ?
        goto    stinc           ;Jump to Substatus + 1
        bsf     cont_data,4     ;Set B4 = 1
        goto    stinc           ;Jump to Substatus + 1
st23    movlw   d'14'           ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 14 ?
        goto    st24            ;No.
        goto    st_off          ;Input signal OFF ?
st24    movlw   d'15'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 15 ?
        goto    st25            ;No.
        goto    st_on           ;Input signal ON ?
st25    movlw   d'16'           ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 16 ?
        goto    st26            ;No.
        btfss   porta,ra1       ;B5 = 1 ?
        goto    stinc           ;Jump to Substatus + 1
        bsf     cont_data,5     ;Set B5 = 1
        goto    stinc           ;Jump to Substatus + 1
st26    movlw   d'17'           ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 17 ?
        goto    st27            ;No.
        goto    st_off          ;Input signal OFF ?
st27    movlw   d'18'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 18 ?
        goto    st28            ;No.
        goto    st_on           ;Input signal ON ?
st28    movlw   d'19'           ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 19 ?
        goto    st29            ;No.
        btfss   porta,ra1       ;B6 = 1 ?
        goto    stinc           ;Jump to Substatus + 1
        bsf     cont_data,6     ;Set B6 = 1
        goto    stinc           ;Jump to Substatus + 1
st29    movlw   d'20'           ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 20 ?
        goto    st30            ;No.
        goto    st_off          ;Input signal OFF ?
st30    movlw   d'21'           ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 21 ?
        goto    st31            ;No.
        goto    st_on           ;Input signal ON ?
st31    movlw   d'22'           ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 22 ?
        goto    st32            ;No. Substatus=23
        btfss   porta,ra1       ;B7 = 1 ?
        goto    stinc           ;Jump to Substatus + 1
        bsf     cont_data,7     ;Set B7 = 1
        goto    stinc           ;Jump to Substatus + 1
st32    btfsc   porta,ra1       ;Input signal OFF ?
        goto    illegal         ;No. Jump to illegal
        clrf    rx_substatus    ;RX substatus = 0
        incf    rx_status,f     ;RX status = 2
        goto    int_end         ;End of interruption

st_on
        btfss   porta,ra1       ;Input signal ON ?
        goto    illegal         ;No. Jump to illegal
        goto    stinc           ;Jump to Substatus + 1
st_off
        btfsc   porta,ra1       ;Input signal OFF ?
        goto    illegal         ;No. Jump to illegal
        goto    stinc           ;Jump to Substatus + 1

;**************  End data check Process  ****************
stchk2  btfss   porta,ra1       ;Input signal ON ?
        goto    illegal         ;No. Jump to illegal
        movlw   d'2'            ;Set check data
        subwf   rx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 2 ?
        goto    stinc           ;Jump to Substatus + 1

;****************  Data check Process  ******************
        movf    cont_data,w     ;Read control data
        xorlw   ptn1            ;Check Pattern1
        btfss   status,z        ;Data = Pattern1 ?
        goto    dtchk0          ;No.
        bcf     portb,rb7       ;RL2 OFF
        bsf     portb,rb5       ;RL1 ON
        goto    dtchk1          ;Jump to ON counter set
dtchk0
        movf    cont_data,w     ;Read control data
        xorlw   ptn2            ;Check Pattern2
        btfss   status,z        ;Data = Pattern2 ?
        goto    illegal         ;No. Jump to illegal
        bcf     portb,rb5       ;RL1 OFF
        bsf     portb,rb7       ;RL2 ON
dtchk1  movlw   d'50'           ;Set 500msec Relay ON
        movwf   relay           ;Save Relay ON counter

;*****************  Illegal Process  ********************
illegal incf    rx_edge,f       ;Edge check flag ON
        clrf    rx_substatus    ;RX substatus = 0
        clrf    rx_status       ;RX status = 0
        clrf    code_ck         ;Clear code check flag
        goto    int_end         ;End of interruption

;***********  Substatus Increment Process  **************
stinc   incf    rx_substatus,f  ;Substatus + 1

;********  End of Timer Interruption Process  ***********
int_end movlw   d'100'          ;256-10000us/64us = 100
        movwf   tmr0            ;Set 10msec to TMR0
        movf    s_save,w        ;Read saved STATUS reg
        movwf   status          ;Recover STATUS reg
        swapf   w_save,f        ;Read saved W register
        swapf   w_save,w        ;Recover W register
        retfie                  ;End of interruption

;********************************************************
;           END of Remote Controller Receiver
;********************************************************

        end

remo_r_source.zip
remo_r_hex.zip