You are on page 1of 2

PIC is a Peripheral Interface Microcontroller which was developed in the year 1993 by the General

Instruments Microcontrollers. It is controlled by software and programmed in such a way that it


performs different tasks and controls a generation line. PIC microcontrollers are used in different
new applications such as smartphones, audio accessories, and advanced medical devices.

CHASING LEDS
============
In this project 8 LEDs are connected to PORTC of a PIC18F45K22 microcontroller and the
microcontroller is operated from an 8 MHz crystal.
The program turns ON the LEDs in an an clockwise manner with 1 s delay between
each output. The net result is that LEDs seem to be chasing each other.

**************************************************************************/
void main()
{
unsigned char J = 1;
ANSELC = 0; // Configure PORTC as digital
TRISC = 0; // Configure PORTC as output
for(;;) // Endless loop
{
PORTC = J; // Send J to PORTC
Delay_ms(1000); // Delay 1 s
J = J << 1; // Shi _ le _ J
if(J == 0) J = 1; // If last LED, move to first one
}
}
If you are using the EasyPIC V7 development board, then make sure that the following
jumper is configured:
DIP switch SW3: PORTC ON

COMPLEX FLASHING LED


===================
In this project an LEDs is connected to port pin RC0 of a PIC18F45K22 microcontroller and the
microcontroller is operated from an 8 MHz crystal.
The program flashes the LED con nuously with the following pa ern:
3 flashes with 200 ms delay between each flash
2 s delay
*****************************************************************************/
void main()
{
unsigned char i;
ANSELC = 0; // Configure PORTC as digital
TRISC = 0; // Configure PORTC as output
for(;;) // Endless loop
{
for(i = 0; i < 3; i++) // Do 3 _mes
{
PORTC.RC0 = 1; // LED ON
Delay_ms(200); // 200 ms delay
PORTC.RC0 = 0; // LED OFF
Delay_ms(200); // 200 ms delay
}
Delay_ms(2000); // 2 s delay
}
}
DIP switch SW3: PORTC ON

RANDOM FLASHING LEDS


====================

In this project 8 LEDs are connected to PORTC of a PIC18F45K22 microcontroller and the
microcontroller is operated from an 8 MHz crystal.
The program uses a pseudorandom number generator to generate a number between 0 and
32767. This number is then divided by 128 to limit it between 1 and 255. The resultant number
is sent to PORTC of the microcontroller. This process is repeated every second.
*****************************************************************************/
void main()
{
unsigned int p;
ANSELC = 0; // Configure PORTC as digital
TRISC = 0; // Configure PORTC as output
srand(10); // Ini alize random number seed
for(;;) // Endless loop
{
p = rand(); // Generate a random number
p = p / 128; // Number between 1 and 255
PORTC = p; // Send to PORTC
Delay_ms(1000); // 1 s delay
}
}

You might also like