Keil Logo

C51: USING TIMED ACCESS REGISTERS ON DALLAS PARTS


Information in this article applies to:

  • C51 Version 6.02

QUESTION

How do I use the Timed Access registers on the Dallas Semiconductor parts? I can't seem to get the compiler to generate code that sets or clears the timed access registers fast enough. Is there a way to do this in C?

ANSWER

Yes. The following example shows how to reset the watchdog timer for the Dallas 320 using the C Programming Language.

sfr TA = 0xC7;
sfr WDCON = 0xD8;

sbit RWT = WDCON^0;

#pragma DISABLE     // disable ints for this function
void reset_watchdog (void)
{
TA = 0xAA;
TA = 0x55;
RWT = 1;       /*** Reset the Watchdog Timer ***/
}

This example generates the following code:

             ; FUNCTION reset_watchdog (BEGIN)
0000 D3                SETB    C
0001 10AF01            JBC     EA,?C0003
0004 C3                CLR     C
0005         ?C0003:
0005 C0D0              PUSH    PSW
                                           ; SOURCE LINE # 8
                                           ; SOURCE LINE # 9
                                           ; SOURCE LINE # 10
0007 75C7AA            MOV     TA,#0AAH
                                           ; SOURCE LINE # 11
000A 75C755            MOV     TA,#055H
                                           ; SOURCE LINE # 12
000D D2D8              SETB    RWT
                                           ; SOURCE LINE # 13
000F D0D0              POP     PSW
0011 92AF              MOV     EA,C
0013 22                RET
             ; FUNCTION reset_watchdog (END)

As you can see from this listing, the TA register is set to 0xAA and then to 0x55 and the next instruction writes to the RWT bit.

The C51 C Compiler is an optimizing compiler. Some optimization levels may cause problems with timed access registers like those supported by the Dallas Semiconductor parts. It is a good idea to create a function for each type of timed access and manually set the optimizer level for that routine. For example:

sfr TA = 0xC7;
sfr WDCON = 0xD8;

sbit RWT = WDCON^0;

#pragma SAVE        // save current optimization level
#pragma OPTIMIZE(8) // prevent common subroutine optimization
#pragma DISABLE     // disable ints for this function

void reset_watchdog (void)
{
TA = 0xAA;
TA = 0x55;
RWT = 1;       /*** Reset the Watchdog Timer ***/
}

#pragma RESTORE    // restore previous optimization level

MORE INFORMATION

  • Refer to OPTIMIZE in the Cx51 User's Guide.
  • Refer to SAVE in the Cx51 User's Guide.
  • Refer to RESTORE in the Cx51 User's Guide.

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Tuesday, October 24, 2006


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.