Traditional and Structure Approach to C Coding
3 - 6 TMS320F2837xD Microcontroller Workshop - Peripherial Registers Header Files
Structure Approach to C Coding
void main(void)
{
EPwm1Regs.TBCTL.all = 0x1234; //write entire register
EPwm1Regs.TBCTL.bit.CTRMODE = 3; //stop time-base counter
}
Disadvantages - Can be difficult to remember the structure names
(Editor Auto Complete feature to the rescue!)
- More to type (again, Editor Auto Complete feature
to the rescue)
Advantages - Easy to manipulate individual bits
- Watch window is amazing! (next slide)
- Generates most efficient code (on C28x)
The structure approach to C coding uses the peripheral register header files. First, a peripheral is
specified, followed by a control register. Then you can modify the complete register or selected
bits. This is almost self-commented code.
The first line of code on this slide we are writing to the entire register. The second line of code we
are modifying a bit field. Advantages? Easy to manipulate individual bits, it works great with our
tools, and will generate the most efficient code. Disadvantages? Can be difficult to remember
the structure names and more to type; however, the edit auto complete feature of Code
Composer Studio will eliminate these disadvantages.