Here is an emulated DS2423 counter I'm working on .......
It does appear to have a problem I've been unable to find...
It wants to hang after running about 3 days...
Its written for Proton basic..... and is still a work in progress
their own slave.....I would have attatched as zip, but couldn't figure out how..
Device = 12F1822 ' PROTON BASIC
Declare Create_Coff = On ' use with mplab sim to debug
' V1a 1st working 12F1822 @ 16mhz
' V1b 1st working 12F1822 @ 16mhz + ctrs
' V1c use 32mhz
' V2 attempt to use TIC int
' V2b
' V2c use count/reset method ~ 10ms - not any mods to reset loop
' V2d try mod reset loop to chk gp0/gp1
' V2d1 use tmr1 as external ctr RA5 input
' V3 TMR1 ctr working
' V4 use GP0 as DQ GP2 as ctr B
' V5 changed RMT1
' V6 = V5 -- cleanup ----
' V6b/c need to implement WDT use ready loop to reset
' V6c make GP1/RA1 output add led RDY pulse
' RA2 must have 3.9k 39k .1u
' V6f
'CONFIG intrc_osc_noclkout,mclre_off,pwrte_on,bod_off,wdt_off,fcmen_off,ieso_off
' intrc_ocs_noclkout 0x3FFC
' mclre_off 0x3FDF -> 3FDC
' pwrte_on 0x3FEF -> 3FCC
' bod_off 0x3CFF -> 3CCC
' wdt_off 0x3FF7 -> 3CC4
' fcmem_off 0x37FF -> 34C4
' ieso_off 0x3BFF -> 30C4
' __cfig 0x30C4
'Config 0x30c2 ' MIKE ' same as above
'Config HS_OSC,mclre_off,pwrte_on,bod_off,wdt_off,fcmen_off,ieso_off
Config1 fosc_intosc,mclre_off,pwrte_on,boren_off,wdte_on,fcmen_off,ieso_off,clkouten_off
''Config2 LVP_OFF, PLLEN_on, wrt_off,stvren_off
Config2 LVP_OFF, PLLEN_on, wrt_off,stvren_off
Declare Xtal 32 'using internal 16
''Declare Xtal 32 '' not sure since using PLL
'-----------------------------------------------------------------------
' FOSC = 32/4 =8mhz ~ 125ns cycle *16 = 2us step *64 = 8us step
' TMR0 1:2 - 1:256 *32 = 4us step
' TMR1 -16 bit
' TMR2 prescale 1,4,16,64 postscale 0-F 1:1-1:16 T2CON.2=1 on
' T2CON<1:0> T2CON<6:3>
'-----------------------------------------------------------------------
EData $08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08
EData $08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08
EData $09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09
EData $09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09
EData $0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a
EData $0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a
EData $0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b
EData $0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b
EData $0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c
EData $0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c
EData $0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d
EData $0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d
EData $0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E
EData $0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$0E
EData $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f
'EData "165-9a"
EData "V6g---"
EData $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f
'------------------------------------------------------------------------------
' PIC12F1882
' __ __
' | \__/ |
' +5v --- Vdd |1 8| Vss --- 0v
' ctrA in --> RA5/T1CKI/OSC1/CLKIN |2 7| RA0/AN0/CIN+/ICSPDAT/ULPWU <--> DQ
' RA4/AN3/!T1G/OSC2/CLKOUT/ |3 6| RA1/AN1/CIN-/Vref/ICSPCLK <-->
' reset ctrs --> RA3/!MCLR/Vpp |4 5| RA2/AN2/T0CKI/INT/COUT/CCP1 <--ctrB in
' |________|
'
' ______
' | |----DQ---------------\ \---------------------------------------|
' | DS |----0V----------------\ \--------------------------------| |
' |9490R | ____________ | |
' | |----+5V ---------------\ \------------|1 Vdd 8 Vss|-----| |
' | | | | ////// |
' |------| | | |
' | PC | +5---xxxx---|------|---xxxx-----|---|2 RA5 7 RA0|-----------|
' |______| | | | | |
' ctrA - SW .1uf-cap .1uf-cap| |
' | | | | |
' ///////////////////////// | |
' +5---------|>|---------xxxx---------|3 RA4 6 RA1|--- unused
' led 2.7k | |
' | |
' |---------|----xxxx-------|4 RA3 5 RA2|---xxxx-----|-------|-----xxxx--+5 |
' | | 1k |____________| 3.9k | | 39k
' ctr Reset SW .1uf-cap ctrB - SW .1uf-cap
' | | | |
' ////////////////// ///////////////
' Adjust/Rework debounce filters as needed ..........
'------------------------------------------------------------------------------
Symbol FamilyCode = $1D ' Family code - serial# - CRC
Symbol Sn5 = $0
Symbol Sn4 = $0
Symbol Sn3 = $0 ' of this particular device
Symbol Sn2 = $0
Symbol Sn1 = $0
Symbol Sn0 = $0
Symbol FamilyCRC = $C3 ' we could maybe auto gen this within pgm
'------------------------------------------------------------------------------
Symbol Hi=1
Symbol Lo=0
Symbol Wire = PORTA.0
Symbol SW0 = PORTA.3
'Symbol SetWire = INDF0.2
'----------------------------------------------------------------------
Dim TXB As Byte
Dim CRAP As Byte
Dim I As Byte
Dim I1 As Byte
Dim RXB As Byte
Dim CMD As Byte
'======================================================================
Dim CRCData As Byte
Dim CRCLo As Byte
Dim CRCHi As Byte
Dim CRC As CRCLo
Dim Temp As Byte
Dim Index As Byte
'============================
Dim X As Byte
Dim Y As Byte
Dim Acnt[4] As Byte
Dim Bcnt[4] As Byte
Dim M12cnt[4] As Byte
Dim M13cnt[4] As Byte
Dim TA1 As Byte ' lsb
Dim TA2 As Byte ' msb
Dim E_S As Byte
Dim WTA1 As Byte
Dim WTA2 As Byte
Dim WE_S As Byte
Dim AA As E_S.7
Dim Pf As E_S.5
Dim PGA As Byte ' page address
Dim SPO As Byte ' scratch pad address
Dim SPAD[34] As Byte ' 32 + 2
Dim ACT As Byte
Dim BCT As Byte
Dim BitCnt As Byte
Dim TIC As Byte
Symbol TICK = TIC.0
Symbol Allow = TIC.1
Symbol Slots = TIC.2
Symbol Flag = TIC
Symbol Last4 = TIC.3
'-------------------------------------------------------
' Defines after Dim's
'-------------------------------------------------------
Symbol RPF = Flag.7 ' rcv partial flag
Symbol bounce = 100 ' 255-105=150 *70us=10.8 ms
Symbol WPUEN = OPTION_REG,7
On_Hardware_Interrupt GoTo int
GoTo main
'=============================================================================
int:
'=============================================================================
' RA2 external rising edge schmitt trigger .1cap
'-----------------------------------------------------------------------------
Asm
Btfss INTCON,1 ' INTF gp2 int
Retfie
Bcf INTCON,1 ' Clr INTF
Incf BCT,f
Retfie
EndAsm
'------------------------------------------------------------------------------
Asm
check:
Movf BCT,w
Btfsc STATUS,2 ' w = Zero
Return
Addwf Bcnt +0,f
Btfss STATUS,0 ' carry = 1
GoTo check1
Call Binc1
check1: Clrf BCT
Return
EndAsm
' ----------------------------------------------------------------------------
Asm
Ainc: Incfsz Acnt +0,f
Return '
Incfsz Acnt +1,f '\
Return ' \
Incfsz Acnt +2,f ' > increment Acount
Return ' /
Incf Acnt +3,f '/
EndAsm '
Return '
'------------------------------------------------------------------------------
Asm
Binc: Incfsz Bcnt +0,f
Return '
Binc1: Incfsz Bcnt +1,f '\
Return ' \
Incfsz Bcnt +2,f ' > increment Bcount
Return ' /
Incf Bcnt +3,f '/
EndAsm '
Return '
'==============================================================================
main: ' 32/4=8 =>.125 *16 = 2us step for TMR2 1:16
'------------------------------------------------------------------------------
BSR = 1 ' bank 1
'OSCCON = %01111000 ' 16 mhz internal
OSCCON = %11110000 ' 8 mhz internal 8x4=32 pll
OSCTUNE = 0x0 ''f ' SET TMR2, TMR1, TMR2
'OPTION_REG = %10000011 ' !PU 1:16 = 8 US RESOLUTION 8MHZ xtal
'OPTION_REG = %10000100 ' !PU 1:32 = 8 US RESOLUTION 16MHZ xtal
'OPTION_REG = %00000011 ' PU 1:16 @ 4 US step RESOLUTION 16MHZ xtal
OPTION_REG = %01000111 ' PU 1:256 --> 64 * 256 = 16.384ms to ovflo
' intdg bit 6 = 1
TRISA = %00101101 ' gp0, 2,3, 5 input 1,4 outputs
WDTCON = %00011000 ' wdt 4 seconds time out
'--------------------------------------------------------------------------------
BSR = 3
ANSELA = 0 ' all digital
'--------------------------------------------------------------------------------
BSR = 4
WPUA = %00001001 ' weak pullup port A
'--------------------------------------------------------------------------------
BSR = 7
IOCAP = 0 '3 ' RA0-1 pin change rising edge detect
IOCAN = 0 ' no detect falling edge
IOCAF = 0 ' pins that changed
'------------------------------------------------------------------------------
BSR = 0 ' bank 0
'------------------------------------------------------------------------------
' TMR0 = 0 ' 2US RESOLUTION 1:4 PRESCALE
' 001-1:4 010-1:8 011-1:16
' intcon.T0IE = 0 ' DISABLE TIMER 0 INTERRUPT
'==============================================================================
' T1CON cc pp t x u s ' pp = 1:1,2,4,8
'==============================================================================
T1CON = %10000101 ' 10-RA5[TKCI] extinput 00-1:1 0-osc disabled
T1GCON = $00 ' 1-no sync ext clk 0-ukn 1 enb TMR1
'==============================================================================
' Main Timing counter TMR2 00000S00-1:1 01-1:4 10-1:16 11-1:64 S-strt/stop
'==============================================================================
T2CON = %00000010 ' set TMR2 1:16 4 us/step[16mosc]
T2CON.2 = 1 ' start TMR2
'==============================================================================
' SET ADC ' SELECT CHANNEL 0
' ANSELA = 0 '0X51 ' FOSC/16[8mhz clock] & GP0[51h]
' ADCON0 = 0X81 ' RJustify, Vdd ref, AN0-000,
'==============================================================================
CRAP = PORTA '
INTCON.0 = 0 ' IOCIF
INTCON.1 = 0 ' INTF
INTCON.2 = 0 ' T0IF
INTCON.3 = 0 ' IOCIE
INTCON.4 = 0 ' INTE allow RA2 pin int
INTCON.5 = 0 ' T0IE
INTCON.6 = 0 ' PEIE
PORTA=0
PIE1=0
PIE2=0
INTCON = $90 ' GIE & INTE
'================================================================================================
E_S = $1F '\
TA1 = $A0 ' |- preset values
TA2 = $01 '/
GoSub ClrReg ' clear counters
GoTo Wait_IP
'================================================================================================
'================================================================================================
' changed for step = 2us
'================================================================================================
'================================================================================================
Wait_IP: ''INTCON.7 = 0 ' dis able GIE
TMR2 = 0
' TTCT = 0 ' total time cnt = 0
FSR0H=0
'------------------------------------------------------------------------------------------------
BSR=1 ' bank1
TRISA.0=1 ' > -- float
BSR=0 ' bank0
'------------------------------------------------------------------------------------------------
'' INTCON.3=1 ' enb INTE
'------------------------------------------------------------------------------------------------
' may need to mod ewrite to gosub check at 64 us intervals ****************
'------------------------------------------------------------------------------------------------
If Flag.6 = 1 Then GoTo LateWrite ' used for eeprom write
'------------------------------------------------------------------------------------------------
Wait_IPa: If TMR2 = 70/2 Then
TMR2 = 0
GoSub check ' 70 us elapsed
EndIf
Clrwdt
If Wire = Hi Then GoTo Wait_IPa ' could be high long time
'---------------------------------------------------
' wire gone low reset timer
'---------------------------------------------------
Wait_IPa1: TMR2 = 0 ' preset tmro
If PORTA.4=1 Then
PORTA.4=0
Else
PORTA.4=1
EndIf
'----------------------------------------------------
Wait_IP64: If Wire = Hi Then GoTo Wait_IP ' hi before 480 us
' If TMR2 = 70/2 Then GoSub check
' If TMR2 = 140/2 Then GoSub check
If TMR2 = 210/2 Then GoSub check
If PORTA.3 = 0 Then GoSub ClrReg ' ================
' If TMR2 = 280/2 Then GoSub check
' If TMR2 = 350/2 Then GoSub check
If TMR2 = 420/2 Then GoSub check
If TMR2 < 480/2 Then GoTo Wait_IP64 ' < 480 us
TMR2 = 0
'-------------------------------------------------------------------------------
' Update A-Counter rising edge - use .1 cap on RA5/GP5
' schmitt trigger input
'-------------------------------------------------------------------------------
Acnt[0] = TMR1L
Acnt[1] = TMR1H '
If PIR1.0 = 0 Then GoTo Wait_IPx
PIR1.0 = 0
Asm
Incfsz Acnt +2,f ' > increment Acount
GoTo Wait_IPx ' /
Incf Acnt +3,f '/
EndAsm
' if pinchang int then
Wait_IPx: If Wire = Hi Then GoTo E0
If PORTA.3 = 0 Then GoSub ClrReg ' ================
' If TMR2 = 70/2 Then GoSub check
' If TMR2 = 140/2 Then GoSub check
If TMR2 = 210/2 Then GoSub check
' If TMR2 = 280/2 Then GoSub check
' If TMR2 = 350/2 Then GoSub check
If TMR2 = 420/2 Then GoSub check
If TMR2 < 480/2 Then GoTo Wait_IPx ' < 480 us
GoTo Wait_IP ' possible stuck low
E0: TMR2=0 ' set TMR2
E1: If TMR2.3=0 Then GoTo E1 ' 8*2=16 dly 16*2=32us **************
GoSub check
'----------------------------------------------------------------------------------
PORTA.0=0 ' insure latch bit = 0
BSR=1 ' bank1
TRISA.0=0 ' DQ = output = 0 since PORTA.0=0
BSR=0 ' bank 0
'----------------------------------------------------------------------------------
TMR2=0 ' set TMR2
E2: If TMR2 = 70/2 Then GoSub check
If TMR2 = 140/2 Then GoSub check
If TMR2 < 180/2 Then GoTo E2 '' 180us presence
'----------------------------------------------------------------------------------
E2a: BSR=1 ' bank1
TRISA.0=1 ' float
BSR=0 ' bank 0
'----------------------------------------------------------------------------------
'' INTCON.7 = 1 ' enable GIE
E3: If Wire = Lo Then GoTo E3 End If ' wait until wire is high
'================================================================================================
' get cmd byte 8 bits from MASTER
'-------------------------------------------------------------------------------------------------
Fetch: GoSub RX8
'---------------------------------------------------------------------------------
Fetch1: If RXB = $55 Then GoTo MatchRom End If ' match sdr rtn
If RXB = $F0 Then GoTo SearchRom End If ' search
If RXB = $CC Then GoTo Funct_CMD End If ' SkipRom cmd
If RXB = $33 Then GoTo ReadRom End If ' 1 slave online rtn fc,sn,crc
'If RXB = $EC Then GoTo ConditionalSearchRom End If ' search
'If RXB = $3C Then GoTo OverdriveSkipRom End If ' search
'If RXB = $69 Then GoTo OverdriveMatchRom End If ' search
GoTo Wait_IP
'if RXB = $EC then goto AlarmRom end if ' modified search
'if RXB = $FF then goto ReadRom end if ' 1 slave online rtn fc,sn,crc
'goto Wait_IP ' main
'=================================================================================
RX8: ' FSR0L = $8C
' INTCON.7 = 0
GoSub RX1 ' Recieve bit 0
GoSub RX1 ' Recieve bit 1
GoSub RX1 ' Recieve bit 2
GoSub RX1 ' Recieve bit 3
GoSub RX1 ' Recieve bit 4
GoSub RX1 ' Recieve bit 5
GoSub RX1 ' Recieve bit 6
GoSub RX1 ' Recieve bit 7
' INTCON.7 = 1
Return
'=================================================================================
RX1: RXB = RXB >> 1 ' this shifts in a 0 bit ??
RX2: If Wire = Hi Then GoTo RX2 End If
TMR2 = 0 '
x1: If TMR2 < 7 Then GoTo x1 ' 7*2us < 14 us
x2: If Wire = Hi Then ' look for 1 during 14-32 us
RXB.7=1 ' 14-32 us window
Return '
EndIf '
X2x: If TMR2.4=0 Then GoTo x2 End If ' 2^4 = 32us
X3: If Wire = Hi Then Return
X4: If TMR2.6 = 0 Then GoTo X3 End If ' 2^6 = 64*2 = 128 must be interupt
'------------------------------------------------------------------------------------------
GoTo Wait_IP64 ' trash stack ie circular on/off 03/12
'==================================================================================
ReadRom: GoSub WSN ' wire hi & $33 cmd decoded
GoTo Funct_CMD
'==================================================================================
MatchRom: GoSub RX8 ' wire hi & $55 cmd decoded
If RXB <> FamilyCode Then GoTo Wait_IP '0 FC 20 1D
GoSub RX8
If RXB <> Sn5 Then GoTo Wait_IP '1 0
GoSub RX8
If RXB <> Sn4 Then GoTo Wait_IP '2 0
GoSub RX8
If RXB <> Sn3 Then GoTo Wait_IP '3 0
GoSub RX8
If RXB <> Sn2 Then GoTo Wait_IP '4 0
GoSub RX8
If RXB <> Sn1 Then GoTo Wait_IP '5 0
GoSub RX8
If RXB <> Sn0 Then GoTo Wait_IP '6 0
GoSub RX8
If RXB <> FamilyCRC Then GoTo Wait_IP '7 crc EF C3
GoTo Funct_CMD
'===================================================================================
SkipRom: GoTo Funct_CMD ' wire is hi & $F0 cmd decoded
'===================================================================================
SearchRom: TXB = FamilyCode
GoSub SR8
TXB = Sn5
GoSub SR8
TXB = Sn4
GoSub SR8
TXB = Sn3
GoSub SR8
TXB = Sn2
GoSub SR8
TXB = Sn1
GoSub SR8
TXB = Sn0
GoSub SR8
TXB = FamilyCRC
GoSub SR8
GoTo Wait_IP
'===================================================================================
Funct_CMD: FSR0L = $8C ' wire is hi & $CC cmd decoded
'RXB = 0 ' clear old data
GoSub RX1 ' Recieve bit 0
GoSub RX1 ' Recieve bit 1
GoSub RX1 ' Recieve bit 2
GoSub RX1 ' Recieve bit 3
GoSub RX1 ' Recieve bit 4
GoSub RX1 ' Recieve bit 5
GoSub RX1 ' Recieve bit 6
GoSub RX1 ' Recieve bit 7
'GoSub RX8 ' get function byte
Fcmd: If Wire = Lo Then GoTo Fcmd
GoTo Fcmd1
Fcmd1: GoTo Fcmd2
Fcmd2: If RXB = $AA Then GoTo Rd_2423_SP
If RXB = $55 Then GoTo Copy_SP
If RXB = $A5 Then GoTo READ_Mem ''Read_2423_ctr
If RXB = $F0 Then GoTo READ_Mem ''Rd_2423_M
If RXB = $0F Then GoTo Wr_2423_SP
If RXB = $5A Then GoTo Copy_SP
'-------------------------------------------------------------------
GoTo Wait_IP ' no valid cmd
'=========================================================================================
ClrReg: Str M12cnt = $0,$0,$0,$0
Str M13cnt = $0,$0,$0,$0
Str Acnt = $0,$0,$0,$0
Str Bcnt = $0,$0,$0,$0
TMR1L = 0
TMR1H = 0
' ACT = 0
BCT = 0
Return
'=========================================================================================
RD_PWR: TXB=$00 ' FF +5 powered
GoSub TX8
GoTo Wait_IP
'===========================================================================
WSN: TXB = FamilyCode ' $1D ' Family code
GoSub TX8
TXB = Sn5 ' 0 ' SN lsb
GoSub TX8
TXB = Sn4 ' 0 ' SN
GoSub TX8
TXB = Sn3 ' 0 ' SN
GoSub TX8
TXB = Sn2 ' 0 ' SN
GoSub TX8
TXB = Sn1 ' 0 ' SN
GoSub TX8
TXB = Sn0 ' 0 ' SN msb
GoSub TX8
TXB = FamilyCRC ' $C3 ' CRC
GoSub TX8
Return
'===================================================================
' TRANSMIT 32 0 bits
'===================================================================
TX32z: TXB =0
CRCData=0
GoSub TX8
GoSub XCRC16LU
TXB =0
CRCData=0
GoSub TX8
GoSub XCRC16LU
TXB =0
CRCData=0
GoSub TX8
GoSub XCRC16LU
TXB =0
CRCData=0
GoSub TX8
GoSub XCRC16LU
Return
'======================================================================
' TRANSMIT INVERTED CRC & EXIT
'======================================================================
TxINVcrc: TXB=CRCLo ^ $FF ' invert crc
GoSub TX8 '
TXB= CRCHi ^ $FF ' invert crc
GoSub TX8
GoTo Wait_IP
'======================================================================
' TRANSMIT INVERTED CRC & RETURN
'======================================================================
TXcrc: TXB=CRCLo ^ $FF ' invert crc
GoSub TX8 '
TXB= CRCHi ^ $FF ' invert crc
GoSub TX8
CRCLo=0
CRCHi=0
Return
'=======================================================================
' Transmit 8 bits of byte TXB
'=======================================================================
TX8: FSR0L = $8C
If TXB.0=0 Then GoSub TX1L
If TXB.0=1 Then GoSub TX1H
If TXB.1=0 Then GoSub TX1L
If TXB.1=1 Then GoSub TX1H
If TXB.2=0 Then GoSub TX1L
If TXB.2=1 Then GoSub TX1H
If TXB.3=0 Then GoSub TX1L
If TXB.3=1 Then GoSub TX1H
If TXB.4=0 Then GoSub TX1L
If TXB.4=1 Then GoSub TX1H
If TXB.5=0 Then GoSub TX1L
If TXB.5=1 Then GoSub TX1H
If TXB.6=0 Then GoSub TX1L
If TXB.6=1 Then GoSub TX1H
If TXB.7=0 Then GoSub TX1L
If TXB.7=1 Then GoSub TX1H
Return
'======================================================================
' Transmit search bit 0
'======================================================================
SR0: GoSub TX1L
GoSub TX1H
GoSub RX1
If RXB.7=1 Then GoTo Wait_IP End If ' error trash stack
Return
'=================================================================
' Transmit search bit 1
'=================================================================
SR1: GoSub TX1H
GoSub TX1L
GoSub RX1
If RXB.7=0 Then GoTo Wait_IP End If ' error trash stack
Return
'================================================================
' Transmit search bits
'================================================================
SR8: FSR0L = $8C
If TXB.0=0 Then GoSub SR0
If TXB.0=1 Then GoSub SR1
If TXB.1=0 Then GoSub SR0
If TXB.1=1 Then GoSub SR1
If TXB.2=0 Then GoSub SR0
If TXB.2=1 Then GoSub SR1
If TXB.3=0 Then GoSub SR0
If TXB.3=1 Then GoSub SR1
If TXB.4=0 Then GoSub SR0
If TXB.4=1 Then GoSub SR1
If TXB.5=0 Then GoSub SR0
If TXB.5=1 Then GoSub SR1
If TXB.6=0 Then GoSub SR0
If TXB.6=1 Then GoSub SR1
If TXB.7=0 Then GoSub SR0
If TXB.7=1 Then GoSub SR1
Return
'=========================================================================================
' need revisit timing 4us step
'=========================================================================================
TX1H: BSR=1 ' bank1
TRISA.0=1 ' DQ = float-pullup
BSR=0 ' bank 0
TX1H1: If Wire = Hi Then GoTo TX1H1 '
TMR2=0 ' master strobed wire low Start Slot
Te: If Wire = Lo Then GoTo TeL ' '
TeH: If TMR2.4 = 0 Then GoTo TeH ' 2^4 = 16 *2 = 32us
Return ' wire Hi return after 32 us
TeL: If TMR2.5=0 Then GoTo Te ' 32*2us = 64us LIMIT slot to 64us
GoTo Wait_IP64 ' error trash return
'=========================================================================================
TX1L: If Wire = Hi Then GoTo TX1L End If ' wait master strobe wire low
PORTA.0=0 ' insure 0 bit
BSR=1 ' bank1
TRISA.0=0 ' DQ = output = 0 since PORTA.0=0
BSR=0 ' bank 0
TMR2=0 ' Clear TMR2 hold for 56us
Tb: If TMR2 < 44/2 Then GoTo Tb End If ' TMR2 < 24=48us 25*2=50us 30*2=60us
BSR=1 ' bank1
TRISA.0=1 ' DQ = float-pullup
BSR=0 ' bank 0
Tc: If Wire = Hi Then Return ' Ensure wire hi before return
If TMR2.5=0 Then GoTo Tc End If ' 1-2-4-8-16-32 *2=64
GoTo Wait_IP64 ' error trash return
'========================================================================================
' Copy Scratch Pad to Memory
' EEprom write delay is 10ms / char therfor causing OneWireViewer to miss copy complete
' routine termiates after authorization then copys to mem at 1st reset
'========================================================================================
Copy_SP: If E_S > $1F Then GoTo Wait_IP ' CURRENT error AA or PF flags are set
GoSub RX8 '
If WTA1 <> RXB Then GoTo Wait_IP ' TA1 mismatch --> exit
GoSub RX8 '