From: Oberholtzer,Stephen <ste...@fr...> - 2006-04-25 18:58:54
|
Most PICs have a 16-bit timer (named Timer1). The PIC18-series enhances Timer1 (and its other 16-bit timers) to offer the choice of a consistent read of the 16-bit value (lessening the pain of accurately reading a 16-bit volatile value 8 bits at a time): a bit in the timer's control register enables a latched read of the high-byte when the low-byte is read by the CPU, so that you can do this: movwf TMR1L ; when setup properly, at the same moment TMR1L is read, a copy of TMR1H is latched into a buffer ; do stuff movwf TMR1H ; reads the value that was latched into the buffer when TMR1L was read ; do more stuff It seems to me that constructing a 16-bit variable from two 8-bit registers should be fairly simple, considering that the 16-bit variable is, itself, two 8-bit memory locations. So I'm kinda surprised to see this code generated when I tried this: sdcc -mpic16 -p18f452 -c makeword.c ; .line 11; makeword.c _tmr1 =3D (TMR1L)|(TMR1H<<8); MOVFF _TMR1H, r0x00 CLRF r0x01 MOVF r0x00, W MOVWF r0x03 CLRF r0x02 MOVFF _TMR1L, r0x00 CLRF r0x01 MOVF r0x02, W IORWF r0x00, W BANKSEL __tmr1 MOVWF __tmr1, B MOVF r0x03, W IORWF r0x01, W BANKSEL (__tmr1 + 1) MOVWF (__tmr1 + 1), B I noticed that SDCC pays no mind to the order of the statement: (TMR1L)|(TMR1H<<8) and (TMR1H<<8)|(TMR1L); both yield identical code. I don't know what the C standard has to say about this, wrt. volatiles, but I'm sure it's OK. (incidentally, can someone point me to a copy of the C99 standard?) In any case, I would expect something more like this: movff _TMR1L, (__tmr1) movff _TMR1H, (__tmr1 + 1) Obviously I'm going about this the wrong way. What would be the proper way to tell SDCC what I want it to do? This E-Mail is intended only for the use of the individual or entity to = which it is addressed, and may contain information that is privileged, = confidential and exempt from disclosure under applicable law. If you = have received this communication in error, please do not distribute it = and notify us immediately by telephone: 610-902-9000 and delete the = original message. |