Traditional and Structure Approach to C Coding
TMS320F2837xD Microcontroller Workshop - Peripherial Registers Header Files 3 - 5
Traditional and Structure Approach to C Coding
Traditional Approach to C Coding
#define TBCTL (volatile unsigned int *)0x00004000
...
void main(void)
{
*TBCTL = 0x1234; //write entire register
*TBCTL |= 0x0003; //stop time-base counter
}
Disadvantages - Requires individual masks to be generated to
manipulate individual bits
- Cannot easily display bit fields in debugger window
- Will generate less efficient code in many cases
Advantages - Simple, fast and easy to type
- Variable names can match register names (easy
to remember)
In the traditional approach to C coding, we used a #define to assign the address of the register
and referenced it with a pointer. The first line of code on this slide we are writing to the entire
register with a 16-bit value. The second line, we are ORing a bit field.
Advantages? Simple, fast, and easy to type. The variable names can exactly match the register
names, so it's easy to remember. Disadvantages? Requires individual masks to be generated to
manipulate individual bits, it cannot easily display bit fields in the debugger window, and it will
generate less efficient code in many cases.