📄 pbir.asm
字号:
;
; Packard Bell Infrared Remote receiver
;
; Copyright (C) 2000-1 Tom Parker (tom-hc11@wiresncode.com)
; Portions Copyright (C) 2000 Paul Stoffregen (paul@pjrc.com)
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 2
; of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;
; Author's note: This is free software, for commerical use I would
; appreciate some recognition though. If you are using this and like
; it send me some email or a postcard. Code changes for inclusion
; are also welcome.
;
; Tom Parker, PO Box 2165, Fitzroy, VIC, 3065, AUSTRALIA (tom@wiresncode.com)
;
.include "pbir.h"
;
;---------------------------------------------------------
;
;
;-* *------------------* *-------* *-------*
; | | | | | | |
; | | | | | | |
; *----------------* *-------* *---------------* *---
; ^ ^ ^ ^
; | preamble | zero | one |
;
;
minpre = 0x3080 ;Minimum preamble length
maxpre = 0x3100 ;Maximum preamble length
minzero = 0x03f0 ;Minimum zero pulse length
maxzero = 0x0430 ;Maximum zero pulse length
minone = 0x07f0 ;Minimum one pulse length
maxone = 0x0830 ;Maximum one pulse length
; typical sequence
;
; 30 A0
; 04 0F 04 0F 03 F9 04 10 08 22 03 FB 04 25 03 F8 08 12 08 0D 08 21 08 11 04 0E 08 23 07 FB
; 08 20 08 13 04 0C 04 0E 08 0F 03 FC 04 10 04 0D 04 11 04 0E 07 FB 08 22 04 0E 08 10 08 23
;---------------------------------------------------------;
.module pbir_asm
.area code (REL)
;
;Initialisation
;
pbir_init:
mov irmesg+0, #0
mov irmesg+1, #0
mov irbitcnt, #0
mov ircode, #0xff
clr irprefound
ret
;
;save current timer & enable interrupts
;
pbir_start:
mov irtimersample+0, th0
mov irtimersample+1, tl0
ret
;
;interrupt service routine
;
pbir_isr:
clr ex0
push acc
clr rs1 ;register bank 1
setb rs0
clr tr0
mov r6, th0 ;save new timer sample
mov r7, tl0
setb tr0
mov a, r6
mov r4, a
mov a, r7 ;subtract lsb from previous
clr c
subb a, irtimersample+1
jnc i0noborrow
dec r4 ;borrow from msb
i0noborrow:
mov r5, a
mov a, r4 ;subtract msb from previous
clr c
subb a, irtimersample+0
mov r4, a
mov irtimersample+0, r6
mov irtimersample+1, r7
i0zmsbmax:
add a, #255 - (maxzero >> 8)
jc i0omsbmax ;check zero msb maximum
inc a
jnz i0zmsbmin
mov a, r5 ;check lsb maximum
add a, #255 - (maxzero & 0x00ff)
jc i0omsbmax
i0zmsbmin:
mov a, r4
add a, #255 - (minzero >> 8) + 1
jnc i0invalid ;check msb minimum
jnz i0zerofound
mov a, r5 ;check lsb minimum
clr c
subb a, #(minzero & 0x00ff)
jc i0invalid
i0zerofound:
jnb irprefound, i0invalid
clr c
sjmp i0datafound
i0invalid:
clr irprefound
ajmp i0done
i0omsbmax:
mov a, r4
add a, #255 - (maxone >> 8)
jc i0pmsbmax ;check zero msb maximum
inc a
jnz i0omsbmin
mov a, r5 ;check lsb maximum
add a, #255 - (maxone & 0x00ff)
jc i0pmsbmax
i0omsbmin:
mov a, r4
add a, #255 - (minone >> 8) + 1
jnc i0invalid ;check msb minimum
jnz i0onefound
mov a, r5 ;check lsb minimum
clr c
subb a, #(minone & 0x00ff)
jc i0invalid
i0onefound:
jnb irprefound, i0invalid
setb c
i0datafound:
mov a, irmesg+0
rlc a
mov irmesg+0, a
mov a, irmesg+1
rlc a
mov irmesg+1, a
dec irbitcnt
mov a, irbitcnt
jz i0mesg ;whole mesg?
cjne a, #16, i0done ;first 2 bytes?
mov a, irmesg+1 ;check for control ID
cjne a, #0x08, i0invalid
mov a, irmesg+0
cjne a, #0xf7, i0invalid
sjmp i0done
i0mesg:
mov a, ircode ;check previous mesg was received
cjne a, #0xff, i0invalid
mov a, irmesg+0 ;check new mesg
xrl a, #0xff
cjne a, irmesg+1, i0invalid
mov ircode, a
clr irprefound
sjmp i0done
i0pmsbmax:
mov a, r4
add a, #255 - (maxpre >> 8)
jc i0invalid ;check msb maximum
inc a
jnz i0pmsbmin
mov a, r5 ;check lsb maximum
add a, #255 - (maxpre & 0x00ff)
jc i0invalid
i0pmsbmin:
mov a, r4
add a, #255 - (minpre >> 8) + 1
jnc i0invalid ;check msb minimum
jnz i0prefound
mov a, r5 ;check lsb minimum
clr c
subb a, #(minpre & 0x00ff)
jc i0invalid
i0prefound:
setb irprefound ;flag preamble and clear message buffer
mov irmesg+0, #0
mov irmesg+1, #0
mov irbitcnt, #32
i0done:
pop acc
setb ex0
clr rs1 ;register bank 0
clr rs0
reti
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -