Source Code File:"12FLedsSub.c"

#pragma CLOCK_FREQ 4000000
#pragma DATA 0x2007, 0x184
#include <system.h>

                // DEFINE OUPUT PINS IN USE
char gp1 = 00000001b;
char gp2 = 00000010b;
char gp4 = 00000100b;
char gp5 = 00010000b;
char gp6 = 00100000b;

                // DEFINE DATA DIRECTION
char trs1   = 11111100b;
char trs2   = 11111001b;
char trs3   = 11111010b;
char trs4   = 11101110b;
char trs5   = 11101101b;
char trs6   = 11101011b;
char trs7   = 11011110b;
char trs8   = 11011101b;
char trs9   = 11011011b;
char trs10  = 11001111b;

void Led(unsigned char num);

void interrupt(void)
{
    gpio = gp2;             // LED9 FOR FEEDBACK
    clear_bit( intcon, GPIF );  // clear RB change flag
}
void main()
{
    clear_bit( option_reg, 0 ); // set config INT_OSC_NO_CLK_OUT
    clear_bit( option_reg, 1 ); // "
    clear_bit( intcon, GIE );   // disable global interrupts
    delay_ms(10);               
    set_bit( intcon, GIE );     // enable global interrupts
    set_bit( intcon, GPIE );    // enable RB change bit    
    set_bit(iocb, IOC3);        // Allow interrupt on GP3
//  
    unsigned char i,j;  
    trisio = 0x00;
    gpio = 0x00;    
    delay_ms(100);
LOOP:
    for (i = 1; i <= 3; i++)
    {
                                // FIRST LOOP RUNS ONE WAY
        for (j = 1; j <= 20; j++)
        {
            Led(j);
            delay_ms(100);

        } // end for j
    } // end for i
    gpio = 0;
    delay_ms(255);
    
    for (i = 1; i <= 3; i++)
    {
                                // FIRST LOOP RUNS ONE WAY
        for (j = 20; j >= 1; j--)
        {
            Led(j);
            delay_ms(100);

        } // end for j
    } // end for i
    gpio = 0;
    delay_ms(255);
    
    for (i = 1; i <= 3; i++)
    {
                                // FIRST LOOP RUNS ONE WAY
        for (j = 1; j <= 20; j++)
        {
            Led(j);
            delay_ms(100);

        } // end for j
        for (j = 20; j >= 1; j--)
        {
            Led(j);
            delay_ms(100);

        } // end for j
    } // end for i
    gpio = 0;
    delay_ms(255);
    
    
    sleep();
goto LOOP;
}
// function lights chosen led
void Led(unsigned char num)
{
    switch (num)
    {
case 1:
    {
    trisio = trs1;
    gpio = gp1; // LED1
    break;
    }
case 2:
    {
    trisio = trs1;
    gpio = gp2; // LED2
    break;
    }
case 3:
    {
    trisio = trs2;  
    gpio = gp2; // LED3
    break;
    }   
 case 4:
    {
    trisio = trs2;  
    gpio = gp4; // LED4
    break;
    }
 case 5:
    {
    trisio = trs3;  
    gpio = gp1; // LED5
    break;
    }   
 case 6:
    {
    trisio = trs3;  
    gpio = gp4; // LED6
    break;
    }   
 case 7:
    {
    trisio = trs4;
    gpio = gp1; // LED7
    break;
    }   
 case 8:
    {
    trisio = trs4;
    gpio = gp5; // LED8 
    break;
    }
 case 9:
    {
    trisio = trs5;
    gpio = gp2; // LED9
    break;
    }
case 10:
    {   
    trisio = trs5;
    gpio = gp5; // LED10
    break;
    }   
case 11:
    { 
    trisio = trs6;
    gpio = gp4; // LED11    
    break;
    }
 case 12:
    {
    trisio = trs6;
    gpio = gp5; // LED12    
    break;
    }
 case 13:
    {
    trisio = trs7;
    gpio = gp1; // LED13    
    break;
    }
 case 14:
    {
    trisio = trs7;
    gpio = gp6; // LED14    
    break;
    }
 case 15:
    {
    trisio = trs8;
    gpio = gp2; // LED15
    break;
    }   
 case 16:
    {
    trisio = trs8;
    gpio = gp6; // LED16    
    break;
    }
 case 17:
    {
    trisio = trs9;
    gpio = gp4; // LED17    
    break;
    }
 case 18:
    {
    trisio = trs9;
    gpio = gp6; // LED18
    break;
    }
 case 19:
    {
    trisio = trs10;
    gpio = gp5; // LED19
    break;
    }
 case 20:
    {
    trisio = trs10;
    gpio = gp6; // LED20
    break;
    }
default:
    {
        break;
    }
}   
} // end Led(num)

http://www.sourceboost.com

Copyright © 2006 SourceBoost Technologies