在Intel 8051上组合SDCC和ASM代码编译的问题

时间:2011-02-15 17:42:20

标签: assembly 8051 sdcc

我们正在尝试编译我们的C代码,其中包括大量用于各种操作的组件(时序,产生输出波形和测量输入频率)。

我们在一些ASM操作中遇到同样的错误:

“。在REL区域中的组织或指令/助记错误”

在下面的代码中,我们得到3个错误(我评论了它们发生了哪些行,以及我们得到的错误究竟是什么。谢谢!

void getFrequency(int *freqHi, int *freqLo) 
{
    __asm
    ;
    ; A program that measures the frequency at pin T0 (P1.2)

    ljmp GetFreq

    Wait1s:
        mov R2, #40
    M3: mov R1, #250
    M2: mov R0, #181
    M1: djnz R0, M1 ; 2 machine cycles-> 2*0.27126us*181=100us
        djnz R1, M2 ; 100us*250=0.025s
        djnz R2, M3 ; 0.025s*40=1s
        ret

    ;Initializes timer/counter 0 as a 16-bit counter
    InitTimer0:
        setb T0 ; Enable pin T0 as input
        clr TR0 ; Stop timer 0
        mov a,#0F0H ; ERROR <o> .org in REL area or directive / mnemonic error
        anl a,TMOD
        orl a,#00000101B ; Set timer 0 as 16-bit counter ERROR <o> .org in REL area or directive / mnemonic error
        mov TMOD,a
        ret

    GetFreq:
        mov SP, #7FH ; Set the stack pointer to the begining of idata ERROR <o> .org in REL area or directive / mnemonic error

        lcall InitTimer0

        clr TR0 ; Stop counter 0
        mov TL0, #0
        mov TH0, #0

        setb TR0 ; Start counting
        lcall Wait1s ; Wait one second
        clr TR0 ; Stop counter 0, TH0-TL0 has the frequency

        mov R0, TH0
        mov R1, TL0

        mov _freqHi, R0
        mov _freqLo, R1

    __endasm;

    // freqHi, freqLo have respective values
}

1 个答案:

答案 0 :(得分:2)

sdcc的汇编程序不支持您正在使用的直接值的HB后缀语法。

尝试#0xF0代替#0F0H#0b00000101代替#00000101B等。

相关问题