LED blinking, chasing, converging and diverging

Thread Starter

jaary

Joined Sep 18, 2012
2
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
 

ErnieM

Joined Apr 24, 2011
8,041
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:

Rich (BB code):
void main(void)
{
    char Buttons;

    TRISx = 0b00001111;               // define input pins

    while(1)
    {
        Buttons = PortB & 0x0F;     // mask for used buttons
        switch (Buttons)
        {
            case 0b00001110:
                Pattern_1();
                break;
            case 0b00001101:
                Pattern_2();
                break;
            case 0b00001011:
                Pattern_3();
                break;
            case 0b00000111:
                Pattern_4();
                break;
        }
    }
}
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.
 
Top