13.07.2015 Views

TASKING VX-toolset for 8051 User Guide

TASKING VX-toolset for 8051 User Guide

TASKING VX-toolset for 8051 User Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>TASKING</strong> <strong>VX</strong>-<strong>toolset</strong> <strong>for</strong> <strong>8051</strong> <strong>User</strong> <strong>Guide</strong>• The bit symbol cannot be used as a global symbol. An extern on the bit variable, without __atbit(),will lead to an unresolved external message from the linker, so there<strong>for</strong>e __atbit() is required.Examples/* Module 1 */volatile __bdata unsigned int bitword;volatile __bit b __atbit( bitword, 3 );/* Module 2 */extern volatile __bdata unsigned int bitword;extern volatile __bit b __atbit( bitword, 3);Drawbacks of __atbit()The __atbit() requires all involved objects to be volatile. If your application does not require theseobjects to be volatile, you may see in many cases that the generated code is less optimal than when theobjects were not volatile. The reason <strong>for</strong> that is that the compiler must generate each read and writeaccess <strong>for</strong> volatile objects as written down in the C code. Fortunately the standard C language providesmethods to achieve the same result as with __atbit(). The compiler is smart enough to generateefficient bit operations where possible.1.2.5. Accessing Hardware from C: __sfr, __bsfrUsing Special Function RegistersIt is easy to access Special Function Registers (SFRs) that relate to peripherals from C. The SFRs aredefined in a special function register file (*.sfr) as symbol names <strong>for</strong> use with the compiler. An SFR filecontains the names of the SFRs and the bits in the SFRs.These SFR files are also used by the assemblerand the simulator engine. The debugger and the Eclipse IDE use the XML variants of the SFR files. TheXML files include full descriptions of the SFRs and the bit-fields. Also the bit-field values are described.To decrease compile time the .sfr files do not contain the descriptions. The .sfr files are in written Cand are derived from the XML files.Example use in C:#include void set_sfr(void){SCON = 0x88;SCR_P00_IN_3 = 1;if (SCR_P00_IN_4 == 1){SCR_P00_IN_3 = 0;}TCON_IE1 = 1;}// include the SFR file// use SFR name// use of bit name// use of bit nameYou can find a list of defined SFRs and defined bits by inspecting the SFR file <strong>for</strong> a specific processor.The files are named regcpu.sfr, where cpu is the name of the target processor. You can include the10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!