We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello ALL I need to access some of the bit positions of the SFR. But each time i tried to declare a variable of the type sbit , i get error C141: syntax error near sbit. I have read the manual and i even tried the statement :
sbit EA = 0xAF
Take a look at the example CPU header files for your variant. This likely has already been done for you, and certainly has for standard 8051 SFRs.
sfr IE = 0xA8; /* IE */ sbit EA = 0xAF; sbit ES = 0xAC; sbit ET1 = 0xAB; sbit EX1 = 0xAA; sbit ET0 = 0xA9; sbit EX0 = 0xA8;
Thanks Davis! I think the problem was that I placed the declaration within the main program scope. When i placed the statement
sbit EA = 0xAF; </>just after function prototypes, the error cease to exist. Hoever, if you have Sfr (MMCON0 , 0xE4); Sfr (MMCON1 , 0xE5); Sfr (MMCON2 , 0xE6); in the header file, and for example, you need to access the second bit of MMCON1, would something like this sbit RESPEN = 0xE5 + 1; works? Please, take note of the address of MMCON2. Thanks
Sfr (MMCON0 , 0xE4); Sfr (MMCON1 , 0xE5); Sfr (MMCON2 , 0xE6);
sbit RESPEN = 0xE5 + 1;
sbit EA = 0xAF;
You are obviously not familiar with the '51'. Trying to program this chip as "any chip" is the sure road to disaster. Before writing one more line of code read "the bible" Please, take note of the address of MMCON2. here are the links to "the bible" Chapter 1 http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_ARCH_1.pdf chapter 2 http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_PROG_GUIDE_1.pdf chapter 3 http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_HARDWARE_1.pdf Erik
Thanks Erik, I appreciate it. I will read the Bible as suggested. Amos
Only SFRs with addresses that end in 0 or 8 are bit-addressable. Note that there are eight bits in a byte, and the bit addresses for SFR X0 range from X + 0 to X + 7, whereupon you reach SFR X8 with bits X8 + 0 to X8 + 7. There's method in the madness. For registers that are not bit addressable, you can set bits the good old fashioned way, with AND and OR operations. AND / OR also works on the SFRs with addressable bits.