We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am pretty new to this stuff, but I am usually able to work out problems on my own. I am trying to interface to some humidity sensor that uses it's own proprietary 2-wire serial interface (clock line and a data line). To make things easier, I declared sbits for each pin (SCK and DATA). When I try to compile and execute code like this: . . DATA = 1; SCK = 1; error = DATA; SCK = 0; . . the compiler omits the line "SCK = 1". This is just an example, and it happens sporadically throughout the code. I read on some other posts that sbits are automatically volatile, and similar rumors, but the compiler is optimizing necessary lines out anyway. My compiler version is 6.20a. Thanks
When I compiled your example, I got the following:
ASSEMBLY LISTING OF GENERATED OBJECT CODE ; FUNCTION L?0006 (BEGIN) 0000 C2C8 CLR SCK 0002 120000 R LCALL Hold 0005 D2C8 SETB SCK ; The above executes ; SCK = 0; ; Hold (); ; SCK = 1; ; and then falls into the Hold routine ; FUNCTION Hold (BEGIN) ; SOURCE LINE # 9 ; SOURCE LINE # 10 ; SOURCE LINE # 12 ;---- Variable 'i' assigned to Register 'R7' ---- 0007 7FFF MOV R7,#0FFH 0009 ?C0001: 0009 DFFE DJNZ R7,?C0001 ; SOURCE LINE # 13 000B ?C0004: 000B 22 RET ; FUNCTION Hold (END) ; FUNCTION StartTX (BEGIN) ; SOURCE LINE # 15 ; SOURCE LINE # 16 ; SOURCE LINE # 17 ;---- Variable 'SFRPAGE_SAVE' assigned to Register 'R6' ---- char SFRPAGE_SAVE = SFRPAGE; 0000 AE84 MOV R6,SFRPAGE ; SOURCE LINE # 18 SFRPAGE = CONFIG_PAGE; 0002 75840F MOV SFRPAGE,#0FH ; SOURCE LINE # 19 DATA = 1; 0005 D2C9 SETB DATA ; SOURCE LINE # 20 ; SOURCE LINE # 21 ; SOURCE LINE # 22 ; SOURCE LINE # 23 SCK = 0; Hold (); SCK = 1; Hold (); 0007 120000 R LCALL L?0006 ; SOURCE LINE # 24 DATA = 0; 000A C2C9 CLR DATA ; SOURCE LINE # 25 Hold (); 000C 120000 R LCALL Hold ; SOURCE LINE # 26 ; SOURCE LINE # 27 ; SOURCE LINE # 28 ; SOURCE LINE # 29 SCK = 0; Hold (); SCK = 1; Hold (); 000F 120000 R LCALL L?0006 ; SOURCE LINE # 30 DATA = 1; 0012 D2C9 SETB DATA ; SOURCE LINE # 31 Hold (); 0014 120000 R LCALL Hold ; SOURCE LINE # 32 SCK = 0; 0017 C2C8 CLR SCK ; SOURCE LINE # 33 SFRPAGE = SFRPAGE_SAVE; 0019 8E84 MOV SFRPAGE,R6 ; SOURCE LINE # 34 001B 22 RET ; FUNCTION StartTX (END)