SerBit16
movlw .8 ;bit counter
movwf cnt1
movwf cnt2
bsf GPIO,2 ;mark
call dly50
call dly50
call dly50
s16H
btfsc tmpTMR16+1,7
;;;;;;;;;;;;;;;do high byte
call Manch1 ;out a 1
btfss tmpTMR16+1,7
call Manch0 ;out a 0
rlf tmpTMR16+1,F
decfsz cnt1,F
goto s16H
s16L
btfsc tmpTMR16,7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;do low byte
call Manch1 ;out a 1
btfss tmpTMR16,7
call Manch0 ;out a 0
rlf tmpTMR16,F
decfsz cnt2,F
goto s16L
bsf GPIO,2 ;mark
call dly50
call dly50
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SerBit8 takes whatever was loaded into 8 bit reg
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; tmpTMR8 and encodes it into Manchester MSB first
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; format.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SerBit8
movlw .8 ;bit counter
movwf cnt1
bsf GPIO,2 ;mark
call dly50
call dly50
sloop8
btfsc tmpTMR8,7 ;do byte
call Manch1 ;out a 1
btfss tmpTMR8,7
call Manch0 ;out a 0
rlf tmpTMR8,F
decfsz cnt1,F
goto sloop8
bsf GPIO,2 ;mark
call dly50
call dly50
return
made all the difference in understanding and creating a
robust interface.
A brief code description starts with the bit timing,
which is set near the module bottom to 50 µs for a 4
MHz clock. The leaked Manchester code is on pin
GPIO2. There is a function call for 16-bit data and eight-bit
data. The eight-bit call marks a 1 for 100 µs then calls a
one-bit or zero-bit function to serially output the byte. This
is followed by another mark to a 1.
Again, marking helps in synchronizing the decoder.
The 16-bit call processes the high byte followed by the
low byte in a similar manner. With a bit of editing, this
simple code can be adapted to just about any processor,
not just low-end PICs.
Code Block 3
;*******************************************************
; *
;;;;Filename: Manchester.asm *
;;;;Date: 081616 *
;;;;Author: Copyright 2002-2016 Kevin J O’Connor *
;;;;Company: Hollywood Controls *
; *
; *
;*******************************************************
;
; SerBit16 takes whatever was loaded into 16 bit reg
; tmpTMR16 and encodes it into Manchester MSB first
; format.
;
;
#include <p12f629.inc>
;;;;;;;;;;;;;;; processor specific variable definitions
#include <CapBtn.inc>
Manch code
;
;Global/Extern
;
global SerBit16, SerBit8
extern tmpTMR16
;;;;;;;;;;;;;;;16 bit register pair containing
;;;;;;;;;;;;;;;word to convert to Manchester
extern tmpTMR8
;;;;;;;;;;;;;;;8 bit register containing
;
;;;;;;;;;;;;;;;word to convert to Manchester
extern cnt1, cnt2
;;;;;;;;;;;;;;;counters for timer
Manch1 ;make a 1’s bit cell
bsf GPIO,2
call dly50
bcf GPIO,2
call dly50
return
Manch0 ;make a 0’s bit cell
bcf GPIO,2
call dly50
bsf GPIO,2
call dly50
return
;
;Manchester 1/2 bit timing loop for 50us 4MHz clock
;
dly50
movlw D’15’
movwf CounterA
tloop
decfsz CounterA,1
goto tloop
retlw 0
END
In Code Block 4, I have shown just the rudimentary
outline of how you might use the assembly code version
in a more complete program. (I’m assuming a PIC12F629
again.) In this code, I have allocated and initialized the
Manchester registers, as well as provided the module
references. The remaining code transfers the PIC status
March 2018 37