Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > General Electronics Chat


General Electronics Chat This forum is for general chat about electronics, eg: Dont know what a part does? Dont know how to read a circuit? Want to get an opinion?

Reply
 
LinkBack Thread Tools Display Modes
Old 24th July 2007, 07:44 AM   (permalink)
Red face >> Can Anybody Explain This Code For Me? :(

hi all ... i'm involving with a project of reading data from a SD card using microcontroller. i have came across a coding which i have downloaded from internet and unfortunately the comments in written in that coding is not in English language... :cry: :cry:

so can any one please explain this code for me...Thnx in advance... :wink: :roll:




Please EXPLAIN THIS AS SOON AS POSIBLE IF U ARE ABLE...i have marked the comment mark , " //" where i need explanation.. so feel free to help me... thnx...






#include <D:\cc5\16F877.H>
#pragma config |= 0b.11.111101.11.00.10
#pragma bit CS @ PORTC.2 //Ausgang für Chip Select

uns16 AL, BytN,ByteLes,Claster,FAT,Verz,Dat; //
char AH ;

#pragma origin 100

//************************************************** ****************************
void InitUSART()
{
BRGH=1;
SPBRG=129; // (9600 baud @ 20MHz input clock)
SPEN = 1; // Set_Serial_Pins;
SYNC = 0; // Set_Async_Mode;
TX9 = 0; // Set_8bit_Tx;
RX9 = 0; // Set_8bit_Rx;
CREN = 1; // Enable_Rx;
TXEN = 1; // Enable_Tx;
RCIE=0; // Rx Interrupt aus
}

//************************************************** ************************
void SerString(const char *str) //
{
char ps;
ps = *str; //
while(ps>0) //
{
str++; //
if (ps== 0) break; //
while(!TXIF); //
TXREG =ps ; //
ps = *str; //
}
}

//************************************************** ***************************
char SPI(char d) //
{ //
SSPBUF=d;
while (!BF); //
return SSPBUF; //
}

//************************************************** ****************************
char Command(char befF,uns16 AdrH,uns16 AdrL,char befH ) //
{
char a;
for (a=0;a<9;a++)
{
Carry=0; //
AdrL = rl(AdrL); //
AdrH = rl(AdrH); //
}
SPI(0xFF); //
SPI(befF); //
SPI(AdrH.high8); //
SPI(AdrH.low8); //
SPI(AdrL.high8); //
SPI(AdrL.low8); //
SPI(befH); //
SPI(0xFF); //
return SPI(0xFF); //
}

//************************************************** **************************
bit MMC_Init()
{
SMP=0; //
CKE=0; //
CKE=1; //
CKP=1; // CKP=0; //
SSPM0=1;
SSPEN=1; //
CS=1; //
char i; //
for(i=0; i < 10; i++)SPI(0xFF);
CS=0;
if (Command(0x40,0,0,0x95) !=1)goto Fehler ;
st:
if (Command(0x41,0,0,0xFF) !=0) goto st ;
return 1;
Fehler:
return 0;
}

//************************************************** *********************************
void Byte_lesen (void)
{
bit zw;
char a;
int16 i;
zw=0;
Command(0x51,AH,AL,0xFF);
while(SPI(0xFF) != 0xFE); //
for(i=0; i < 512; i++) //
{
a=SPI(0xFF);
if (zw)
{
ByteLes.high8=a; //
zw=0;
}
if (i==BytN) //
{
ByteLes.low8=a;
zw=1;
}

}
SPI(0xFF); //
SPI(0xFF);
}

//************************************************** ****************************
void Suche(const char *wort) //
{
uns16 i,L,N;
bit gef;
char a,m,b;
gef=0;
m=0;
N=Verz+32; //
for (L=Verz;L<N;L++) //
{
Command(0x51,0,L,0xFF); //
while(SPI(0xFF) != 0xFE); //
for(i=0; i < 512; i++)
{
a=SPI(0xFF) ;
b=wort[m];
if(a==b)
{
m++;
if(!wort[m])
{
SerString("Gefunden ");
m=0;
BytN=i;
AL=L;
AH=0;
gef=1;
}
goto fu;
}

m=0;
fu:
}
SPI(0xFF); //
SPI(0xFF);
if(gef) goto raus;
}
raus:
SerString("Beendet ");
BytN+=16;
Byte_lesen();
}

//************************************************** *****************************
void Lesen(char H,uns16 L)
{
uns16 i; //
if (Command(0x51,H,L,0xFF) !=0) SerString("Lese_resp_Fehler");
while(SPI(0xFF) != 0xFE); //
for(i=0; i < 512; i++)
{
while(!TXIF); //
TXREG =SPI(0xFF); //
}
SPI(0xFF); //
SPI(0xFF);
}

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

void main(void)
{
uns16 temp;
INTCON=0; //
ADCON1=0x6; //
TRISC=0b.1101.0011; //
TRISB=0b.0000.0010; //
InitUSART(); //
//SerString("Ich bin ON "); //
MMC_Init(); //

//
AL=0; // 3
AH=0;
BytN=0x1C6;
Byte_lesen();
AL=ByteLes; // 4
BytN=0xE; // 5
Byte_lesen();
FAT=ByteLes+AL; // 6
BytN=0x16; // 7
Byte_lesen();
ByteLes=ByteLes*2;
Verz=FAT+ByteLes; // 8
Dat=Verz+32; // 9, 10


Suche("TEST TXT"); // 11

while(ByteLes != 0xFFFF)// 12, 25
{
Claster=ByteLes; // 13
Claster=Claster-2; // 14
AL=Claster; // 15
Carry=0; // 16
AL = rl(AL); //
AH = rl(AH);


#asm // 17
MOVF Dat+1,W
ADDWF AL+1,1
MOVF Dat,W
ADDWF AL,1
BTFSS 0x03,Carry
GOTO keinCarry
BCF 0x03,Carry
INCF AL+1,1
BTFSC 0x03,Carry
INCF AH,1
keinCarry:
#endasm

Lesen(AH,AL); // 18 Erste Block des Clasters
Carry=0; // 19
AL++;
if(Carry)AH++; // Hier werden Grenzen der wariable berücksichtigt
Lesen(AH,AL); // 20 Zweite Block des Clasters

AL=FAT; // 21 nexte Claster
temp=ByteLes/0x100;
AL=AL+temp; // 22
temp=temp*0x100; // 23
BytN=ByteLes-temp;
BytN=BytN*2;
Byte_lesen(); // 24
}

while(1);
}



ur help of getting me through the project is appreciated
chamith20xx is offline  
Old 24th July 2007, 07:56 AM   (permalink)
Default

Quote:
Originally Posted by chamith20xx
i have came across a coding which i have downloaded from internet and unfortunately the comments in written in that coding is not in English language...
Use a language translator tool & get the idea.There are plenty on the web.
Suraj143 is offline  
Old 24th July 2007, 09:56 AM   (permalink)
Default

looks like German maybe ...
__________________
************************************************** *****************
john1 is offline  
Old 24th July 2007, 11:00 AM   (permalink)
Default

It appears to be some code for handling an MMC Memory Card. Code is code and you really should not need the comments especially for things like initializing the UART and the SPI Port. A FAT is a file allocation table and it gives you information on the files on the MMC card. This program would be more understandable if you knew what the format of the data on an MMC card was. Do you know anything about MMC cards? I personally don't know much more about them then I've already written.

The comments are in German so you should be able to decode them with a German English dictionary. Give it a go, it's actually fun poking into another language.
Papabravo is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Accessing EEPROM Clayton Micro Controllers 15 23rd March 2007 04:00 AM
Need some help with a code provided by ATMEL ikalogic Micro Controllers 1 23rd January 2007 03:46 PM
Code not working..help Electrix Micro Controllers 15 26th September 2005 12:12 PM
Tough assembly program for the PIC16F84 asmpic Micro Controllers 34 3rd December 2004 07:50 PM
An error in pic16f84a, why? Zener_Diode Micro Controllers 6 11th April 2004 03:55 AM



All times are GMT. The time now is 08:58 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker