Traditional and Structure Approach to C Coding
3 - 4 C2000 Microcontroller Workshop - Peripheral Registers Header Files
Structure Approach to C Coding
void main(void)
{
AdcRegs.ADCCTL1.all = 0x1234; //write entire register
AdcRegs.ADCCTL1.bit.ADCENABLE = 1; //enable ADC module
}
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.