[Menu]>[Circuits Gallery]>[Remote Controller]


Source code file of Transmitter

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
;********************************************************
;
;               Remote Controller Transmitter
;
;                                 Author : Seiichi Inoue
;********************************************************

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


;****************  Label Definition  ********************
        cblock  h'0c'
tx_status                       ;TX status save area
tx_substatus                    ;TX substatus save area
pattern                         ;Pattern save area
        endc

ptn1    equ     b'11110000'     ;Pattern 1 data
ptn2    equ     b'00001111'     ;Pattern 2 data
ra4     equ     d'4'            ;RA4 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'00000011'     ;RA4-2:OUT RA1,0:IN mode
        movwf   trisa           ;Set TRISA reg
        movlw   b'00000101'     ;RBPU/TOCS/PSA=0,PS=101
        movwf   option_reg      ;Set OPTION_REG
        bcf     status,rp0      ;Change to Bank0

        clrf    porta           ;Stop wave emission
        clrf    tx_status       ;Clear TX status
        clrf    tx_substatus    ;Clear TX substatus

        movlw   b'00000001'     ;Set mask pattern
        andwf   porta,w         ;Pick up RA0
        btfsc   status,z        ;RA0 = 1 (SW1 ON) ?
        goto    in1             ;No. Check next input
        movlw   ptn1            ;Set pattern1 data
in0     movwf   pattern         ;Save pattern data
        goto    tm              ;Jump to timer set
in1     movlw   b'00000010'     ;Set mask pattern
        andwf   porta,w         ;Pick up RA1
        btfsc   status,z        ;RA1 = 1 (SW2 ON) ?
        goto    init            ;No. Illegal input
        movlw   ptn2            ;Set pattern2 data
        goto    in0             ;Jump to pattern save

tm      movlw   d'100'          ;256-10000us/64us = 100
        movwf   tmr0            ;Set 10msec to TMR0
        movlw   h'a0'           ;GIE=1,TOIE=1
        movwf   intcon          ;Interruption enable

        goto    $               ;Wait interruption

;*********  Begin Timer Interruption Process  ***********
int
        bcf     intcon,t0if     ;Clear timer int flag

stchk0
        movf    tx_status,w     ;Read TX status
        btfss   status,z        ;TX status = 0 ?
        goto    stchk1          ;No. Next

;************  Preamble data send Process  **************
        movlw   d'7'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfsc   status,z        ;Substatus = 7 ?
        goto    stinc           ;Yes. Substatus + 1
        movlw   d'8'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfsc   status,z        ;Substatus = 8 ?
        goto    st01            ;Yes.
        movlw   d'9'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfsc   status,z        ;Substatus = 9 ?
        goto    st02            ;Yes.
        movlw   b'00000001'     ;Set mask pattern
        andwf   tx_substatus,w  ;Pick up LSB
        btfss   status,z        ;LSB = 0 (Even) ?
        goto    st00            ;No. (Odd)
        bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1
st00    bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1
st01    bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1
st02    bsf     porta,ra4       ;Start wave emission
        clrf    tx_substatus    ;Clear TX substatus
        incf    tx_status,f     ;Set TX status = 1
        goto    int_end         ;Jump to timer int end

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

;************  Control data send Process  ***************
        movf    tx_substatus,w  ;Read TX substatus
        btfss   status,z        ;Substatus = 0 ?
        goto    st11            ;No. Next
        movlw   b'00000001'     ;Set mask pattern
        andwf   pattern,w       ;Pick up data
        btfss   status,z        ;Data = 0 ?
        goto    st10            ;No. Data = 1
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1
st10    bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st11    movlw   d'1'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 1 ?
        goto    st12            ;No. Next
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1
        
st12    movlw   d'2'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 2 ?
        goto    st13            ;No. Next
        bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st13    movlw   d'3'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 3 ?
        goto    st15            ;No. Next
        movlw   b'00000010'     ;Set mask pattern
        andwf   pattern,w       ;Pick up data
        btfss   status,z        ;Data = 0 ?
        goto    st14            ;No. Data = 1
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1
st14    bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st15    movlw   d'4'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 4 ?
        goto    st16            ;No. Next
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1

st16    movlw   d'5'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 5 ?
        goto    st17            ;No. Next
        bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st17    movlw   d'6'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 6 ?
        goto    st19            ;No. Next
        movlw   b'00000100'     ;Set mask pattern
        andwf   pattern,w       ;Pick up data
        btfss   status,z        ;Data = 0 ?
        goto    st18            ;No. Data = 1
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1
st18    bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st19    movlw   d'7'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 7 ?
        goto    st20            ;No. Next
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1

st20    movlw   d'8'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 8 ?
        goto    st21            ;No. Next
        bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st21    movlw   d'9'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 9 ?
        goto    st23            ;No. Next
        movlw   b'00001000'     ;Set mask pattern
        andwf   pattern,w       ;Pick up data
        btfss   status,z        ;Data = 0 ?
        goto    st22            ;No. Data = 1
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1
st22    bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st23    movlw   d'10'           ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 10 ?
        goto    st24            ;No. Next
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1

st24    movlw   d'11'           ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 11 ?
        goto    st25            ;No. Next
        bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st25    movlw   d'12'           ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 12 ?
        goto    st27            ;No. Next
        movlw   b'00010000'     ;Set mask pattern
        andwf   pattern,w       ;Pick up data
        btfss   status,z        ;Data = 0 ?
        goto    st26            ;No. Data = 1
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1
st26    bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st27    movlw   d'13'           ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 13 ?
        goto    st28            ;No. Next
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1

st28    movlw   d'14'           ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 14 ?
        goto    st29            ;No. Next
        bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st29    movlw   d'15'           ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 15 ?
        goto    st31            ;No. Next
        movlw   b'00100000'     ;Set mask pattern
        andwf   pattern,w       ;Pick up data
        btfss   status,z        ;Data = 0 ?
        goto    st30            ;No. Data = 1
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1
st30    bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st31    movlw   d'16'           ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 16 ?
        goto    st32            ;No. Next
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1

st32    movlw   d'17'           ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 17 ?
        goto    st33            ;No. Next
        bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st33    movlw   d'18'           ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 18 ?
        goto    st35            ;No. Next
        movlw   b'01000000'     ;Set mask pattern
        andwf   pattern,w       ;Pick up data
        btfss   status,z        ;Data = 0 ?
        goto    st34            ;No. Data = 1
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1
st34    bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st35    movlw   d'19'           ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 19 ?
        goto    st36            ;No. Next
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1

st36    movlw   d'20'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 20 ?
        goto    st37            ;No. Next
        bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st37    movlw   d'21'           ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 21 ?
        goto    st39            ;No. Next
        movlw   b'10000000'     ;Set mask pattern
        andwf   pattern,w       ;Pick up data
        btfss   status,z        ;Data = 0 ?
        goto    st38            ;No. Data = 1
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1
st38    bsf     porta,ra4       ;Start wave emission
        goto    stinc           ;Jump to Substatus + 1

st39    movlw   d'22'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 22 ?
        goto    st40            ;No. Next
        bcf     porta,ra4       ;Stop wave emission
        goto    stinc           ;Jump to Substatus + 1

st40    bsf     porta,ra4       ;Start wave emission
        clrf    tx_substatus    ;Clear TX substatus
        incf    tx_status,f     ;Set TX status = 2
        goto    int_end         ;Jump to timer int end

;**************  End data send Process  *****************
stchk2  movlw   d'2'            ;Set check data
        subwf   tx_substatus,w  ;Substatus - check data
        btfss   status,z        ;Substatus = 2 ?
        goto    stinc           ;No.Jump to Substatus + 1
        bcf     porta,ra4       ;Stop wave emission
        clrf    tx_substatus    ;Clear TX substatus
        clrf    tx_status       ;Clear TX status
        goto    int_end         ;Jump to timer int end

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

;********  End of Timer Interruption Process  ***********
int_end movlw   d'100'          ;256-10000us/64us = 100
        movwf   tmr0            ;Set 10msec to TMR0   
        retfie                  ;End of interruption

;********************************************************
;          END of Remote Controller Transmitter
;********************************************************

        end

remocon_source.zip
remocon_hex.zip