Writing a function
Functions (sometimes called subroutines) are used to hide the complexity of underlying program statements, thereby presenting a more abstract view of the program. Abstraction is commonplace in engineering; for example, we can think of a car as comprising subassemblies that include body, engine, gearbox, suspension, and so on. The complexity within these subassemblies is only important to those specialists such as designers, test engineers, and technicians who need to interact with them. For example, the designers of the gearbox don't need to concern themselves with the intricacies of the engine, they just need to know a few important parameters. Functions provide a similar abstraction mechanism. We already met the functions LED_Initialize()
; LED_On()
, and LED_Off()
used to initialize and switch the LEDs. We don't need to know exactly how these functions do their job but only how to use them. C provides functions as a mechanism of achieving hierarchical decomposition. For...