Pic all write 010c pic doc SERIN.pdf

(15 KB) Pobierz
SERIN.htm
; SERIN port, pin, baud, polarity, bytes, filter
; Receives data serially at the specified rate and polarity via the
specified
; port pin. Stores the data as a counted string starting at buffer-1
(buffer is
; the number of bytes in the string). An optional filter causes the routine
to
; ignore data outside a range of ASCII character values set by filt_lo and
; filt_hi.
buffer
B2400
B1200
B600
B300
filt_lo
filt_hi
=
=
=
=
=
=
=
org
ds
ds
ds
ds
ds
ds
ds
ds
31
30
62
126
255
'0'
'9'
8
1
1
1
1
1
1
1
1
=
=
=
=
;
;
;
;
;
;
;
String storage.
Bit delay for 2400 baud.
Bit delay for 1200 baud.
Bit delay for 600 baud.
Bit delay for 300 baud.
Set filter for ASCII
chars representing 0-9.
baud
pin
port
bytes
temp1
temp2
temp3
ser_fl
;
;
;
;
;
;
;
;
Baud rate.
Pin number (0-7).
Port number (0-2).
Number of bytes to receive.
Temporary counter for Serin.
Temporary counter for Serin.
Temporary counter for delay.
Flags for serin switches.
; Polarity: 0=true, 1=inverted.
; Range filter: 0=off, 1=on.
; 1st filter byte passed?: 0=no,
; Temporary flag for filter
polarity
filter
filt_1st
1=yes.
aux
comparisons.
ser_fl.0
ser_fl.1
ser_fl.2
ser_fl.3
; Device data and reset vector
device pic16c55,xt_osc,wdt_off,protect_off
reset
start
org
0
; Table to convert pin number (0-7) into bit mask (00000001b to 10000000b).
Pinz
jmp
pc+w
retw
1,2,4,8,16,32,64,128
file:///D|/Electronice/Programe/Microcontrolere&PIC/Pic%20all%20write%20010c/pic_doc/SERIN.htm (1 of 4)08.08.2003 03:52:28
SERIN.htm
; Subroutine used by Serin to get a bit and delay for a number of loops
; set by temp3. Jumping into get_bit:loop provides the delay, but ignores
the
; input bit.
get_bit mov
fsr,port
; Point to port.
mov
w,indirect
; IF Polarity = 0 THEN w = Port
snb
Polarity
; ELSE w = NOT Port
mov
w,/indirect
AND
w,pin
snz
; IF w AND pin THEN carry = 1
clc
; ELSE carry = 0.
sz
stc
mov
fsr,temp1
; Point to buffer location.
rr
indirect
; Rotate carry into msb of data byte.
:loop
jmp
$+1
; Two-cycle nops.
jmp
$+1
jmp
$+1
jmp
$+1
jmp
$+1
djnz
temp3,:loop
ret
; Main program start. Receives a single byte of data, filtered for numeric
; characters, and displays the data bits on LEDs connected to port RB.
start
mov
!ra, #15
; All inputs.
mov
!rb,#0
; All outputs for LEDs.
clr
rc
; Clear the LEDs.
clr
ser_fl
; Clear serial flags.
mov
bytes,#1
; Receive 1 byte
clrb
filter
; not filtered
setb
polarity
; inverted polarity
mov
baud,#B2400
; at 2400 baud
mov
pin,#2
; via pin 2
mov
port,#0
; of port ra.
CALL
SERIN
; Receive the data.
mov
rb,buffer-1
; Move byte to LEDs on RB.
jmp
start
; Endless loop
; Body of the Serin routine. Expects the baud constant in baud, number of
; bytes to receive in bytes, the I/O port (0-2 for RA through RC) in port,
; the pin number (0-7) in pin, and the flag settings in ser_fl
file:///D|/Electronice/Programe/Microcontrolere&PIC/Pic%20all%20write%20010c/pic_doc/SERIN.htm (2 of 4)08.08.2003 03:52:28
SERIN.htm
SERIN
:poll
:rcv
:done
:skip
clr
clrb
ADD
mov
CALL
mov
mov
mov
mov
snb
mov
AND
jnz
clc
mov
mov
CALL
mov
CALL
mov
mov
CALL
djnz
mov
CALL
jnb
clrb
csae
setb
csbe
setb
jnb
snb
ret
jmp
setb
DEC
inc
djnz
ret
buffer
filt_1st
port,#RA
w,pin
Pinz
pin,w
temp1,#buffer-1
fsr,port
w,indirect
Polarity
w,/indirect
w,pin
:poll
; Clear buffer counter.
; Add offset for port RA.
; Get bit mask from the table.
; Put the mask into pin.
; Pointer for first data address.
; IF Polarity = 0 THEN w = Port
; ELSE w = NOT Port
; IF pin = 0 THEN receive data
; ELSE poll
LET temp3 = baud/2
Set up 1/2 bit time delay.
Jump into delay of get_bit.
Set up full bit time delay.
Jump into delay of get_bit.
Eight data bits.
Set up bit delay.
Get the next data bit.
Eight bits received?
Set up bit delay.
Wait for stop bit.
IF filter=0 (off) THEN :skip
LET aux = 0.
; IF byte < filt_lo THEN aux=1
; IF byte > filt_hi THEN aux=1
If aux = 0 (byte is within
filter range) :skip. If byte is
out of range, but valid bytes have
been received, return. Else poll.
Decrement buffer pointer.
Increment buffer counter.
More bytes to receive: poll.
w,>>baud
;
temp3,w
;
get_bit:loop
;
temp3,baud
;
get_bit:loop
;
temp2,#8
;
temp3,baud
;
get_bit
;
temp2,:rcv
;
temp3,baud
;
get_bit:loop
;
filter,:skip
;
aux
;
indirect,#filt_lo
aux
indirect,#filt_hi
aux
aux,:skip
;
filt_1st
;
;
:poll
;
filt_1st
temp1
;
buffer
;
bytes,:poll
;
BACK
file:///D|/Electronice/Programe/Microcontrolere&PIC/Pic%20all%20write%20010c/pic_doc/SERIN.htm (3 of 4)08.08.2003 03:52:28
SERIN.htm
file:///D|/Electronice/Programe/Microcontrolere&PIC/Pic%20all%20write%20010c/pic_doc/SERIN.htm (4 of 4)08.08.2003 03:52:28
Zgłoś jeśli naruszono regulamin