i have problem programming pic18f4520 also interfacing with 74hc595 shift regiter

Status
Not open for further replies.
Hi,

Code:
/* 22:07 25 April 2013
*  https://www.electro-tech-online.com/threads/i-have-problem-programming-pic18f4520-also-interfacing-with-74hc595-shift-regiter.134254/
*  E:\Electronics\PIC Projects\Electrotech\saaiim 4525_74HC595_SPI\Source\Main V3.c
*  MPLAB C18 v3.45
*  PIC18F4520
*  
*  Read PORTA and send image to 74HC595 parallel outputs using SPI
*
*  Tested OK 01:19 26/04/2013
*/

#include <p18F4520.h>
#include <delays.h>

/*------------------------------------------------------------------------*/

#pragma config OSC = INTIO67
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOREN = OFF
#pragma config WDT = OFF
#pragma config PBADEN = OFF
#pragma config LPT1OSC = OFF
#pragma config MCLRE = ON
#pragma config STVREN = OFF
#pragma config LVP = OFF
#pragma config XINST = OFF

/*------------------------------------------------------------------------*/

#define rx_buffer_full  (SSPSTATbits.BF)

/*------------------------------------------------------------------------*/

char null_data;

/*------------------------------------------------------------------------*/

void SPI_init (void);

/*------------------------------------------------------------------------*/
void main (void)
{
    OSCCON = 0b01100010;            // Fosc = 4MHz (Inst. clk = 1MHz)
    ADCON1 = 0xF;                   // No analog, all digital i/o
    TRISA = 0xff;                   // DIL switch inputs
    LATA = 0x0;

    SPI_init();                     // Set up the SPI

/********* Start of main loop **********/

 while(1)
{
    SSPBUF = PORTA >> 6 | PORTA << 2 ;  // SPI byte to be txd is on PORTA
    while (!rx_buffer_full);            // Wait until buffer is full (tx done)
    null_data = SSPBUF;                 // Read buffer to clear BF flag

    Delay10KTCYx(25);

    }
 }
/*------------------------------------------------------------------------*/
void SPI_init (void)
{
    SSPSTAT = 0b10000000;       // b7 = SMP: Sample bit
                                // b6 = CKE: SPI ClK Select bit
                                // b5-1 = I2C mode only
                                // b0 = BF: Buffer Full Status bit (rx mode only)

    SSPCON1 = 0b00100000;       // b7 = WCOL: Write collision detect
                                // b6 = SSPOV: Receive Overflow Indicator bit
                                // b5 = SSPEN: Synchronous Serial Port Enable
                                // b4 = CKP: Clock Polarity Select
                                // b3-0 = SSPM: Synchronous Serial Port Mode Select bits

    TRISCbits.TRISC5 = 0;       // [pic pin24] SPI data out
    TRISCbits.TRISC3 = 0;       // [pic pin18] SPI clock out

}


**broken link removed**

**broken link removed**
 
Last edited:
thanks for reply responce basicaly i want to display just a single charachter on led matrics e.g i want to display B on led matrix then what will be its programming i have used port d for data
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…