#include "../mscbemb.h"#include "SPI_handler.h"Functions | |
| void | SPI_Init (void) |
| void | SPI_ClockOnce (void) |
| void | SPI_WriteByte (unsigned char dataToSend) |
| void | SPI_WriteUInt (unsigned int dataToBeSend) |
| unsigned char | SPI_ReadByteRising (void) |
Variables | |
| sbit | SPI_SCK = MSCB_SPI_SCK |
| sbit | SPI_MISO = MSCB_SPI_MISO |
| sbit | SPI_MOSI = MSCB_SPI_MOSI |
| void SPI_ClockOnce | ( | void | ) |
Generating the SPI communication clock."SFRPAGE = SPI0_PAGE" makes sure that we are in the right page to properly communicate with the SPI protocol.
00059 { 00060 SFRPAGE = SPI0_PAGE; 00061 delay_us(SPI_DELAY); 00062 SPI_SCK = 1; 00063 delay_us(SPI_DELAY); 00064 SPI_SCK = 0; 00065 }
| void SPI_Init | ( | void | ) |
| unsigned char SPI_ReadByteRising | ( | void | ) |
00144 { 00145 signed char i = 0; 00146 unsigned char din = 0; 00147 unsigned char dataReceived = 0; 00148 00149 SFRPAGE = SPI0_PAGE ; 00150 for(i = 7; i >= 0; i--) 00151 { 00152 delay_us(SPI_DELAY); 00153 din = SPI_MISO; 00154 dataReceived |= (din << i); 00155 SPI_SCK = 1; 00156 delay_us(SPI_DELAY); 00157 SPI_SCK = 0; 00158 00159 } 00160 return dataReceived; 00161 }
| void SPI_WriteByte | ( | unsigned char | dataToSend | ) |
Performing SPI write operation.One byte of data transmits in a bit wise fashion
| dataToSend | One byte of information which has to be sent via SPI protocol. |
00077 { 00078 signed char i; 00079 00080 SFRPAGE = SPI0_PAGE ; 00081 for(i = 7; i >= 0; i--) { 00082 SPI_MOSI = (dataToSend >> i) & 0x01; 00083 SPI_ClockOnce(); 00084 } 00085 SPI_MOSI = 0; 00086 }
| void SPI_WriteUInt | ( | unsigned int | dataToBeSend | ) |
Performing SPI write operation.Two bytes of data transmits in a bit wise fashion
| dataToSend | Two byte of information which has to be sent via SPI protocol. |
00099 { 00100 signed char i; 00101 00102 SFRPAGE = SPI0_PAGE ; 00103 00104 for(i = 15; i >= 0; i--) { 00105 SPI_MOSI = (dataToBeSend >> i) & 0x01; 00106 SPI_ClockOnce(); 00107 } 00108 SPI_MOSI = 0; 00109 }
| sbit SPI_MISO = MSCB_SPI_MISO |
| sbit SPI_MOSI = MSCB_SPI_MOSI |
| sbit SPI_SCK = MSCB_SPI_SCK |
Setting the related pins of SPI protocol
1.4.7