Why do I receive syntax errors in Simplicity Studio when defining an interrupt? The code compiles and works correctly, but declaring an interrupt, such as this one, gives a syntax error in Studio:
This occurs since Simplicity Studio uses a generic C syntax parser when looking for syntax errors in code. It doesn't understand compiler-specific C code, like that used by Keil C51 to define an interrupt function - the 'interrupt' keyword and interrupt number after the function declaration aren't standard C, so it throws a syntax error. Keil, however, when the project is compiled, understands this syntax and compiles the code correctly.
We have a work-around for this visual error by the way of macros in si_toolchain.h. If you use the SI_INTERRUPT(name, vector) macro, it will generate different declarations based on which tool is viewing the code. If __SLS_IDE__ is defined (that is, if the Simplicity Studio parser is looking at the code, it omits the interrupt vector number from the actual declaration. If Keil C51 is viewing the code, it places the vector number in the correct location for Keil to compile it correctly.
For example, if we used the following:
SI_INTERRUPT(INT1_ISR, 2)
In the IDE, this would generate:
void INT1_ISR (void)
But, for C51, this would generate:
void INT1_ISR (void) interrupt 2
This would eliminate the syntax error, but still allow Keil to compile the interrupt correctly.
8-bit Knowledge Base
Syntax error in Simplicity Studio when declaring interrupts?
Question:
Why do I receive syntax errors in Simplicity Studio when defining an interrupt? The code compiles and works correctly, but declaring an interrupt, such as this one, gives a syntax error in Studio:
Answer:
This occurs since Simplicity Studio uses a generic C syntax parser when looking for syntax errors in code. It doesn't understand compiler-specific C code, like that used by Keil C51 to define an interrupt function - the 'interrupt' keyword and interrupt number after the function declaration aren't standard C, so it throws a syntax error. Keil, however, when the project is compiled, understands this syntax and compiles the code correctly.
We have a work-around for this visual error by the way of macros in si_toolchain.h. If you use the SI_INTERRUPT(name, vector) macro, it will generate different declarations based on which tool is viewing the code. If __SLS_IDE__ is defined (that is, if the Simplicity Studio parser is looking at the code, it omits the interrupt vector number from the actual declaration. If Keil C51 is viewing the code, it places the vector number in the correct location for Keil to compile it correctly.
For example, if we used the following:
In the IDE, this would generate:
But, for C51, this would generate:
This would eliminate the syntax error, but still allow Keil to compile the interrupt correctly.
在BL51或LX51中使用常量来设定flash lock字节值
问题
是否可以在编译代码时指定8051 MCU lock 字节的值 ?
答案
可以,在使用Keil C51工具链时,可以很容易的通过BL51或LX51来实现
首先,需要在代码中的某个位置初始化lock 字节的设定。譬如,可以创建一个新的文件,并命名为”lockbyte.c”,然后在其中加入如下的代码,
这段代码将会在flash中占用一个byte,且其初始值为0,但此时并未指定其具体地址。为了将这个字节放置在flash的lock字节位置,需要使用到链接器。
关于lock字节的地址,请查阅相应MCU的参考手册。例如EFM8BB1F8的lock 字节在flash的0x1FFF位置。
如果使用Simplicity Studio,链接器的指令可以在如下位置修改,Project -> Properties -> C/C++ Build -> Settings-> Keil 8051 Linker > Miscellaneous。然后在[Additional Flags]中添加链接器指令。
如果使用LX51,请在[Additional Flags]中添加如下命令:
如果使用LX51,同时该MCU有code banking, 则需要指定code bank以及地址。例如,使用如下命令将LOCKBYTE放置在bank3 0x1FFFF位置。
如果REMOVEUNUNUSED有被使能,那么需要使用OVERLAY命令以保证其不会处理该lock字节,否则链接器会将LOCKBYTE从代码段移除掉。REMOVEUNUNUSED设定在如下位置:
如果使用BL51,相应的命令如下
编译完成之后,查看.m51文件或.hex文件,即可以确定是否有将常量放置在指定的lock字节(0x1FFF)位置,同时其初始值是否正确。
此外还有一种比较简单直接的方法就是手动修改HEX文件,在HEX文件结束符之前加入一行用来锁定Flash
以C8051F02x MCU为例,其lock byte在0xFDFE和0xFDFF,手动修改HEX文件如下:
...
...User code...
...
:02FDFE00000003
:00000001FF
其中
02 表示包含2个字节数据
FDFE 表示起始地址
00 表示记录类型(普通数据)
0000 待写入的值
03 校验和
00000001FF 文件结束符
为什么我在Simplicity Studio中编译项目的时候总提示Keil C51编译器没有注册?
如何为一台无法上网的机器注册 Keil C51 编译器?
Keil C51注册的关键信息是CID:Computer ID和PSN: Product Serial。这两个信息每台电脑都不一样,所以不能简单的将一个电脑的注册信息复制到另外一台。
如果一个电脑无法上网,我们可以获取它的PSN/CID然后到另外一台可以上网的电脑进行注册。CID的获取方式可以采用如下方式之一:
1. 如果有安装了Keil uVision,则在注册页面可以看到。详情参看AN104
http://www.silabs.com/Support%20Documents/TechnicalDocs/an104.pdf
2. 如果是安装了Studio,那么可以在Studio中启动注册页面,在URL中看到注册信息。选择 Help->Licensing Helper,然后点击"this form"启动注册页面。
然后在浏览器的地址栏即可看到PSN和CID,可以直接将地址栏中地址输入到另外一台电脑注册,也可以在 https://www.keil.com/license/install.htm 输入PSN和CID注册。
使用 LFO时 EFM8BB1 高待机电流
如何创建和链接一个静态库文件
输出由Keil PK51编译的工程的内存使用情况总结
如何在Simplicity IDE中创建汇编工程
在 Simplicity Studio 中用 Keil C51 产生内联汇编代码
如何把Silicon Labs IDE的8位工程导入Simplicity Studio?