4 Function & Interrupts Flashcards
What are functions in C?
- A function is a re-usable block of code that contains variables and expressions
- Examples might include the __delay_ms() function we have seen already
- The concept is the same as using call and return in assembly (but in assembly we called the function a sub-routine)
Example function block in C?
The position of function blocks?
Main is a special function, it defines the entry point of our program
Any other functions (libraries or our own) need to be defined before main, so that they exist before we try and use them
Example function overall structure within the code?
Advantages of functions?
- Re-use a block of code many times
- Decompose complex programming tasks into simpler steps
- Reduce code duplication
- Divide large tasks between team members
- Individual functions can be tested in isolation before assembly into a larger program
What are interrupts?
- Interrupts are a hardware feature of the PIC, so they work in basically the same way in C as assembler
- Just like if and while, interrupts can be a useful tool to change the flow of your code (for example in response to a button press)
- Once configured, an external interrupt will call the ISR
Example ISR code checking PORTB?
Standards are designed to create code that is:
Organised Easy to read Easy to understand Maintainable Efficient All major companies will adopt their own set of rules
Why are coding standards important?
- Up to 80% of lifetime cost of software is maintenance
- Rarely is the original author responsible for the entire life-cycle
- Commercial software must be reliable and efficient
Example indentation in the code?
Comments details?
start with //
What is revision control?
Having software in place to monitor how many version of code there are.