In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Peter Van der Zee wrote: Hi PJ; Here's the interpretation: ASM MOV FSR,#__TRISC ;point to the (shadow) memory location that holds the direction register for port C... located in bank F on an SX28 MODE $0F ;set the MODE to accept changes to the SX direction reggisters SETB IND.7 ;prep bit 7 of the shadow register to input direction MOV !RC,IND ;now transfer the shadow to the actual direction register inside the SX BANK $00 ;return to the default bank JNB RC.7,@$ ;loop here, continually testing the serial line for a a low, indicating no transmitter is connected JB RC.7,@$ ;loop here continually testing for a high, indicating a transmitter is connected, and in the serial STOP condition MOV __PARAM2,#8 ;a low now indicates a falling start bit edge has been detected, set the bit counter to 8 bits MOV __PARAM3,#2 ;now load the some parameters to do some time loops (duration depending on baud rates) MOV __PARAM4,#76 ; to sample the second bit (first data bit after the START bit) at its mid point..... one and one half bit lengths DJNZ __PARAM4,@$ ;and do the timing here DJNZ __PARAM3,@$-3 ; with two nested loops.... outer loop is 2 times the inner loop of 76, each of 5 instruction cycles (jump instruction itself is 3 cycles plus the @ page insruction plus the dec-skip-if zero) NOP ;some fine tuning of the timing NOP ;to get the sampling interval just right MOV __PARAM3,#3 ;now load the parameters for timing duration to sample all following bits in their middle; relative to the middle of the first data bit ...... one bit length MOV __PARAM4,#151 ;outer loop is 3 times the inner loop of 151 loops of 5 instruction cycles each DJNZ __PARAM4,@$ ;and execute the delay here with DJNZ __PARAM3,@$-3 ; again two nested loops JMP @$+2 ;this is a little weird but is just a 4 instruction time delay... effectively not really a jump in program sequence RR __PARAM1 ;move the shifter along one bit and make room for the new bit coming in MOVB __PARAM1.7,RC.7 ;merge the sampled bit into position 7 of the shifter.... the previous value is overwitten DJNZ __PARAM2,@$-17 ;decrement the bit counter, and if it is not zero (indicating it has done 8 bits) jump back 17 to load up the second set of delay loops again to sample in the middle of the next bit MOV outbyte,__PARAM1 ;copy the received result to the destination variable ENDASM PJ... the $ indicates the present value of the program counter, and the $+ or $- values are relative to that point. The $-17 you referred to is actually 17 instructions... that is program LOCATIONS. The assembled code DJNZ are compound instructions consuming 2 bytes each, and then there is the @ page instruction on top of that. So, no, it does not point back to the BANK which is 17 LINES back, but instead it points 17 SINGLE INSTRUCTIONS back to the load of the timing parameters. Hope that helps. Cheers, Peter (pjv) ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=283153#m283798 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)