Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. sbit EN at PORTC.B2;
  2. sbit SCLK at PORTC.B3;
  3. sbit SDI at PORTC.B4;
  4. sbit SDO at PORTC.B5;
  5.  
  6. sbit EN_Direction at TRISC2_bit;
  7. sbit SCLK_Direction at TRISC3_bit;
  8. sbit SDI_Direction at TRISC4_bit;
  9. sbit SDO_Direction at TRISC5_bit;
  10.  
  11. // SPI Initialization Fucntion
  12.  
  13. void SPI_init(void){
  14.  
  15. INTCON |= 0xC0; // GIE and PEIE enable
  16. SSPSTAT.SMP = 0; // Sample at MIDDLE
  17. SSPSTAT.CKE = 1; // Data send on Rising Edge
  18. SSPCON |= 0x21; // Serial Port Enable, Idle state Clk is Low, Clock = Fosc/16 => 31 KBytes/sec
  19. SCLK_Direction=0;
  20. SDO_Direction =0;
  21. EN_Direction =0; // Output Ports
  22. SDI_Direction =1;
  23. EN = 1;
  24. }
  25.  
  26. // ============== Main function =============
  27.  
  28. void main(){
  29.  
  30. SPI_init();
  31. EN=0; // Active low signal
  32. SSPBUF = 0x85; // Hour Address
  33. while(SSPSTAT.BF == 0); // Adress Transmission not complete ? Stay here
  34. value=SSPBUF; // Read to Clear BufferFullStatusBit
  35. while(SSPSTAT.BF == 0); // Recieve byte not complete ? Stay here
  36. value=SSPBUF; // Store the recieved Byte
  37. EN=1; // Fininsh Reading
  38. PORTB=value; // Transfer byte to PORTB
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement