ElectroNerd
Newbie level 6
This thread will resolve to be the major thread of which I will include all my LED combinational patterns that I am having difficulty with. My next pattern is to have the LEDs shift into each other; something like this:
1000000001
0100000010
0010000100
0001001000
0000110000
I have the following code, but it is two seperate while loops that make it so half the LEDs scroll up, and once that's finished, the other half scroll down. I need that to happen simultaneously. Obviously, I need to have a single while loop but I'm not sure how that would work. The code that's after the "//----------[The following code controls the LEDs]----------" is the code that I need to be concerned of:
I have 4 bits going to TRISA and 6 bits going to TRISB, that's what makes this confusing. How do I make this work? Can I get by with just 2 variables instead of 3? I am using the PIC18F1320 with the C18 compiler from MPLAB.
Thanks!
1000000001
0100000010
0010000100
0001001000
0000110000
I have the following code, but it is two seperate while loops that make it so half the LEDs scroll up, and once that's finished, the other half scroll down. I need that to happen simultaneously. Obviously, I need to have a single while loop but I'm not sure how that would work. The code that's after the "//----------[The following code controls the LEDs]----------" is the code that I need to be concerned of:
Code:
//
// WalkingLEDCombo3.C
//
#include <p18f1320.h>
#include <delays.h>
#include <stdlib.h>
#pragma config OSC=INTIO2, WDT=OFF, LVP=OFF, DEBUG=ON
#define PAUSE 50
void main()
{
unsigned int pat; // Variable for TRISA
unsigned int patstopBits; // Variable for TRISB
unsigned int patstop; // Variable for TRISB
OSCCONbits.IRCF0=1;
OSCCONbits.IRCF1=1;
OSCCONbits.IRCF2=1;
while(!OSCCONbits.IOFS);
TRISA = 0b11110000;
TRISB = 0b11000000;
//----------[The following code controls the LEDs]----------
while(1)
{
pat = 0x01;
patstop = 0x20;
while(pat < 0x1F)
{
patstopBits=pat>>4; // patstopBits is a function of pat.
LATA = pat;
LATB = patstopBits; // patstopBits is for TRISB.
Delay10KTCYx(PAUSE);
pat<<=1; // Shift pat once to the right.
patstopBits>>=1;
}
patstopBits = 0x20;
while(patstopBits > 1E0)
{
LATB = patstopBits; // patstopBits is for TRISB.
Delay10KTCYx(PAUSE);
patstopBits>>=1;
}
}
}
I have 4 bits going to TRISA and 6 bits going to TRISB, that's what makes this confusing. How do I make this work? Can I get by with just 2 variables instead of 3? I am using the PIC18F1320 with the C18 compiler from MPLAB.
Thanks!