Traditional and Structure Approach to C Coding
C2000 Microcontroller Workshop - Peripheral Registers Header Files
3 - 3
Traditional and Structure Approach to C Coding
Traditional Approach to C Coding
#define ADCCTL1 (volatile unsigned int *)0x00007100
...
void main(void)
{
*ADCCTL1 = 0x1234;
//write entire register
*ADCCTL1 |= 0x4000;
//enable ADC module
}
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 exactly 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.
Содержание C2000 Piccolo LaunchPad
Страница 74: ...Interrupts 4 18 C2000 Microcontroller Workshop Reset and Interrupts ...
Страница 100: ...Lab 5 System Initialization 5 26 C2000 Microcontroller Workshop System Initialization ...
Страница 126: ...Lab 6 Analog to Digital Converter 6 26 C2000 Microcontroller Workshop Analog to Digital Converter ...
Страница 218: ...Lab 8 IQmath FIR Filter 8 42 C2000 Microcontroller Workshop Numerical Concepts ...
Страница 236: ...Lab 9 Servicing the ADC with DMA 9 18 C2000 Microcontroller Workshop Direct Memory Access Controller ...
Страница 260: ...Lab 10 CLA Floating Point FIR Filter 10 24 C2000 Microcontroller Workshop Control Law Accelerator ...
Страница 331: ...C2000 Microcontroller Workshop Appendix A Experimenter s Kit A 1 Appendix A Experimenter s Kit ...
Страница 334: ...F28069 controlCARD A 4 C2000 Microcontroller Workshop Appendix A Experimenter s Kit SW2 ...
Страница 336: ...F28035 controlCARD A 6 C2000 Microcontroller Workshop Appendix A Experimenter s Kit SW2 SW3 ...
Страница 338: ...F28335 controlCARD A 8 C2000 Microcontroller Workshop Appendix A Experimenter s Kit LD1 LD2 LD3 SW1 ...