Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

push button coding to change the pattern of led

Status
Not open for further replies.

apizbaygon

Junior Member level 3
Joined
Jan 5, 2013
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,431
hi guys...i wanna ask how to change the pattern of led chaser using only single push button??
i've decided to make 4 pattern of led blinking and to change the pattern with push button..it consists of 8 leds for port b and c in PIC16f877a
i use MikroC for the coding
~newbie~
 

declare one port as input and connect push button to that port... use the other port as output and connect the led to that...
write the program such that if input changes led to change the pattern
 

so the problem is at the coding...i'm new in MikroC
 

Hi apizbaygon

It is very simple. make your RA0 pin input and make PORTB and PORTC output ports. Write the code for switch with debounce and increment a counter from 0 to 4. 0 will represent OFF and 1...4 represent 4 patterns. You should also make the pattern counter 0 if its value is > 4. Then you have to use a switch case or if...else if statement and depending upon the value of patter counter PORTB and PORTC will have port enable or disable codes.
 

now i understand a little bit but i don't know where to put the coding for led pattern..
 

this is my 1st pattern and the other pattern i haven't decide yet..u can put any pattern there..
Code:
void main()
{
  TRISB = 0x00; // Sets all pins in PORTB as output
  PORTB = 1; // Set RB0 to high 00000001
    TRISC = 0x00;
    PORTC = 0xff;
    TRISD = 0x00;
    


 do // To set infinite loop
    {


    Delay_ms(300); // 100 mili seconds delay
    PORTB = PORTB<<1; //Shifting right by one bit
    PORTD = PORTD>>1;
    if(PORTB >= 0b10000000 && PORTD <= 0b00000001 ) //To reset to 00000001
    {                          //when the count becomes 10000000
       Delay_ms(300); // 200 mili seconds delay
       PORTB = 0x01;
       PORTD = 0x80;
    }
    
//    for (;;)

    {
    PORTC = 0xff ;          // turn all LEDs ON
    Delay_ms(100) ;         // wait 500 ms
    PORTC = 0 ;             // turn all LEDs OFF
    Delay_ms(100) ;         // wait 500 ms
    }
    
    
 // }while(1); // To set infinite loop


   }while (1);

}

- - - Updated - - -

ignore the comments in the code
 

I will think about the patterns and tell you but there is an infinite for loop in your code because of that your port c will be blinking all the time and nothing else happens after entering the for loop.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top