You are on page 1of 6

What Are SFRs?

The 8051 is a flexible microcontroller with a relatively large number of modes of operations. Your program may inspect and/or change the operating mode of the 8051 by manipulating the values of the 8051 s !pecial "unction #egisters $!"#s%. !"#s are accessed as if they were normal &nternal #'(. The only difference is that &nternal #'( is from address 00h through )"h whereas !"# registers exist in the address range of 80h through ""h. *ach !"# has an address $80h through ""h% and a name. The following chart provides a graphical presentation of the 8051 s !"#s+ their names+ and their address.

's you can see+ although the address range of 80h through ""h offer 1,8 possible addresses+ there are only ,1 !"#s in a standard 8051. 'll other addresses in the !"# range $80h through ""h% are considered invalid. -riting to or reading from these registers may produce undefined values or behavior. Programming Tip: &t is recommended that you not read or write to !"# addresses that have not been assigned to an !"#. .oing so may provo/e undefined behavior and may cause your program to be incompatible with other 80510derivatives that use the given !"# for some other purpose.

SFR Types

's mentioned in the chart itself+ the !"#s that have a blue bac/ground are !"#s related to the &/1 ports. The 8051 has four &/1 ports of 8 bits+ for a total of 2, &/1 lines. -hether a given &/1 line is high or low and the value read from the line are controlled by the !"#s in green. The !"#s with yellow bac/grouns are !"#s which in some way control the operation or the configuration of some aspect of the 8051. "or example+ TCON controls the timers+ !314 controls the serial port. The remaining !"#s+ with green bac/grounds+ are 5other !"#s.5 These !"#s can be thought of as auxillary !"#s in the sense that they don t directly configure the 8051 but obviously the 8051 cannot operate without them. "or example+ once the serial port has been configured using SCON+ the program may read or write to the serial port using the SBUF register. 6rogramming Tip7 The !"#s whose names appear in red in the chart above are !"#s that may be accessed via bit operations $i.e.+ using the SETB and CLR instructions%. The other !"#s cannot be accessed using bit operations. 's you can see+ all !"#s that whose addresses are divisible by 8 can be accessed with bit operations.

SFR Des riptions


This section will endeavor to 8uic/ly overview each of the standard !"#s found in the above !"# chart map. &t is not the intention of this section to fully explain the functionality of each !"#00this information will be covered in separate chapters of the tutorial. This section is to 9ust give you a general idea of what each !"# does. P! "Port !# A$$ress %!h# Bit&A$$ressa'(e): This is input/output port 0. *ach bit of this !"# corresponds to one of the pins on the microcontroller. "or example+ bit 0 of port 0 is pin 60.0+ bit ) is pin 60.). -riting a value of 1 to a bit of this !"# will send a high level on the corresponding &/1 pin whereas a value of 0 will bring it to a low level. Programming Tip: -hile the 8051 has four &/1 port $60+ 61+ 6,+ and 62%+ if your hardware uses external #'( or external code memory $i.e.+ your program is stored in an external #1( or *6#1( chip or if you are using external #'( chips% you may not use 60 or 6,. This is because the 8051 uses ports 60 and 6, to address the external memory. Thus if you are using external #'( or code memory you may only use ports 61 and 62 for your own use. SP "Sta * Pointer# A$$ress %+h): This is the stac/ pointer of the microcontroller. This !"# indicates where the next value to be ta/en from the stac/ will be read from in &nternal #'(. &f you push a value onto the stac/+ the value will be written to the address of !6 : 1. That is to say+ if !6 holds the value 0)h+ a 6;!< instruction will push the value onto the stac/ at address 08h. This !"# is modified by all instructions which modify the stac/+ such as 6;!<+ 616+ =3'==+ #*T+ #*T&+ and whenever interrupts are provo/ed by the microcontroller.

Programming Tip: The !6 !"#+ on startup+ is initiali>ed to 0)h. This means the stac/ will start at 08h and start expanding upward in internal #'(. !ince alternate register ban/s 1+ ,+ and 2 as well as the user bit variables occupy internal #'( from addresses 08h through ,"h+ it is necessary to initiali>e !6 in your program to some other value if you will be using the alternate register ban/s and/or bit memory. &t s not a bad idea to initiali>e !6 to ,"h as the first instruction of every one of your programs unless you are 100? sure you will not be using the register ban/s and bit variables. DPL,DP- "Data Pointer Lo.,-igh# A$$resses %/h,%0h): The !"#s .6= and .6< wor/ together to represent a 1@0bit value called the Data Pointer. The data pointer is used in operations regarding external #'( and some instructions involving code memory. !ince it is an unsigned two0byte integer value+ it can represent values from 0000h to """"h $0 through @5+525 decimal%. Programming Tip: .6T# is really .6< and .6= ta/en together as a 1@0bit value. &n reality+ you almost always have to deal with .6T# one byte at a time. "or example+ to push .6T# onto the stac/ you must first push .6= and then .6<. You can t simply plush .6T# onto the stac/. 'dditionally+ there is an instruction to 5increment .6T#.5 -hen you execute this instruction+ the two bytes are operated upon as a 1@0bit value. <owever+ there is no instruction that decrements .6T#. &f you wish to decrement the value of .6T#+ you must write your own code to do so. PCON "Po.er Contro(# A$$resses %1h): The 6ower 3ontrol !"# is used to control the 8051 s power control modes. 3ertain operation modes of the 8051 allow the 8051 to go into a type of 5sleep5 mode which re8uires much less power. These modes of operation are controlled through 6314. 'dditionally+ one of the bits in 6314 is used to double the effective baud rate of the 8051 s serial port. TCON "Timer Contro(# A$$resses %%h# Bit&A$$ressa'(e): The Timer 3ontrol !"# is used to configure and modify the way in which the 8051 s two timers operate. This !"# controls whether each of the two timers is running or stopped and contains a flag to indicate that each timer has overflowed. 'dditionally+ some non0timer related bits are located in the T314 !"#. These bits are used to configure the way in which the external interrupts are activated and also contain the external interrupt flags which are set when an external interrupt has occured. T2OD "Timer 2o$e# A$$resses %3h): The Timer (ode !"# is used to configure the mode of operation of each of the two timers. ;sing this !"# your program may configure each timer to be a 1@0bit timer+ an 80bit autoreload timer+ a 120bit timer+ or two separate timers. 'dditionally+ you may configure the timers to only count when an external pin is activated or to count 5events5 that are indicated on an external pin. TL!,T-! "Timer ! Lo.,-igh# A$$resses %Ah,%Ch): These two !"#s+ ta/en together+ represent timer 0. Their exact behavior depends on how the timer is configured in the T(1. !"#A however+ these timers always count up. -hat is configurable is how and when they increment in value.

TL+,T-+ "Timer + Lo.,-igh# A$$resses %Bh,%Dh): These two !"#s+ ta/en together+ represent timer 1. Their exact behavior depends on how the timer is configured in the T(1. !"#A however+ these timers always count up. -hat is configurable is how and when they increment in value. P+ "Port +# A$$ress 3!h# Bit&A$$ressa'(e): This is input/output port 1. *ach bit of this !"# corresponds to one of the pins on the microcontroller. "or example+ bit 0 of port 1 is pin 61.0+ bit ) is pin 61.). -riting a value of 1 to a bit of this !"# will send a high level on the corresponding &/1 pin whereas a value of 0 will bring it to a low level. SCON "Seria( Contro(# A$$resses 3%h# Bit&A$$ressa'(e): The !erial 3ontrol !"# is used to configure the behavior of the 8051 s on0board serial port. This !"# controls the baud rate of the serial port+ whether the serial port is activated to receive data+ and also contains flags that are set when a byte is successfully sent or received. Programming Tip: To use the 8051 s on0board serial port+ it is generally necessary to initiali>e the following !"#s7 !314+ T314+ and T(1.. This is because !314 controls the serial port. <owever+ in most cases the program will wish to use one of the timers to establish the serial port s baud rate. &n this case+ it is necessary to configure timer 1 by initiali>ing T314 and T(1.. SBUF "Seria( Contro(# A$$resses 33h): The !erial Buffer !"# is used to send and receive data via the on0board serial port. 'ny value written to !B;" will be sent out the serial port s TC. pin. =i/ewise+ any value which the 8051 receives via the serial port s #C. pin will be delivered to the user program via !B;". &n other words+ !B;" serves as the output port when written to and as an input port when read from. P/ "Port /# A$$ress A!h# Bit&A$$ressa'(e): This is input/output port ,. *ach bit of this !"# corresponds to one of the pins on the microcontroller. "or example+ bit 0 of port , is pin 6,.0+ bit ) is pin 6,.). -riting a value of 1 to a bit of this !"# will send a high level on the corresponding &/1 pin whereas a value of 0 will bring it to a low level. Programming Tip: -hile the 8051 has four &/1 port $60+ 61+ 6,+ and 62%+ if your hardware uses external #'( or external code memory $i.e.+ your program is stored in an external #1( or *6#1( chip or if you are using external #'( chips% you may not use 60 or 6,. This is because the 8051 uses ports 60 and 6, to address the external memory. Thus if you are using external #'( or code memory you may only use ports 61 and 62 for your own use. 4E "4nterr5pt Ena'(e# A$$resses A%h): The &nterrupt *nable !"# is used to enable and disable specific interrupts. The low ) bits of the !"# are used to enable/disable the specific interrupts+ where as the highest bit is used to enable or disable '== interrupts. Thus+ if the high bit of &* is 0 all interrupts are disabled regardless of whether an individual interrupt is enabled by setting a lower bit.

P0 "Port 0# A$$ress B!h# Bit&A$$ressa'(e): This is input/output port 2. *ach bit of this !"# corresponds to one of the pins on the microcontroller. "or example+ bit 0 of port 2 is pin 62.0+ bit ) is pin 62.). -riting a value of 1 to a bit of this !"# will send a high level on the corresponding &/1 pin whereas a value of 0 will bring it to a low level. 4P "4nterr5pt Priority# A$$resses B%h# Bit&A$$ressa'(e): The &nterrupt 6riority !"# is used to specify the relative priority of each interrupt. 1n the 8051+ an interrupt may either be of low $0% priority or high $1% priority. 'n interrupt may only interrupt interrupts of lower priority. "or example+ if we configure the 8051 so that all interrupts are of low priority except the serial interrupt+ the serial interrupt will always be able to interrupt the system+ even if another interrupt is currently executing. <owever+ if a serial interrupt is executing no other interrupt will be able to interrupt the serial interrupt routine since the serial interrupt routine has the highest priority. PSW "Program Stat5s Wor$# A$$resses D!h# Bit&A$$ressa'(e): The 6rogram !tatus -ord is used to store a number of important bits that are set and cleared by 8051 instructions. The 6!- !"# contains the carry flag+ the auxiliary carry flag+ the overflow flag+ and the parity flag. 'dditionally+ the 6!- register contains the register ban/ select flags which are used to select which of the 5#5 register ban/s are currently selected. Programming Tip: &f you write an interrupt handler routine+ it is a very good idea to always save the 6!- !"# on the stac/ and restore it when your interrupt is complete. (any 8051 instructions modify the bits of 6!-. &f your interrupt routine does not guarantee that 6!- is the same upon exit as it was upon entry+ your program is bound to behave rather erradically and unpredictably00and it will be tric/y to debug since the behavior will tend not to ma/e any sense. ACC "A 5m5(ator# A$$resses E!h# Bit&A$$ressa'(e): The 'ccumulator is one of the most0used !"#s on the 8051 since it is involved in so many instructions. The 'ccumulator resides as an !"# at *0h+ which means the instruction 2O6 A#7/!h is really the same as 2O6 E!h#7/!h. <owever+ it is a good idea to use the first method since it only re8uires two bytes whereas the second option re8uires three bytes. B "B Register# A$$resses F!h# Bit&A$$ressa'(e): The 5B5 register is used in two instructions7 the multiply and divide operations. The B register is also commonly used by programmers as an auxiliary register to temporarily store values.

Other SFRs
The chart above is a summary of all the !"#s that exist in a standard 8051. 'll derivative microcontrollers of the 8051 must support these basic !"#s in order to maintain compatability with the underlying (!3!51 standard. ' common practice when semiconductor firms wish to develop a new 8051 derivative is to add additional !"#s to support new functions that exist in the new chip. "or example+ the .allas !emiconductor .!8032,0 is upwards compatible with the 8051. This means that any program that runs on a standard 8051 should run without

modification on the .!8032,0. This means that all the !"#s defined above also apply to the .allas component. <owever+ since the .!8032,0 provides many new features that the standard 8051 does not+ there must be some way to control and configure these new features. This is accomplished by adding additional !"#s to those listed here. "or example+ since the .!8032,0 supports two serial ports $as opposed to 9ust one on the 8051%+ the !"#s !B;", and !314, have been added. &n addition to all the !"#s listed above+ the .!8032,0 also recogni>es these two new !"#s as valid and uses their values to determine the mode of operation of the secondary serial port. 1bviously+ these new !"#s have been assigned to !"# addresses that were unused in the original 8051. &n this manner+ new 8051 derivative chips may be developed which will run existing 8051 programs. Programming Tip: &f you write a program that utili>es new !"#s that are specific to a given derivative chip and not included in the above !"# list+ your program will not run properly on a standard 8051 where that !"# does not exist. Thus+ only use non0standard !"#s if you are sure that your program wil only have to run on that specific microcontroller. =i/ewise+ if you write code that uses non0 standard !"#s and subse8uently share it with a third0party+ be sure to let that party /now that your code is using non0standard !"#s to save them the headache of reali>ing that due to strange behavior at run0 time.

You might also like