声明sfr地址时编译错误

时间:2020-08-29 17:06:46

标签: c embedded microcontroller keil 8051

我正在研究基于8051的MCU STC16C65A,我希望它通过P2.0发出PWM,我从其手册中复制并修改了此代码:

#include "8051.h"

    sfr AUXR = 0x8e;
                //Auxiliary register T0 interrupt service routine
void t0int() interrupt 1           //(location at 000BH)
{
}
void main()
{
    AUXR = 0x80;
                //timer0 work in 1T mode
    TMOD = 0x06;                  //set timer0 as counter mode2 (8-bit auto-reload)
    TL0 = TH0 = 0xff;               //fill with 0xff to count one time
    TR0 = 1;                        //timer0 start run
    ET0 = 1;                        //enable T0 interrupt
    EA = 1;                         //open global interrupt switch
    IF P2.0 = 0 THEN P2.0 = 1 ELSE P2.0 = 0;
    while (1);
}

但是当我使用MCU 8051 ide编译它时,出现语法错误,在sfr AUXR = 0x8e中忽略了声明;我认为所使用的库(8051.reg)是通用库,而不是他们在手册中建议使用的reg51.h(已过时),我不使用,因为这是最新的库错误消息 谁可以帮我?也许我必须为该指针选择其他地址? 预先感谢

1 个答案:

答案 0 :(得分:0)

SDCC与Keil C51是不同的编译器,您必须期望C标准的扩展有所不同。 SFR的声明是扩展。

请使用已记录的语法:

__sfr __at(0x8e) AUXR;
相关问题