447
//Configuration bits #pragma config FOSC = HS // High-speed oscillator #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled) #pragma config BOREN = ON // Brown-out Reset Enable (BOR enabled) #pragma config LVP = OFF // Low-Voltage (single-supply) In-Circuit Serial Programming Enable (LVP disabled) #pragma config CPD = OFF // Data EEPROM Memory Code Protection (Data EEPROM code protection off) #pragma config WRT = OFF // Flash Program Memory Write Enable (Write protection off) #pragma config CP = OFF // Flash Program Memory Code Protection (Code protection off) #include <xc.h> #include <stdint.h> #include "config.h" #define _XTAL_FREQ 4000000 // IO Pins Definitions #define UP RB0 #define Down RB1 #define Send RB2 // Function Declarations void SPI_Master_Init(); void SPI_Write(uint8_t); // Function Definitions void SPI_Master_Init() { // Set SPI Mode To Master + Set SCK Rate To Fosc/64 SSPM0 = 0; SSPM1 = 0; SSPM2 = 0; SSPM3 = 0; // Enable The Synchronous Serial Port SSPEN = 1; // Configure Clock Polarity & Phase (SPI Mode Num. 1) CKP = 0; CKE = 0; // Configure Sampling Time (Middle) SMP = 0; // Configure IO Pins For SPI Master Mode TRISC5 = 0; // SDO -> Output TRISC4 = 1; // SDI -> Input TRISC3 = 0; // SCK -> Output } void SPI_Write(uint8_t Data) { SSPBUF = Data; // Transfer Data To Buffer Register }