Книга: 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

Оглавление книги


Генерация: 2.039. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз