Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

microC pro file handling, how to save image in sd card

Status
Not open for further replies.

rmarkespanto

Junior Member level 1
Joined
Jan 30, 2012
Messages
18
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,293
Location
phillippines
Activity points
1,401
Someone help me guys for the codings of my project.. specially in file handling... i want to save a jpeg image in my sd card using pic18f4550 from a serial camera, w/c is a uart interface.... Help me how to use the mmc and spi library, for saving my image data,256 bytes per package... please some one help me....:cry::cry::cry::cry::cry::idea:
 

First of All you must LEarn how to interface and MMC card and Initialize it..


Here is a Sample Code Written By me MikroC to do some basic Opertaion..

Code:
/*********************SECURE DIGITAL CARD PROJECT************************/
/************************************************************************/
/*
  CS  is Connected to RC2
  CLK is Connected to RC3
  DO  is Connected to RC4
  DI  is Connected to RC5

The program reads the SD card CID register parameters and sends it to a PC via the serial interface.
This process is repeated at every 10 seconds.

*/
/*************************** MMC MODULE CONNECTION*************************/

sfr sbit Mmc_Chip_Select at RC2_bit;
sfr sbit Mmc_Chip_Select_Direction at TRISC2_bit;

/**************************************************************************/

/***********************Function For New Line******************************/
void NewLine()
{
 UART1_Write(10);                //Line Feed
 UART1_Write(13);                //Carriage Return
}
/**************************************************************************/

/**********************MAIN PROGRAM STARTS FROM HERE***********************/

unsigned char error, CID[16];         //CID means Card Identification Register
unsigned char msg[] = "SD Card CID Register";
unsigned int i;
unsigned short x;
unsigned char Data1[512],Data2[512];         //These Variables are used to Store and Receive Data in SD Card
void main()
{
 
 //Configure the Serial Port
 
 UART1_Init(9600);      //Set Baud Rate of 2400bps
 
 //Initialize the Secure Digital Card
 //Set SPI1 module to master mode, clock = Fosc/16, data sampled at the middle of interval,
 //clock idle state low and data transmitted at low to high edge:

 SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV16,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
 
 //Initialize the Secure Digital Card Bus
 //And Check Whether it gets Initialized or Not
 //If Not then try again and Again
 // memory_card_not_detected:
 
 while(Mmc_Init() != 0)
 {
  NewLine();
  UART1_Write_Text("Memory Card Not Detected");
 }
 
  NewLine();
  UART1_Write_Text("Memory Card Detected Successfully!!");
  
  //If Memory Card Detected Successfully
 
  NewLine();
  UART1_Write_Text(msg);
  while(Mmc_Read_CID(CID) != 0)
  {
   NewLine();
   UART1_Write_Text("CID Value Not Found");
   NewLine();
  }
  NewLine();
  UART1_Write_Text("CID Values are Obtained");
  NewLine();
  //Now we will loads sector 10 of the SD card with character "A".
  //The contents of sector 10 is then read and sent to the UART,
  //displaying 512 "A" characters on the PC display.
  
  UART1_Write_Text("Now Time To Write Some Data in the SD Card");
  for(i=0;i<20;i++)
  {
   NewLine();
  }
  //The Above For Loop Clear the Hyper-Terminal Screen
  
  //Now Fill the Buffer with Character "A"
  for(i=0;i<512;i++)
  {
   Data1[i] = "A";
  }
  //After this the Data1 buffer gets Filled with "A" Character
  //Now write this buffer to SD Card Sector
  
  x = Mmc_Write_Sector(10,Data1);    //Writing Data to 10th Sector
  //We Can Check Here whether Writing was Successful or not by Monitoring the Value x
  if(x == 0)
  {
   UART1_Write_Text("Write Successfull");
   Newline();
  }
  
  //Now Read The Data From Sector-10 of SD Card
  x = Mmc_Read_Sector(10,Data2);     //Read data From Sector-10 of SD card and Store the Result in Data2
  if(x == 0)
  {
   UART1_Write_Text("Read Successfull");
   Newline();
  }
  //Display the Result on Hyper-Terminal
  
  for(i=0;i<10;i++)
  {
   UART1_Write(Data2[i]);
  }
  

 while(1);              //Stop Code Here for Debugging Purpose*/
}

Edit this Code and use it with your memory card..
after that try to write some data, then after you can save your image..

Hope this Helps..
 

thanks and have more blessing bro... Are you also using pic18f4550, what if the pin for rx and sdo are in only one pin... do you have a solution for this bro???
 

Actually this is For PIC18F452

You can change your Code Accordingly..
what if the pin for rx and sdo are in only one pin... do you have a solution for this bro???

Are you using a Development Board..
If not you can change your connection..

And in my code I haven't used the Rx(UART) pin only transmit pin is used..

What ever Thing i got from MMC Card.. I put that on Serial Port..

Hope You Understand..
In my code there is no need to use Rx(UART) pin
 

can you please explain to me, how data from sd card have been put on serial port, and vice versa... thanks a lot...
:idea:
 

Do You have basic Knowledge of SD MMC Cards..


You have to read data from Memory Sectors...
I think first of all you have to learn basics of SD and MMC Card and SPI...

can you please explain to me, how data from sd card have been put on serial port, and vice versa... thanks a lot...

MikroC has inBuilt function to do this...
My Advice for you is to learn basics of SD card..

Do you understand my Code...
If Not which part..
Post that part i will explain it to u..
 
thanks for the help.. and also for the code... can i us again a question, i have continnous 256bytes package of an image from serial camera, i want to store it every loop, or every package to sd card... like for example..

while(total_number_of_package!=0)
{
unsigned char image_data[];
i=0;
while(i<256)
{
if(UART_Data_Ready()==1)
{
image_data=UART_Read(); \\1 byte every loop
}
}
}

were im going to put my call function for the 256 byte of image data, in an array.. To get data from that array store to sd card... because in my pic18f4550, i have a limited of 2kb of memory... please help me bro....

---------- Post added at 17:26 ---------- Previous post was at 17:20 ----------

i mean is, how to put the image data package in sd card per package of 256 bytes.... Is this possible bro..??

You have to read data from Memory Sectors...
I think first of all you have to learn basics of SD and MMC Card and SPI...
do you have any tutorial for theory of sd card, or how it is function.. i have many research, but it is so hard to understand,
i want is how is data inserted in that mmc/sd card..

thanks a lot bro....
 

Code:
while(total_number_of_package!=0)
{
unsigned char image_data[];
i=0;
while(i<256)
{
if(UART_Data_Ready()==1)
{
image_data[i]=UART_Read(); \\1 byte every loop
}
}
}


This is your code...
What is Total_Number_Of_Pacakage
you have used image_data[]
in you while loop.. i think it is not correct

Do this hope this works

Code:
unsigned char x,image_data[256];
unsigned int i;
for(i=0;i<256;i++)
{
      if(UART1_Data_Ready() == 1)
      {
              image_data[i] = UART1_Read();
      }
}

 x = Mmc_Write_Sector(10,image_data);    //Writing Data to 10th Sector
  //We Can Check Here whether Writing was Successful or not by Monitoring the Value x
  if(x == 0)
  {
   UART1_Write_Text("Write Successfull");
   Newline();
  }

I know there is only 2Kbyte space in PIC18F4550..
But my advice is to do this.. if this works then it okay..
Other wise i will think something else for you...

Hope this helps
[/CODE]

---------- Post added at 22:11 ---------- Previous post was at 22:00 ----------

Pls Give me you email id..
I will mail you...
The stuff related to this..
 
thanks bro... it helps me a lot... i think i can make my thesis succesful, because of you... can i ask again.. what is the cid register and csd register in the mmc library of microC...???? this is my email adress... anglongz_21@yahoo.com

---------- Post added at 21:44 ---------- Previous post was at 21:34 ----------

the calculation for number of package is # image package=image size/(package size-6)... this formula is from the data sheet of my serial camera, package size can support 64bytes to 512bytes.....

Thank you very much... More blessings come to you...:razz::razz::razz::razz::razz::razz::razz::razz:

runmark
 

I am sending you a mail regarding SD Cards Tutorial using MikroC it is having a full description.

Have a look on it..
That will be extremely helpful to you...
My Email Id is arunsharma0731@gmail.com

If you don't have any problem in sending your thesis to me.. then pls mail me...
 
it is my project study, a camera that you can interface to uart communication.... as simple a serial camera... my serial camera model is c328... you just going to research the datasheet... for now im just going to finish my thesis....


regards
runmark
 

Arun Sharma


this is my circuit, im just using a simulator... but this is the output.. can you help me...

the help.jpg--- before im going to run my proteus
the help2.jpg--after i run my proteus..



but im going to try it in actual and change the pic18f4520 to pic18f4550...
can you please, help me for the circuit.. maybe i have wrong connection.. i will wait for your reply... i will post later for the actual cicuit for my serial camera interface to sd card, if i tested it succesful...


runmark
 

Attachments

  • help.jpg
    help.jpg
    450.4 KB · Views: 133
  • help2.jpg
    help2.jpg
    457.2 KB · Views: 118

Sure I will help you...

But there is nothing to worry with the Connection Diagram...
Do it similar as it is in PIC you have used..
Otherwise inform me..

But i want to ask a question from you...
How will you know whether the Image Written by you is Properly Written..

I mean to say that do you have any display device.. to show the Image when extracted from the SD Card..
Or you will read it in your PC or any other device having a Memory Card Slot..

Actually few days back.. i though to develop a device with which i can play my movies on Graphical LCD..
But fails due to lack of time..

Thats why i am helping you...
 

But i want to ask a question from you...
How will you know whether the Image Written by you is Properly Written..

I mean to say that do you have any display device.. to show the Image when extracted from the SD Card..
Or you will read it in your PC or any other device having a Memory Card Slot..


for a while the image will be store on that sd card, if there is a person/human sensor activated, serial camera keeps on capturing image.., while my gsm/gprs modem device is keep on texting the situation of the monitored place/or the servo motor rotation or what is the location of the person,.. until i want to get image through my cellphone just for a text.. like "send me image1.jpg".... so that i know the real situation.. if there is a thief or any harm person entering my house or any place intalling my device...


and for another purpose, it is a stand alone camera.. or a survillance camera that never need a reciever like computer...

regards
runmark
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top