// SerialRAM connections
sbit Chip_Select at RC7_bit;
sbit HOLD at RC6_bit;
sbit Chip_Select_Direction at TRISC7_bit;
sbit HOLD_Direction at TRISC6_bit;
// End SerialRAM connections
unsigned int i;
unsigned short tmp;
// Write one byte of data to specified address
void Write_Data(unsigned int address, unsigned short dat){
Chip_Select = 0; // Select SerialRAM
SPI1_Write(2); // Write instruction
SPI1_Write(address >> 8); // Sending 16 bits address
SPI1_Write(address);
SPI1_Write(dat); // Writing one byte of data
Chip_Select = 1; // Deselect SerialRAM
}
// Read one byte of data from specified address
unsigned short Read_Data(unsigned int address){
Chip_Select = 0; // Select Serial RAM
SPI1_Write(3); // Read instruction
SPI1_Write(address >> 8); // Sending 16 bits address
SPI1_Write(address);
tmp = SPI1_Read(0); // Read one byte of data
Chip_Select = 1; // Deselect SerialRAM
return tmp;
}
void InitRAM() {
Chip_Select_Direction = 0; // Set CS# pin as Output
Chip_Select = 1; // Deselect SerialRAM
SPI1_Init(); // Initialize SPI module
HOLD_Direction = 0; // Set HOLD# pin as output
HOLD = 1;
} // Hold high when this function is not used
void TestRAM()
{
InitRAM();
Write_Data(1 + 0x0A00, 0xBB);
}
(TestRAM is called from main elsewhere)