This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Write R7 register directly from C

I use KeilC uVision4 for 89C51 MCU.
By "Inline ASM", i can easily direct write value to R7 register, like this :

    #pragma ASM
        MOV R7, #10
    #pragma ENDASM


But now, there are some reason that i have to write to R7 register direct from C (not from inline ASM), eg:

    R7 = 10;


Of course, the C compiler does not understand R7 as MCU Register (not Inline ASM).

-> Is there anyway to solve this problem. Please help me if anyone know, thanks a lot !

Parents
  • Maybe you understand my idea incorrectly. I've used MikroC for 8051. That compiler has a built-in Delay_ms() routines. When I want to delay 10ms, just code

    Delay_ms(10);
    

    The compiler will auto generate source code (to delay 10ms) :

    _Delay_10ms :
        MOV R5, #8
        MOV R6, #1
        MOV R7, #247
        DJNZ R7, PC-2
        DJNZ R6, PC-4
        DJNZ R5, PC-6
        RET
    


    Then, I wonder if I can write a Macro like that in KeilC. Just code "Delay_ms(x);" with x is any number you want. Anything wrong in my idea ?

Reply
  • Maybe you understand my idea incorrectly. I've used MikroC for 8051. That compiler has a built-in Delay_ms() routines. When I want to delay 10ms, just code

    Delay_ms(10);
    

    The compiler will auto generate source code (to delay 10ms) :

    _Delay_10ms :
        MOV R5, #8
        MOV R6, #1
        MOV R7, #247
        DJNZ R7, PC-2
        DJNZ R6, PC-4
        DJNZ R5, PC-6
        RET
    


    Then, I wonder if I can write a Macro like that in KeilC. Just code "Delay_ms(x);" with x is any number you want. Anything wrong in my idea ?

Children