Книга: Advanced PIC Microcontroller Projects in C
3.1 Structure of a mikroC Program
Figure 3.1 shows the simplest structure of a mikroC program. This program flashes an LED connected to port RB0 (bit 0 of PORTB) of a PIC microcontroller in one-second intervals. Do not worry if you don’t understand the operation of the program at this stage, as all will come clear as this chapter progresses. Some of the programming elements in Figure 3.1 are described in detail here.
/********************************************************************
LED FLASHING PROGRAM
*********************************
This program flashes an LED connected to port pin RB0 of PORTB with
one second intervals.
Programmer : D. Ibrahim
File : LED.C
Date : May, 2007
Micro : PIC18F452
**********************************************************************/
void main() {
for(;;) // Endless loop
{
TRISB = 0; // Configure PORTB as output
PORTB.0 = 0; // RB0 = 0
Delay_Ms(1000); // Wait 1 second
PORTB.0 = 1; // RB0 = 1
Delay_Ms(1000); // Wait 1 second
} // End of loop
}
Figure 3.1: Structure of a simple C program
- 3.1.1 Comments
- 3.1.2 Beginning and Ending of a Program
- 3.1.3 Terminating Program Statements
- 3.1.4 White Spaces
- 3.1.5 Case Sensitivity
- 3.1.6 Variable Names
- 3.1.7 Variable Types
- 3.1.8 Constants
- 3.1.9 Escape Sequences
- 3.1.10 Static Variables
- 3.1.11 External Variables
- 3.1.12 Volatile Variables
- 3.1.13 Enumerated Variables
- 3.1.14 Arrays
- 3.1.15 Pointers
- 3.1.16 Structures
- 3.1.17 Unions
- 3.1.18 Operators in C
- 3.1.19 Modifying the Flow of Control
- 3.1.20 Mixing mikroC with Assembly Language Statements
- 3.4 Summary
- 3.1.2 Beginning and Ending of a Program
- 3.1.3 Terminating Program Statements
- 3.1.4 White Spaces
- 3.1.5 Case Sensitivity
- 3.1.7 Variable Types
- 3.1.9 Escape Sequences
- 3.1.10 Static Variables
- 3.1.11 External Variables
- 3.1.12 Volatile Variables
- 9.4 Overload Frame
- CHAPTER 3 C Programming Language