Книга: Advanced PIC Microcontroller Projects in C

Project Program

Project Program

The program is named as LED1.C, and the program listing is given in Figure 6.5. At the beginning of the program PORTC pins are configured as outputs by setting TRISC = 0. Then an endless for loop is formed, and the LEDs are turned ON alternately in an anticlockwise manner to create a chasing effect. The program checks continuously so that when LED 7 is turned ON, the next LED to be turned ON is LED 0.

This program can be compiled using the mikroC compiler. Project settings should be configured to 4MHz clock, XT crystal mode, and WDT OFF. The HEX file (LED1.HEX) should be loaded to the PIC18F452 microcontroller using either an in-circuit debugger or a programming device.

/*****************************************************************************
                               CHASING LEDS
                               ============
In this project 8 LEDs are connected to PORTC of a PIC18F452 microcontroller
and the microcontroller is operated from a 4MHz resonator. The program turns
on the LEDs in an anti-clockwise manner with one second delay between each
output. The net result is that the LEDs seem to be chasing each other.
Author: Dogan Ibrahim
Date:   July 2007
File:   LED1.C
******************************************************************************/
void main() {
 unsigned char J = 1;
 TRISC = 0;
 for(;;)             // Endless loop
 {
  PORTC = J;         // Send J to PORTC
  Delay_ms(1000);    // Delay 1 second
  J = J << 1;        // Shift left J
  if (J == 0) J = 1; // If last LED, move to first LED
 }
}


Figure 6.5: Program listing

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


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