Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sbit EN at PORTC.B2;
- sbit SCLK at PORTC.B3;
- sbit SDI at PORTC.B4;
- sbit SDO at PORTC.B5;
- sbit EN_Direction at TRISC2_bit;
- sbit SCLK_Direction at TRISC3_bit;
- sbit SDI_Direction at TRISC4_bit;
- sbit SDO_Direction at TRISC5_bit;
- // SPI Initialization Fucntion
- void SPI_init(void){
- INTCON |= 0xC0; // GIE and PEIE enable
- SSPSTAT.SMP = 0; // Sample at MIDDLE
- SSPSTAT.CKE = 1; // Data send on Rising Edge
- SSPCON |= 0x21; // Serial Port Enable, Idle state Clk is Low, Clock = Fosc/16 => 31 KBytes/sec
- SCLK_Direction=0;
- SDO_Direction =0;
- EN_Direction =0; // Output Ports
- SDI_Direction =1;
- EN = 1;
- }
- // ============== Main function =============
- void main(){
- SPI_init();
- EN=0; // Active low signal
- SSPBUF = 0x85; // Hour Address
- while(SSPSTAT.BF == 0); // Adress Transmission not complete ? Stay here
- value=SSPBUF; // Read to Clear BufferFullStatusBit
- while(SSPSTAT.BF == 0); // Recieve byte not complete ? Stay here
- value=SSPBUF; // Store the recieved Byte
- EN=1; // Fininsh Reading
- PORTB=value; // Transfer byte to PORTB
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement