PIC167877A with 74HC595 Shift Register using SPI

407 Views Asked by At

HI I'm trying to implement simple spi communication to turn on 8 led connected to shift register can amy one help me whats wrong with this code, im getting random output, I want to send 0x02 to turn on led(00000010) .

#include <xc.h>
#include "spi.h"
#pragma config WDTE = OFF  // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF   // Low-Voltage In-Circuit Serial Programming Enable bit
#pragma config CPD = OFF   // Data EEPROM Memory Code Protection bit 
#pragma config WRT = OFF   // Flash Program Memory Write Enable bits 
#pragma config CP = OFF    // Flash Program Memory Code Protection bit
#define _XTAL_FREQ 8000000
void main()
{
        char data = 0x10;
        spiInit(SPI_MASTER_OSC_DIV4, SPI_DATA_SAMPLE_END, SPI_CLOCK_IDLE_LOW, SPI_IDLE_2_ACTIVE);
        TRISC0 = 0;
        RC0 = 1;
        RC3 = 0;
        RC5 = 0;
        while(1)
        {
                RC0 = 0;       //Slave Select
                __delay_ms(100);
                spiWrite(data);
                while(!SSPSTATbits.BF);
                __delay_ms(100);
                RC0= 1;       //Slave Deselect 
        }
}
0

There are 0 best solutions below