#include <htc.h>
#define MAIN_C
__CONFIG(1, IESODIS & FCMDIS & INTCLKO & CPUDIV1 & PLLDIV1);
__CONFIG(2, BORDIS & PWRTDIS & WDTDIS);
__CONFIG(3, LPT1DIS & MCLREN);
__CONFIG(4, XINSTDIS & STVRDIS & LVPDIS & DEBUGDIS);
//Define pins
#define DATA RA0 // serial data to 595 shift register
#define CLOCK RA3 // SCK to all 595's shift register clock
#define LATCH RA4 // RCK all 595's (PWM, OE)clock for shift register display mode
#define OUTEN RC0 // Output Enable: Enable 0 Disable 1;
#define SCLR RB4 // SCLR Shift Register Clear 0 Clear, 1 don't
#define RTN1 RC1 // sink current bus 1
#define RTN2 RC2 // sink current bus 2
#define RTN3 RC6 // sink current bus 3
#define RTN4 RC7 // sink current bus 4
#define RTN5 RB0 // sink current bus 5
#define RTN6 RB1 // sink current bus 6
#define RTN7 RB2 // sink current bus 7
#define RTN8 RB3 // sink current bus 8
#define HIGH 1
#define LOW 0
// Declare functions
void pulseClock ( void );
void pulseLatch ( void );
// void sendSerial ( void );
void pulseClock()
{
CLOCK = HIGH; // SCK clock it
CLOCK = LOW;
}
void pulseLatch()
{
LATCH = LOW; // RCK pulse the storage register clock LOW
LATCH = HIGH; // RCK
}
void sendSerial(int serial[])
{
int i;
for (i = 0; i <=8; i++){
DATA = serial[i]; // bit 1
pulseClock();
}
}
void main(void){
// unsigned char eightBit;
ADCON1 = 0x0F; // Turn Off A/D's
TRISA = 0b00000000; // Set PORTA to output
TRISB = 0b00000000; // Set PORTB to output
TRISC = 0b00000000; // Set PORTC to output
PORTA = 0b00000000; // Clear PORTA port
PORTB = 0b00000000; // Clear PORTB port
PORTC = 0b00000000; // Clear PORTB port
SCLR = HIGH; // Set Shift Register clear High
int serial[];
while(1)
{
int serial[] = {0,1,1,1,1,1,1,1,1}; // Null 8,7,6,5,4,3,2,1
// row 1
sendSerial(serial);
RTN8 = LOW; // sink current bus 2
OUTEN = HIGH; // Output Enable lights off
RTN1 = HIGH; // sink current bus 1
pulseLatch();
OUTEN = LOW; // Output Enable lights on // stall(1);
// row 2
sendSerial(serial);
RTN1 = LOW; // sink current bus 2
OUTEN = HIGH; // Output Enable lights off
RTN2 = HIGH; // sink current bus 1
pulseLatch();
OUTEN = LOW; // Output Enable lights on // stall(1);
// row 3
sendSerial(serial);
RTN2 = LOW; // sink current bus 2
OUTEN = HIGH; // Output Enable lights off
RTN3 = HIGH; // sink current bus 1
pulseLatch();
OUTEN = LOW; // Output Enable lights on // stall(1);
// row 4
sendSerial(serial);
RTN3 = LOW; // sink current bus 2
OUTEN = HIGH; // Output Enable lights off
RTN4 = HIGH; // sink current bus 1
pulseLatch();
OUTEN = LOW; // Output Enable lights on // stall(1);
// row 5
sendSerial(serial);
RTN4 = LOW; // sink current bus 2
OUTEN = HIGH; // Output Enable lights off
RTN5 = HIGH; // sink current bus 1
pulseLatch();
OUTEN = LOW; // Output Enable lights on // stall(1);
// row 6
sendSerial(serial);
RTN5 = LOW; // sink current bus 2
OUTEN = HIGH; // Output Enable lights off
RTN6 = HIGH; // sink current bus 1
pulseLatch();
OUTEN = LOW; // Output Enable lights on // stall(1);
// row 7
sendSerial(serial);
RTN6 = LOW; // sink current bus 2
OUTEN = HIGH; // Output Enable lights off
RTN7 = HIGH; // sink current bus 1
pulseLatch();
OUTEN = LOW; // Output Enable lights on // stall(1);
// row 8
sendSerial(serial);
RTN7 = LOW; // sink current bus 2
OUTEN = HIGH; // Output Enable lights off
RTN8 = HIGH; // sink current bus 1
pulseLatch();
OUTEN = LOW; // Output Enable lights on // stall(1);
} // while
} // main