ARM Technical Support Knowledge Articles

USING TIMED ACCESS REGISTERS ON DALLAS PARTS

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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

SEE ALSO

Article last edited on: 2006-10-24 12:51:58

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential