Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MMC with PIC18F4550 using MiKroC

Status
Not open for further replies.

Nizar

New Member
Hi,

I am New in PIC Programing, but You helped me a lot to get my first step.
I bought the EasyPIC5 and the MMC/SD Card which is able to connect to PIC,AVR or 8051, but I couldn't get it working.
I don't now the problem, PIC18F4550 use PortB and PortC to connect to MMC card.
I tried to use the example on the MikroC ver. 8.0 but it is for PIC18F4520 with use PortC only.
If some body can help me in any kind I will appreciate it.

Thank you all
 
If I remember correctly, the MMC board from mikroE does not have level shifting so return data to the uC are 3V (and that 18F4550 runs on 5V). If you lower the voltage of the 18F4550 to 4.5V it will work or if you put a level shifter between mmc and port ...

you can also check forum.mikroe.com for more details as they provide "closed" libraries with mikroC so their forum is really the best place to get support for their products
 
But MMC with PIC18F4550 works on Proteus

Thank U for Your replay.

I'm Not bad at programing but I'm new in the field of embedded systems
The Program is working fine on Proteus.

Code:
void ReadCmd(char kp);
void ReadKey(void);

char canRead = 0;
unsigned int error;
const unsigned long sectorNo = 510;
char i=0;
unsigned short kp;
char *chNumbers = "123A456B789C*0#D";
char buffer[17];
char dataBuffer[sectorNo];

void main()
{
  CMCON = 0x07;             // turn off comparators
  ADCON1 = 0xFF;           // turn off analog inputs

  TRISA = 0x00;                         // PORTB is output
  TRISC = 0x00;
  TRISE = 0x00;
  //TRISB=0x00;

  Keypad_Init(&PORTD);
  Lcd_Custom_Config(&LATA,0,1,2,3,&LATE,2,1,0);  // Initialize LCD on PORTB
  Lcd_Custom_Cmd(LCD_CLEAR);       // Clear display
  Lcd_Custom_Cmd(LCD_CURSOR_OFF);  // Cursor off

  Spi_Init_Advanced(MASTER_OSC_DIV4, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);
  //Spi_Init();
  Delay_ms(1000);

  Lcd_Custom_Out(1, 1, "No MMC Card");

  //PortA.F6 = 1;
  LATA = 0x60;

  while(1)
  {
     if(Mmc_Init(&PORTB,6) == 0)
     {
        Lcd_Custom_Out(1, 1, "MMC connected");
        canRead = 1;
        ReadKey();
     }
  }

}//~!

void ReadCmd(char kp)
{
    switch(kp)
    {
       case '#':
       {
         strcpy(dataBuffer, buffer);
         error = Mmc_Write_Sector(sectorNo, dataBuffer);
         if(error == 0)
         {
           i=0;
           buffer[i]='\0';
           Lcd_Custom_Out(2, 1, "                ");
         }
       }break;
       case '*':
       {

         error = Mmc_Read_Sector(sectorNo, dataBuffer);
         if(error == 0)
         {
           strncpy(buffer, dataBuffer, 17);
           Lcd_Custom_Out(2, 1, buffer);
           i=strlen(buffer);
         }
       }break;
       default:
       {
          if(i<16)
          {
            buffer[i++]= kp;
            buffer[i]='\0';
            Lcd_Custom_Out(2, 1, buffer);
          }
       }
    }
}

void ReadKey(void)
{
   do {
    kp = 0;

    //--- Wait for key to be pressed
    do
      //--- un-comment one of the keypad reading functions
      kp = Keypad_Released();
      //kp = Keypad_Read();
    while (!kp);

    //--- print it on LCD

    //Lcd_Custom_Chr(1, 10, chNumbers[kp]);
    ReadCmd(chNumbers[kp]);
    //WordToStr(cnt, txt);

  } while (canRead);
}
 

Attachments

  • MMC_LCD_Keypad.JPG
    MMC_LCD_Keypad.JPG
    144.6 KB · Views: 9,958
If the code work on proteus and not on hw, the 3v-5v is what is messing what you... the output from mmc is 3v and input on pic is 5v .. you also do not have a voltage divider for pic to mmc .. you can "kill" some of the cards as some of them do not have 5v safe inputs ...

the proteus "ignore" all this problems .. it will work even if you remove the pull ups (in proteus) .. in real life - it will most probably kill the mmc ...

the pic to mmc lines - use voltage divider to get the signal from 5v to 3v
the mmc to pic line - either use some level shifter for 3-5 shift or lower the pic vcc, if you lower the pic vcc to 4.8V or 4.5V it will lower the threshold and 3v will be recognised as high signal.

check out the: https://www.electro-tech-online.com/custompdfs/2009/02/3_3vto5vAnalogTipsnTricksBrchr.pdf
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top