I haven't used the 18f452, but port A is analog by default on most PICs so you may need to disable analog functions. Most compilers have a command for it.
Also, you don't have your pins configured properly. CS, CLK, and DO are controlled by the PIC, because they're sending data to the SD card. So they should be....input or output?
DI is controlled by the SD card and read into the PIC, so it should be set to...input or output?
Remember, for the TRIS registers, "1" means input.
Then, for the init sequence, this:
Code:
for(i=0; i<11; i++){ // 0xFF for 10 times then carried low
PORTA=0xFF;
}
Doesn't do anything. Or rather, it doesn't do anything productive. It sets all of the PORTA pins to high. The 0xFF x 10 has to be shifted out via CLK and DO, which is what the puts_SPI command does.
Then, you're going to need to read up on the OpenSPI() command, I don't use C for PICs and don't know about the SPI library so I can't say what that function does. But after the 0xFF x 10 there needs to be a 6-byte sequence sent (0x40, 0, 0, 0, 0, 0x95).
Then you check for a response (should be 0x01).
Then you send another 6-byte sequence: (0x41, 0, 0, 0, 0, 0xFF).
...Sorry, guy, but you might be in over your head here. You should probably look into the compiler documentation to see if there's a library for using SD cards.
Mike