how can an sbit variable be assigned an address which is intrinsically assigned to something else. e.g will the following code work on an 8051?
sfr SCON = 0x98; // declare SCON sbit SM0 = 0x9F; // declare sbit members of SCON sbit SM1 = 0x9E; sbit SM2 = 0x9D; sbit REN = 0x9C; sbit TB8 = 0x9B; sbit RB8 = 0x9A; sbit TI = 0x99; sbit RI = 0x98;
Address 0x9A is the address for a special function register. IEN2. Won't the RB8 and this SFR conflict? I'm especially interested in how the compiler interprets the "sbit" keyword.
Thanks in advance
Byte and bit addresses are two separate address spaces, even if they can access the same data.
The processor is using one set of instructions to access sbit variables, and a different set of instructions to access byte variables. That is the reason why an sbit can have the same numeric value for the address as the data byte has.
You can also have a byte in code space that has the same address value - code is yet another address space. Do read up on the different address ranges in the 8051 processor, and the different assembler instructions used when accessing the different address spaces.
The basic document that you require is the so-called "bible" for the 8051 - the links are here: www.8052.com/.../120112
See also: http://www.8052.com/tutorial
And: http://www.keil.com/books/8051books.asp
here are the links to "the bible" Chapter 1 - 80C51 Family Architecture: www.nxp.com/.../80C51_FAM_ARCH_1.pdf Chapter 2 - 80C51 Family Programmer's Guide and Instruction Set: www.nxp.com/.../80C51_FAM_PROG_GUIDE_1.pdf Chapter 3 - 80C51 Family Hardware Description: www.nxp.com/.../80C51_FAM_HARDWARE_1.pdf
Thanks, I think I understand what an sbit variable really is now.
I have also run into another problem. I tried setting Timer1 to free run mode and unmasking the overflow interrupt as a means of generating a pulse train output on one of the MCU pins. The trouble is that, while I can poll and detect changes to the overflow flag T1CTL.OVFIF, the interrupt function doesn't execute. Below is the very simple code I was trying to test interrupts with.
#include "CC2430.h" // for register declaration void main(void){ P1SEL = 0x00; // Sets PORT 1 pins to GPIO P1DIR = 0xFF; // Set as outputs P1_3=1; //indicates the system's on T1CNTL = 0x00; //reset the counter to zero T1CTL = 0x0D; //free running mode OVFIM = 1; // Unmask overflow //interrupt T1IE = 1; // enable Timer1 interrupt IEN0 = 0x80; // enable all interrupts } void ISR (void) interrupt 9 { // timer one interrupt func P1=0xFF; // turn on the LEDs connected to Port1 }
If it's a different problem, you should start a new thread for it - not least because the title "How The sbit keyword works" is no longer relevant to the content!
You can always include a link(s) to other thread(s) if you think they are helpful...
And before you start a new thread - make sure that your main has an infinite loop so that it doesn't end - there is no operating system to catch you.