Connect with us

one switch control two LED

Discussion in 'Microcontrollers, Programming and IoT' started by ikram1991, Jun 16, 2013.

Scroll to continue with content
  1. ikram1991

    ikram1991

    43
    0
    May 5, 2013
    I'm build source code for one switch control two LED.
    Switch work as counter.
    If counter = 1 LED1 on and LED2 off.
    if counter = 2 LED1 off and LED2 on.
    If counter = 3 LED1 on and LED2 on.

    But when I'm trying in simulation it doesn't work it.
    I'm used PROTEUS ISIS simulation.
    I attach this post with schematic and source code.
    I hope u guys can help me to fix my problem again ;)
     

    Attached Files:

  2. ligo.george

    ligo.george

    12
    4
    Feb 2, 2013
    I have no time to check your code... LED1 is connected to PORTB.0 , LED2 is connected to PORTB.1...and switch is connected to PORTC.0 .. PORTC.0 is pulled up ed via a 10K ohm resistor and pushing the switch makes PORTC.0 low...
    here is the mikroc code for you..
    Code:
    void main()
    {
       int i = 1;
       
       TRISB.F0 = 0; 
       TRISB.F1 = 0;
       TRISC.F0 = 1;
        
        do
        {
           if(PORTC.F0 == 0)
           {  
               Delay_ms(100); //Switch Delay
               if(PORTC.F0 == 0)
               { 
                    i++;
                    if(i>3)
                       i=1;
               }
           }
         
           if(i == 1)
           {
              PORTB.F0 = 1;
              PORTB.F1 = 0;
           }
           if(i == 2)
           {
               PORTB.F0 = 0;
               PORTB.F1 = 1;
           }
           if(i == 3)
           {
               PORTB.F0 = 1;
               PORTB.F1 = 1;
           }
        }while(1);
    }
    
    These links may help you...
    PIC Microcontroller Tutorials
    Using Push Button Switch with PIC Microcontroller

    If you are using any other compiler.. you can make the required code by making some modification in the above code..
     
  3. ikram1991

    ikram1991

    43
    0
    May 5, 2013
    Thank you,George.
    I forgot to mention I use MPLAB with hi-tech C compiler.
    Anyway,It work! :)
     
    Last edited: Jun 16, 2013
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-