LED blinking, chasing, converging and diverging

Discussion in 'Embedded Systems and Microcontrollers' started by jaary, Sep 18, 2012.

  1. jaary

    Thread Starter New Member

    Sep 18, 2012
    2
    0
    Hi. I have my seatwork now in programming a PIC16f84a it goes this way.
    when the bit 0 of porta of the PIC is set to 1 then 0, all 8 LEDS connected to portb will blink 3 times.
    when the bit 1 is set to 1 then 0, the LED runs from left to right 3 times.
    when the bit 2 is set to 1 then 0, the LEds runs from right to left 3 times.
    when the bit 3 is set to 1 then 0, the LEDS diverges 3 times. It looks this way
    00011000
    00100100
    01000010
    10000001
    when the bit 4 is set to 1 then 0, the leds converges 3 times. it looks this way
    10000001
    01000010
    00100100
    00011000

    anyone pls help... i have only an hour to do it. thanks a lot..
    have a good day :D
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    There there, I am here to help. Let me check my book. Nope no free time slot until tomorrow. Sorry for that
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,355
    Yes, I think it's doable.
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Lookup table?
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Assume buttons are on the low 4 bits of a port. As the button codes defines are self-exclusionary we just need to test for each case:

    Code ( (Unknown Language)):
    1. void main(void)
    2. {
    3.     char Buttons;
    4.  
    5.     TRISx = 0b00001111;               // define input pins
    6.  
    7.     while(1)
    8.     {
    9.         Buttons = PortB & 0x0F;     // mask for used buttons
    10.         switch (Buttons)
    11.         {
    12.             case 0b00001110:
    13.                 Pattern_1();
    14.                 break;
    15.             case 0b00001101:
    16.                 Pattern_2();
    17.                 break;
    18.             case 0b00001011:
    19.                 Pattern_3();
    20.                 break;
    21.             case 0b00000111:
    22.                 Pattern_4();
    23.                 break;
    24.         }
    25.     }
    26. }
    Pattern_X() is equally trivial.

    Note as written the pattern will repeat as long as the key is pressed. If this is not desired a check for key_up would be necessary.
     
    absf likes this.
Loading...