0% found this document useful (0 votes)
34 views

Pic Example2

The document contains code for several microcontroller projects including: 1. A logic probe project with two LEDs (red and green) connected to a microcontroller port to indicate the logic level of a probe input. 2. A flashing LED project with an LED connected to a microcontroller port flashing in a repeated pattern of 3 flashes with 200ms delays. 3. A simple dice project using 7 LEDs connected to a microcontroller port to display random dice patterns when a button is pressed.

Uploaded by

UYeMin Htike
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Pic Example2

The document contains code for several microcontroller projects including: 1. A logic probe project with two LEDs (red and green) connected to a microcontroller port to indicate the logic level of a probe input. 2. A flashing LED project with an LED connected to a microcontroller port flashing in a repeated pattern of 3 flashes with 200ms delays. 3. A simple dice project using 7 LEDs connected to a microcontroller port to display random dice patterns when a button is pressed.

Uploaded by

UYeMin Htike
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

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
Author: Dogan Ibrahim
Date: August 2013
File: MIKROC-LED2.C

*****************************************************************************/
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.
Author: Dogan Ibrahim
Date: August 2013
File: MIKROC-LED3.C
*****************************************************************************/
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
}
}
LED BLINKING
====================

void main() {
// set PORTB to be digital output
TRISB = 0;
// Turn OFF LEDs on PORTB
LATB = 0;
while(1) {
// Toggle LEDs on PORTB
LATB = ~LATB;
// Delay 1000 ms
Delay_ms(1000);
}
}

PUSH BUTTON
In this project 1 LED is connected to PORTB.RB0 of a PIC18F45K22 microcontroller and 1 switch
is connected to PORTC.RC0, the microcontroller is operated from an 8 MHz crystal.
The program detects whether the switch is pressed or not. When the switch is pressed, LED
connected to PORTB.RB0 is light up.
*****************************************************************************/

void main() {
TRISC.RC0 = 1; //Configure 1st bit of PORTD as input
TRISB.RB0 = 0; //Configure 1st bit of PORTB as output
PORTB.RB0 = 0; //LED OFF
do
{
if(PORTC.RC0 == 1) //Check whterer the switch is pressed
PORTB.RB0 = 1; //LED ON
else
PORTB.RB0 = 0; //LED OFF
}while(1);
}
DIP switch SW3: PORTC and PORTB ON
Jumper J17 (Bu on Press Level): VCC
LOGIC PROBE
===========
This is a logic probe project. In this project 2 colored LEDs are connected to PORTC pins
RC6 (RED) and RC7 (GREEN). In addi on, RC0 is used as the probe input.
If the logic probe is at logic 0 then the RED LED is turned ON. Otherwise, the GREEN LED is
turned ON.
Author: Dogan Ibrahim
Date: August 2013
File: MIKROC-LED4.C
******************************************************************************
*/
#define PROBE PORTC.RC0
#define RED_LED PORTC.RC6
#define GREEN_LED PORTC.RC7
void main()
{
ANSELC = 0; // Configure PORTC as digital
TRISC0_bit = 1; // Configure RC0 as input
TRISC6_bit = 0; // Configure RC6 as output
TRISC7_bit = 0; // Configure RC7 as output
for(;;) // Endless loop
{
if(PROBE == 0) // If the signal is LOW
{
GREEN_LED = 0; // Turn OFF GREEN LED
RED_LED = 1; // Torn ON RED LED
}
else
{
RED_LED = 0; // Turn OFF RED LED
GREEN_LED = 1; // Turn ON GREEN LED
}
}
}
Jumper J17 (Bu on Press Level): VCC

BUZZER
====================

void main() {
ANSELC=0;
TRISC=0;
PORTC=0;
for(;;)
{unsigned int i,j,k;
for(i=0;i<80;i++)
{PORTC.RC2=1;
Delay_ms(1);
PORTC.RC2=0;
Delay_ms(1);}

for(j=0;j<80;j++)
{ PORTC.RC2=1;
Delay_ms(2);
PORTC.RC2=0;
Delay_ms(2);}

}
}

SIMPLE DICE
==========
In this project 7 LEDs are connected to PORTC of a PIC18F45K22 microcontroller and the
microcontroller is operated from an 8 MHz crystal. The LEDs are organized as the faces
of a real dice. When a push-bu on switch connected to RB0 is pressed a dice pa ern is
displayed on the LEDs. The display remains in this state for 3 s and a er this period
the LEDs all turn OFF to indicate that the system is ready for the bu on to be pressed again.

#define Switch PORTB.RB0


#define Pressed 0
void main()
{
unsigned char J = 1;
unsigned char Pe ern;
unsigned char DICE[] = {0,0x01,0x03,0x07,0x0F,0x1F,0x3F};
ANSELC = 0; // Configure PORTC as digital
ANSELB = 0; // Configure PORTB as digital
TRISC = 0; // Configure PORTC as outputs
TRISB = 1; // Configure RB0 as input
PORTC = 0; // Turn OFF all LEDs
for(;;) // Endless loop
{
if(Switch == Pressed) // Is switch pressed ?
{
Pa ern = DICE[J]; // Get LED pa ern
PORTC = Pa ern; // Turn on LEDs
Delay_ms(3000); // Delay 3 s
PORTC = 0; // Turn OFF all LEDs
J = 0; // Ini_alize J
}
J++; // Increment J
if(J == 7) J = 1; // Back to 1 if >6
}
}
DIP switch SW3: PORTC ON
Jumper J17 (Bu on Press Level): GND

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy