Hi, I'm trying to access SFR memory using the hexa address of the SFR and using only "C" instructions. Since SFR memory is accessed by direct addressing mode, like the first 128 bytes of internal RAM, I tried to use the following instruction :
* ((unsigned char data *) 0xA8) = 0x1;
MOV R0,#0A8H MOV @R0,#01H
* ((unsigned char idata *) 0xA8) = 0x1;
Cf Keil C51 Compiler book p68 : "The 8051 family of microprocessors provides you with a distinct memory area for accessing SFRs. [...] SFRs reside from address 0x80 to 0xFF and can be accessed as bits, bytes and words. Yes, and you use sbit, sfr, sfr16 to access them. Assembler allows you to do anything so I'll ignore that here. So if I want to init a SFR register (which is unknown at compile time), how can I do ? You mean on a new 8051 that Keil doesn't explicitly support? Look in the databook for the part, find the DATA address of the sfr, and sfr the thing.
sfr myNewSfr = 0xE8; if (myNewSfr & SOME_BIT) ...
Yes, and you use sbit, sfr, sfr16 to access them. Assembler allows you to do anything so I'll ignore that here. When you do it in Assembler, you choose the appropriate Addressing Mode and/or mnemonic yourself; it's the sbit, sfr, sfr16 which tell the compiler that you're accessing an SFR and therefore what Addressing Mode and/or mnemonic to use.
How did what I said contradict what you said? I said, "Assembler allows you to do anything so I'll ignore that here." The OP is asking about how to do this in C but quoted irrelvant text about assembler. - Mark
How did what I said contradict what you said? No contradiction! Just adding some detail (which, as you say, was not essential to main 'C' discussion). "Reply" doesn't necessarily imply "Disagree" - sorry if it sounded that way.
"Reply" doesn't necessarily imply "Disagree" - sorry if it sounded that way. My fault. I was being overly sensitive. Please ignore me. Regards. - Mark