当前位置:首页 > 单片机 > 单片机
[导读]SFR定义: sfr P5 = 0x85; /* PORT 5 */ 位寻址定义: sbit st_rs = P5^0; 编译错误: *** ERROR C146 IN LINE 320 OF C8051F020.H: 'P5' invalid base address KEIL FAQ:( http://www.keil.c

SFR定义:
sfr P5 = 0x85; /* PORT 5 */

位寻址定义:
sbit st_rs = P5^0;

编译错误:
*** ERROR C146 IN LINE 320 OF C8051F020.H: 'P5' invalid base address

KEIL FAQ:( http://www.keil.com/support/docs/1916.htm )

*QUESTION :

When I compile my program, I receive the following error message:

Error 146: Invalid Base Address

How do I fix this?

*ANSWER :

This error message indicates that the byte base address specified for an SBIT is not valid. The byte address of an SBIT must be an SFR whose least

significant nibble must be 0 or 8. For example:

sfr P1 = 0x90;
sbit P1_0 = P1^0; // This is valid

sfr P4 = 0xD1;
sbit P4_0 = P4^0; // This is NOT valid since P4 is not an a 0 or 8 boundary

For SFR addresses that are not bit-addressable, you might use standard AND and OR operations to access the indivitual SFR bits.

Example:

sfr P4 = 0xD1;

void test (void) {
if (P4 & 0x01) { // if bit 0 set
P4 |= 0x80; // set bit 7
}
else {
P4 &= ~0x02; // reset bit 1
}
}

原因:
( http://www.keil.com/forum/docs/thread7997.asp )
Non-8 divisible port addresses are not bit assignable. What genious decided that would be a good idea?

Goes all the way back to the original 8051 architecture decisions at Intel.

Bit instructions take one byte of address. Notice that there are 0x10 bytes of bit-addressable memory. The other addressable bits are in SFRs. You can

practically see the hardware guys tapping off the high bit in their address decoder. 0 -> RAM, 1 -> SFR.

Then, you have to decode the next 7 bits to an actual SFR. It's very simple to take bits 6:3 as the SFR address, and use bits 2:0 to select the

individual bit from that byte. That means the bits appear in every eighth SFR address, which is to say the addresses ending in 0 or 8.

Really simple circuit, even at the expense of strangeness at the software level. That's classic Intel design philosophy for you. Save gates where you can

and let the programmers deal with it.

解读:
在SFR空间地址只有可被8整除的寄存器才可以进行位寻址。
位寻址指令代码使用一个字节表示,bit7= 1:片内RAM,0:SFR,bit6~bit3= SFR寄存器地址,bit2~bit0=寄存器内的位地址。
SFR空间内只有16个寄存器是可以位寻址的,其它寄存器的位操作只能用(与)、(或)来操作。

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

采用8051作为核心元件,构成变速调温控制系统,适应特殊的温度曲线,而且采用不同的软件系统,可以适应不同的工艺要求,具有良好的可移植性和扩展性。本文给出了系统硬件和软件的总体设计。

关键字: 8051 变速调温系统 核心元件

CC2530 结合了领先的RF 收发器的优良性能,业界标准的增强型8051 CPU,系统内可编程闪存,8-KB RAM 和许多其它强大的功能。

关键字: cc2530 PWM 8051

  2014年6月11日讯——恩智浦半导体(NXP Semiconductors N.V.)(纳斯达克代码:NXPI)今天宣布推出全新的单级驱动器数字IC系列,用于紧凑型

关键字: 8051 MCU 智能硬件

用8051控制报警产生实例

关键字: 8051 报警

单片机位寻址和不可位寻址

关键字: 不可位寻址 位寻址

MCS- 51系列单片机的指令系统是一种简明高效的指令系统,其基本指令共有111条,其中单字节指令49条,双字节指令4\'5条,三字节指令17条。如果按功能可以讲这些指令分为五类:数据传送类(29条)、算术操作类(24条...

关键字: 8051 单片机 指令系统

复位就是指通过某种手段使单片机内部某些资源一种固定的初始状态,以确保单片机每次复位后都能在某一固定的环境中从某一固定的入口地址处开始运行

关键字: 8051 单片机 复位状态

单片机CPU与外部设备交换信息通常有如下几种方式:无条件传送方式,查询传送方式和中断传送方式。我们以单片机与微型打印机接口为例讲述这三种方式。假定用户要打印三个数据,这三个数据保存在单片机的内部数据存储器10H,11H,...

关键字: 8051 单片机 数据传输方式

8051系列各种芯片的引脚是互相兼容的,8051,8751和8031均采用40脚双列直播封装型式。当然,不同芯片之间引脚功能也略有差异。8051单片机是高性能的单片机,因为受到引脚数目的限制,所以有不少引脚具有第二功能,...

关键字: 8051 单片机 引脚功能

P1口也是一个准双向口,作通用I/O使用。

关键字: 8051 p1口 单片机 端口结构
关闭