hi everybody ..
I hope I find my needs in this great board ..
Now I am trying to initialize MMC SanDisk 1GB using my own code (without using mikroC library) with PIC16F877A ..
When the card is initialized, I want my GLCD to display the word "Ready", otherwise I want to display "Initializing ..." ..
before anything, I want to display "WELCOME" ..
the GLCD is functioning properly alone, but with my code, the glcd displays nothing ..
here is my code:
Code:
//module connection
char GLCD_DataPort at PORTD;
sbit GLCD_CS1 at RB0_bit;
sbit GLCD_CS2 at RB1_bit;
sbit GLCD_RS at RB2_bit;
sbit GLCD_RW at RB3_bit;
sbit GLCD_EN at RB4_bit;
sbit GLCD_RST at RB5_bit;
sbit GLCD_CS1_Direction at TRISB0_bit;
sbit GLCD_CS2_Direction at TRISB1_bit;
sbit GLCD_RS_Direction at TRISB2_bit;
sbit GLCD_RW_Direction at TRISB3_bit;
sbit GLCD_EN_Direction at TRISB4_bit;
sbit GLCD_RST_Direction at TRISB5_bit;
// Software SPI module connections
sbit SoftSpi_SDI at RC4_bit;
sbit SoftSpi_SDO at RC5_bit;
sbit SoftSpi_CLK at RC3_bit;
sbit SoftSpi_SDI_Direction at TRISC4_bit;
sbit SoftSpi_SDO_Direction at TRISC5_bit;
sbit SoftSpi_CLK_Direction at TRISC3_bit;
// End Software SPI module connections
void sendCommand(int cmdIndex); //function prototype
void main() {
unsigned char Response;
Soft_SPI_Init(); // Init Soft_SPI
Glcd_Init(); //Init. GLCD
// Glcd_Set_Font(font5x7 , 5, 7, 32);// Change font
Glcd_Fill(0x00); //Clear GLCD
Glcd_Write_Text("WELCOME",0,0,1);
TRISC.B1=0; //Make RC2 output pin (CS or SS Pin)
PORTC.B1=0; //Hold CC=0
delay_ms(4); //Delay about 75 clock pulses at 20KHz
sendCommand(0x00); //CMD0 for S/W reset
Init:sendCommand(0x37); //CMD55 to tell that the next command is Application Specific
sendCommand(0x29); //ACMD41 to Initialize the SD Card
Response= Soft_Spi_Read(0x00);
if (Response==0x00)
{
Glcd_Fill(0x00); //Clear GLCD
Glcd_Write_Text("Ready !!",20,4,1);
}
else
{
Glcd_Fill(0x00);
Glcd_Write_Text("Initializing ...",20,4,1);
goto Init;
}
}
void sendCommand(int cmdIndex)
{
Soft_Spi_Write(0x40+cmdIndex); //Send command of index cmdIndex
Soft_Spi_Write(0x00); //Send 4
Soft_Spi_Write(0x00); //Clear Bytes
Soft_Spi_Write(0x00); //As
Soft_Spi_Write(0x00); //Argument
Soft_Spi_Write(0x95); //CRC = 0x95 for CMD0 and not important for SPI mode
}
also I am asking about the red number, this function is to read data from spi bus, why do we need to assign data to send ..?
Great thanks to everybody ..
I hope I find my needs in this great board ..
Now I am trying to initialize MMC SanDisk 1GB using my own code (without using mikroC library) with PIC16F877A ..
When the card is initialized, I want my GLCD to display the word "Ready", otherwise I want to display "Initializing ..." ..
before anything, I want to display "WELCOME" ..
the GLCD is functioning properly alone, but with my code, the glcd displays nothing ..
here is my code:
Code:
//module connection
char GLCD_DataPort at PORTD;
sbit GLCD_CS1 at RB0_bit;
sbit GLCD_CS2 at RB1_bit;
sbit GLCD_RS at RB2_bit;
sbit GLCD_RW at RB3_bit;
sbit GLCD_EN at RB4_bit;
sbit GLCD_RST at RB5_bit;
sbit GLCD_CS1_Direction at TRISB0_bit;
sbit GLCD_CS2_Direction at TRISB1_bit;
sbit GLCD_RS_Direction at TRISB2_bit;
sbit GLCD_RW_Direction at TRISB3_bit;
sbit GLCD_EN_Direction at TRISB4_bit;
sbit GLCD_RST_Direction at TRISB5_bit;
// Software SPI module connections
sbit SoftSpi_SDI at RC4_bit;
sbit SoftSpi_SDO at RC5_bit;
sbit SoftSpi_CLK at RC3_bit;
sbit SoftSpi_SDI_Direction at TRISC4_bit;
sbit SoftSpi_SDO_Direction at TRISC5_bit;
sbit SoftSpi_CLK_Direction at TRISC3_bit;
// End Software SPI module connections
void sendCommand(int cmdIndex); //function prototype
void main() {
unsigned char Response;
Soft_SPI_Init(); // Init Soft_SPI
Glcd_Init(); //Init. GLCD
// Glcd_Set_Font(font5x7 , 5, 7, 32);// Change font
Glcd_Fill(0x00); //Clear GLCD
Glcd_Write_Text("WELCOME",0,0,1);
TRISC.B1=0; //Make RC2 output pin (CS or SS Pin)
PORTC.B1=0; //Hold CC=0
delay_ms(4); //Delay about 75 clock pulses at 20KHz
sendCommand(0x00); //CMD0 for S/W reset
Init:sendCommand(0x37); //CMD55 to tell that the next command is Application Specific
sendCommand(0x29); //ACMD41 to Initialize the SD Card
Response= Soft_Spi_Read(0x00);
if (Response==0x00)
{
Glcd_Fill(0x00); //Clear GLCD
Glcd_Write_Text("Ready !!",20,4,1);
}
else
{
Glcd_Fill(0x00);
Glcd_Write_Text("Initializing ...",20,4,1);
goto Init;
}
}
void sendCommand(int cmdIndex)
{
Soft_Spi_Write(0x40+cmdIndex); //Send command of index cmdIndex
Soft_Spi_Write(0x00); //Send 4
Soft_Spi_Write(0x00); //Clear Bytes
Soft_Spi_Write(0x00); //As
Soft_Spi_Write(0x00); //Argument
Soft_Spi_Write(0x95); //CRC = 0x95 for CMD0 and not important for SPI mode
}
also I am asking about the red number, this function is to read data from spi bus, why do we need to assign data to send ..?
Great thanks to everybody ..