Description

The following program flashes 8 LEDs on  the PORTC pins of the pic16f887.

Source Code

void main() {
PORTC=0;  //initialize portc
TRISC=0b00000000;   //configure portc as output
ANSELH=0;    //configure an pin as digital I/O
ANSEL=0;
while(1){
PORTC=~PORTC;     //toggle portc
delay_ms(10000);   //1s delay
}

}

Circuit Diagram

Led blinking circuit


About these ads

Comments on: "Led blinking program with pic16f887 and mikroC PRO for PIC" (20)

  1. shabbash shamim :)

  2. nice work.continue..

  3. Nice work man.
    I want to make program to blink LEDs of RD7, RD4 and RD3 at every 3 sec, 2 sec and 1 sec respectively.
    please help me if you have done it before.

    Thanks.

    • Configure PORTD just like below:
      PORD=0; //initialize portd
      TRISD=0b00000000; //configure portd as output

      change inside the while loop:

      PORTD=0×98; //RD7,RD4,RD3 port blink
      delay_ms(30000); //3s delay
      PORTD=0×00 ;
      delay_ms(30000); //3s delay
      PORTC=0×98;
      delay_ms(20000); //2s delay
      PORTD= 0×00 ;
      delay_ms(20000); //2s delay
      PORTD= 0×98;
      delay_ms(10000); //1s delay
      PORTD=0×00 ;
      delay_ms(10000); //1s delay

      • Anonymous said:

        en pratique le code ne fonctionne pas le pic fait 2 instructios uis il reboucle !!!!! :”’(

  4. Thanks a lot shamim for such a great help.
    By the way can we make the same thing with use of timer?
    I am suggested to make this program using timer.
    If you have done this before let me know.
    Your help is appreciated.
    Thanks again.

  5. i wrote the program as given but it says ANSELH and ANSEL undeclared bro

  6. Please, check your microcontroller model.I have used PIC16F887.

  7. hey,the delays don’t work unless the inbuilt ones are used.Why?also 1s=1000ms,why are u using 10000.Explain me how to use real time delays with this mikroc pro for pic.
    Thx

  8. can some one help me to write simple programming for LED. i want when there is gas leak at 300ppm, LED blink and is connected from portE, pin AN6 and if the gas leak more than 300 ppm the LED blink and is connected from portE , pin AN7.

    • this one is for you salim

      TRISE= 0; // initialise port E as in output port
      for(;;) // infinte loop
      {
      if( gasleak==300 )

      {
      PORTE=0b010;
      }
      if(gasleak>300)
      {
      PORTE=0b100;
      }
      }

  9. I am have little knowledge on microcontrollers, using different PIC’s for developing some control devices. I want the code in mikroC PRO for PIC16F887, with 8.0000 MHz clock for microchip 44 pin Demo board, the routines have been written from microchip in HITECH C, since I am working and have programmer and software from mikroE I am interested to go with that only, instead of running around.

    If any body will help me for that, they used internal oscillator to control the speed of the running leds on one of the ports and the direction is switching with the help of one micro swith. This all I wand in mikroC PRO., that will help me in learning the use and control of the internal clock of the MCU and other things as well.

  10. saurabh said:

    this one is for you salim

    TRISE= 0; // initialise port E as in output port
    for(;;) // infinte loop
    {
    if( gasleak==300 )

    {
    PORTE=0b010;
    }
    if(gasleak>300)
    {
    PORTE=ob100;
    }
    }

  11. Muhammad Abrar said:

    void main() {
    int d,b,c;
    trisb=0;
    trisa=0;
    trisc=0;
    trisd=0;
    portd=0;
    while(d!=10)
    {
    portd=d;
    c=0;
    while(c!=10)
    {
    portc=c;
    b=0;
    while(b!=10)
    {
    portb=b;
    delay_ms(30);

    b=b+1;
    }
    c=c+1;
    }
    d=d+1;
    }
    }

  12. can you tell me how can i configure output as digital on 16f877a on mikroC to make this project working on real time??

  13. void main()
    {
    portb=0b00000001 ;
    delay_ms(1500) ;
    portb=0b00000000 ;
    delay_ms(1500) ;

    portb=0b00000010 ;
    delay_ms(1000) ;
    portb=0b00000000 ;
    delay_ms(1000) ;
    }

    the above coding is do b0 then only do b1…
    how can i make the b0 and b1 run together?

  14. Hmm is anyone else having problems with the pictures on this blog loading?
    I’m trying to determine if its a problem on my end or if it’s
    the blog. Any feed-back would be greatly appreciated.

  15. hello. can somebody help me to write a simple coding which is i have two switch. and switch 1 is turn on, the motor take 1000ms delay before it will rotate and when s2 is turn on, the motor take 3000ms before it stop rotate. i really need it. i use pic 16F877A

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 38 other followers

%d bloggers like this: