Autor Tema: ayuda leer SD en ccs  (Leído 5740 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado BEXTIXTOX

  • PIC16
  • ***
  • Mensajes: 108
ayuda leer SD en ccs
« en: 22 de Septiembre de 2014, 03:02:41 »
colegas del foro comienzo a trabajar con las memorias sd
intento escribir y leer un archivo TXT asta ahorita solamente he podido escribir en la memoria sd un txt y agregarle datos  ;-)
pero no consigo leer ese mismo txt que escribi o cual sea
he seguido el tema de ZUKY pero en los ejemplos solo escriben en las memorias no las leen
utilizo una memoria sd en fat16 de 1gb
ccs 5.007
pic18f4550
proteus 7.9
nokia 3310
las libreias que utilizo de suky son las verciones 1.8 y 1.5

alguien tiene un ejemplo de una lectura en memoria SD??
 

Desconectado BEXTIXTOX

  • PIC16
  • ***
  • Mensajes: 108
Re: ayuda leer SD en ccs
« Respuesta #1 en: 25 de Septiembre de 2014, 04:26:43 »
MMM... sin respuestas aun
tengo algunas dudas
la libreria FAT16.C (1. 8 ) es igual o menor que  FAT16_SDCard.c (1.5)???

mi codigo va algo asi
 
    if(FAT_FindFileDir(SFN,0,ARCHIVO,SectFound,FAddDir,FNClus,FSizeFile)==0){
     printf("  ARCHIVO LOCALIZADO\r\n");              //  localizado!!!
    
      Status=FAT_OpenFileAndRead(SFN,DirectorioRaiz,'o',&Buffer[0]);
            // Envia El contenido de buffer
            if(Status!=FAT_READ_COMPLETE){
   do{
       Status=FAT_OpenFileAndRead(Nombre,DirectorioRaiz,'r',&Buffer[0]);
       // Envia El contenido de buffer
   }while(Status!=FAT_READ_COMPLETE);
}
    
     }
     ELSE { printf("  ARCHIVO NO LOCALIZADO\r\n");}
    
   }


alguien sabe cual es mi  error?? quiero leer el teXto de un archivo .txt Y mandarla a la lcd

Desconectado UcanEl

  • PIC10
  • *
  • Mensajes: 3
Re: ayuda leer SD en ccs
« Respuesta #2 en: 28 de Septiembre de 2014, 08:51:09 »
Yo no sé español.
Traduje mi mensaje a español con google translate.
Puede responder en español,
Puedo traducir y leer,
gracias.

En primer lugar muchas gracias a SUKY para esta gran biblioteca, este es un trabajo increíble.

Tengo el mismo problema,
Puedo crear y escribir en un archivo txt,
pero yo no sé cómo leer un archivo txt existente.

Es la versión 1.8 y 1.5 tienen las mismas reglas para este trabajo?
Imagen de la tarjeta sd de lectura y visualización de SUKY que encontré en GLCD
si es el mismo que puedo trabajar en este ejemplo
http://www.todopic.com.ar/foros/index.php?topic=31050.msg258990#msg258990

¿Alguien explica cómo utilizar SUKY sd versión de la biblioteca 1.8.
¿Qué funciones se utilizan para la lectura de un archivo existente, por ejemplo, un txt.

¿Cómo podemos ver las carpetas en el directorio raíz,
después de que la forma de llegar a las carpetas en otras carpetas
cómo abrir y leer archivos como txt,
donde los personajes es leida de la carpeta?


English Version
Firstly many thanks to SUKY for this great library, this is unbelievable work.

I have the same problem,
I can create and write to a txt file,
but i do not know how to read an existent txt file.

Is version 1.8 and 1.5 have the same rules for this job?
I found SUKY's read sd card and display image on glcd
if it is same I can work on this example
http://www.todopic.com.ar/foros/index.php?topic=31050.msg258990#msg258990

Did anyone explained how to use SUKY sd library version 1.8.
Which functions used for reading a existing file for example a .txt .

How we can see which folders in root directory,
after that how to reach folders in another folders,
how to open and read files like txt,
where is the readed characters of the folder?

Desconectado BEXTIXTOX

  • PIC16
  • ***
  • Mensajes: 108
Re: ayuda leer SD en ccs
« Respuesta #3 en: 28 de Septiembre de 2014, 12:29:51 »
Puedes probar con este codigo que resultados tienes tu??   

Can you try the next code:


Código:

#include <18F4550.h>
#device adc=8
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_a0,rcv=PIN_a1,bits=8)
 
 
#include <SDCard_hard.c>
 #include <FAT16_SDCard.c>

 char Texto [600]="texto creado dentro de un .txt con la libreria del señor suky.";
 //char SFN[13]="";
 //CHAR Buffer[800];
 int32 SectFound=0;
 int16 FAddDir=0;
 int16 FNClus=0;
 int32 FSizeFile=0;
 
 
/*******************************************************************************/
void main(){
char NombreArchivo[13]="DATOO.txt";
char NombreLargo[16]="NombreLargo.txt";
char NombreDirectorio[13]="CARD";
 
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   output_high(PIN_C0);
   output_high(PIN_C1);
   output_high(PIN_C2);
   
   delay_ms(1000);

   printf("Iniciando SD Card...\r\n");

   if(SDCard_init()==0){
      printf("Error\r\n");
   }else{
      printf("  MEMORIA INICIALIZADA OK\r\n ");
       printf("INICIANDO FAT... \r\n");
       IF (FAT_init())  { printf("FAT INICIALIZADO       OK\r\n\r\n");}
      ELSE {  printf("Error INICIALIZAR FAT\r\n");}
      printf("Creando Archivo... \r\n");
      if(FAT_CreateFile(NombreLargo,NombreArchivo,DirectorioRaiz,Texto )==0){
         printf("Error al crear archivo\r\n");
      } ELSE{ Printf("  ARCHIVO CREADO       OK \r\n");}
      printf("Creando FOLDER...\r\n");
      if(FAT_CreateDirectory(NombreDirectorio,NombreDirectorio,DirectorioRaiz)==0){
         printf("Error\r\n");
      }ELSE{ Printf("  FOLDER CREADO        OK\r\n");}
      printf("BUSCANDO Archivo... \r\n");
       if(FAT_FindFileDir(NombreLargo,0,ARCHIVO,SectFound,FAddDir,FNClus,FSizeFile)==0){ //Si no se encuentra..
      printf("  ARCHIVO LOCALIZADO   OK\r\n");
      printf("LEYENDO Archivo... \r\n");
          IF( FAT_OpenFile(NombreLargo,0)==1){
          printf("  ARCHIVO LEIDO        OK");
              } ELSE{ Printf("  ARCHIVO LEIDO        NO");}
    }ELSE{ Printf("  ARCHIVO NO LOCALIZADO\r\n");}
     
   }
   while(1){}
   
   }



Desconectado UcanEl

  • PIC10
  • *
  • Mensajes: 3
Re: ayuda leer SD en ccs
« Respuesta #4 en: 28 de Septiembre de 2014, 15:36:20 »
Yo no probé el código todavía.
Pero creo que
IF ( FAT_OpenFile ( NombreLargo , 0 ) == 1 )
esta parte tiene que ser así
IF ( FAT_OpenFile ( NombreLargo , 0 ) == 0 )

según la versión de la biblioteca de grasa 1.5
volver 0 es exitosa
de otra manera no exitosa

en la versión de la biblioteca 1.8 FAT16
hay una nueva función

# if defined ( FAT_USE_READ_FILE )
UINT8 FAT_OpenFileAndRead ( UINT8 * NameShort , UINT16 NClusP , UINT8 Tipo , UINT8 * Buffer ) {
....

Pero yo no lo probé todavía.

en mi idioma no es un modismo
" persianas y sordos entretiene unos a otros "
No escuche lo que estoy diciendo
porque, al igual que usted , yo tampoco lo sé .

//-----------------------------------------------------
English
I did not tried your code yet.
But i think
IF( FAT_OpenFile(NombreLargo,0)==1)
this part needs to be like this
IF( FAT_OpenFile(NombreLargo,0)==0)

according to the fat library version 1.5
return 0 is successfull
otherwise not successfull

in the version 1.8 FAT16 library
there is a new function

#if defined(FAT_USE_READ_FILE)
UINT8 FAT_OpenFileAndRead(UINT8 *NameShort,UINT16 NClusP, UINT8 Type, UINT8 *Buffer){
....

But i did not tried it yet.

in my language there is an idiom
"blinds and deafs entertains each other"
do not listen what i am saying
because, like you, i do not know either.



Desconectado allennet

  • PIC16
  • ***
  • Mensajes: 108
Re: ayuda leer SD en ccs
« Respuesta #5 en: 28 de Septiembre de 2014, 21:56:39 »
Este es el v1.9
"La curiosidad mato al gato, pero murio sabiendo"

Desconectado BEXTIXTOX

  • PIC16
  • ***
  • Mensajes: 108
Re: ayuda leer SD en ccs
« Respuesta #6 en: 28 de Septiembre de 2014, 22:23:52 »
IF( FAT_OpenFile(NombreLargo,0)==1)
 
IF( FAT_OpenFile(NombreLargo,0)==0)

estas son iguales la diferencia es la sentencia que ponemos a continuacion de ellas

 
sr.. allennet gran aporte tendras algun ejemplo?
a  mi me salen 100 errores cuando compilo


English:
IF (FAT_OpenFile (NombreLargo, 0) == 1)
 
IF (FAT_OpenFile (NombreLargo, 0) == 0)

 
these are the same the difference is the sentence we put them below

 
sr .. allennet great contribution will have some example?
I leave my 100 errors when I compile

Desconectado BEXTIXTOX

  • PIC16
  • ***
  • Mensajes: 108
Re: ayuda leer SD en ccs
« Respuesta #7 en: 29 de Septiembre de 2014, 02:11:10 »
actualize las librerias a 1.9v
y mi resultado fue esto
con el codigo 1 puedo crear un archivo, modificar un archivo y leer un archivo.
en el codigo 2 quiero solamente leer un archivo y me da un error  sabes donde esta mi error?? yo no lo encuentro


i upgrade the libraries to 1.9V
and my result was that
the first   code   i can create a file, edit a file and read a file.
the second  code I only want to read a file but I get an error you know where my mistake ?? I can not find it

code 1:
#include <18F4550.h>
 #device adc=8
  #use delay(clock=40000000)
 #fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG
 #use rs232(baud=9600,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8)




#include "FAT16.c"
#define(FAT_USE_READ_FILE)

UINT16 UbicacionFolder;
UINT8 Texto[512]="Texto Creado con PIC....\r\n";
char Carpetas[20]={"/Carpeta de PIC"};


void main(){

   int1 Card_Work=0;
   int8 i;
   char NombreCorto[13];
   char NombreLargo[50];
   UINT16 UbicacionFolder=0;
  
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
  
   InitHard_SDCard();
   delay_ms(1000);  
  

   while(1){
      if((SD_DETEC==0)&&(Card_Work==FALSE)){
         delay_ms(500);
         if(SD_DETEC==0){
         printf ("sd card   ok \r\n" );
            Card_work=1;
            SDCard_init();
            FAT_init();
              strcpy(&NombreCorto[0],"CARPET~1");
             strcpy(&NombreLargo[0],"Carpeta de PIC");
                UbicacionFolder=FAT_CreateDirectory(&NombreLargo[0],&NombreCorto[0],DirectorioRaiz);
             //   FAT_FindDirectory(Carpetas,DirectorioRaiz,UbicacionFolder);
          
            strcpy(&NombreCorto[0],"ARCHIVO1.txt");
            strcpy(&NombreLargo[0],"Archivo con PIC.txt");
             if( FAT_CreateFile(&NombreLargo[0],&NombreCorto[0],UbicacionFolder,&Texto[0]))printf ("Create file  ok   \r\n" );
            if (FAT_OpenAddFile(&NombreCorto[0],UbicacionFolder,&Texto[0]))printf ("file edited ok   \r\n" );
          
            if  (FAT_FindFile(NombreCorto,UbicacionFolder)){ printf ("find file   ok     \r\n" );
                 if (FAT_OpenFile(NombreCorto,UbicacionFolder)){printf ("open file    ok   \r\n" );  }
            
            }else {printf ("file no found  x    \r\n" );}
            
         }
      }
        
        
      if((SD_DETEC==1)&&(Card_Work==TRUE)){
         Card_work=0;
      }
   }
 
}
 

code 2:
#include <18F4550.h>
 #device adc=8
  #use delay(clock=40000000)
 #fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG
 #use rs232(baud=9600,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8)




#include "FAT16.c"
#define(FAT_USE_READ_FILE)

UINT16 UbicacionFolder;
UINT8 Texto[512]="Texto Creado con PIC....\r\n";
char Carpetas[20]={"/Carpeta de PIC"};


void main(){

   int1 Card_Work=0;
   int8 i;
   char NombreCorto[13];
   char NombreLargo[50];
   UINT16 UbicacionFolder=0;
  
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
  
   InitHard_SDCard();
   delay_ms(1000);  
  

   while(1){
      if((SD_DETEC==0)&&(Card_Work==FALSE)){
         delay_ms(500);
         if(SD_DETEC==0){
         printf ("sd card   ok \r\n" );
            Card_work=1;
            SDCard_init();
            FAT_init();
    //          strcpy(&NombreCorto[0],"CARPET~1");
     //        strcpy(&NombreLargo[0],"Carpeta de PIC");
         //       UbicacionFolder=FAT_CreateDirectory(&NombreLargo[0],&NombreCorto[0],DirectorioRaiz);
               FAT_FindDirectory(Carpetas,DirectorioRaiz,UbicacionFolder);
          
             strcpy(&NombreCorto[0],"ARCHIVO1.txt");
    //        strcpy(&NombreLargo[0],"Archivo con PIC.txt");
      //       if( FAT_CreateFile(&NombreLargo[0],&NombreCorto[0],UbicacionFolder,&Texto[0]))printf ("Create file  ok   \r\n" );
     //       if (FAT_OpenAddFile(&NombreCorto[0],UbicacionFolder,&Texto[0]))printf ("file edited ok   \r\n" );
          
            if  (FAT_FindFile(NombreCorto,UbicacionFolder)){ printf ("find file   ok     \r\n" );
                 if (FAT_OpenFile(NombreCorto,UbicacionFolder)){printf ("open file    ok   \r\n" );  }
            
            }else {printf ("file no found  x    \r\n" );}
            
         }
      }
        
        
      if((SD_DETEC==1)&&(Card_Work==TRUE)){
         Card_work=0;
      }
   }
 
}
 

Desconectado UcanEl

  • PIC10
  • *
  • Mensajes: 3
Re: ayuda leer SD en ccs
« Respuesta #8 en: 04 de Octubre de 2014, 07:30:21 »
I made some changes in the library,
but i think the problem is image that we use in the proteus,
i made .ima image file with WINIMAGE program,
and added a .txt file in this image,
but when i look at that image with winhex (HXD) pogram
i saw that .txt file atrribute (its entry's 0x0B byte is not 0x20
it must be 0x20, if it is not, our sd library does not recognize it as an archive,
so i changed the attribute of the txt in the image file with winhex,
then what happened, i can open the txt with proteus,
i added an image file and my working example you can try it.
name of the txt is 06.TXT,
i used the ( FAT_OpenFileAndRead(NombreCorto,DirectorioRaiz, 'o', BufferFAT) function,
NombreCorto is the short name of the file,
(if the name is smaller than 8 charecters library pads it with zero as needed)
DirectorioRaiz (RootDirectory) where do you want to start your search for this file,
'o' means open it,
when this function used named file is opening end reading it's first 512 byte data in to BufferFAT,
then we than show it!s content with using BufferFAT,
after that if we want to read remainings of the file we just need to use
( FAT_OpenFileAndRead(NombreCorto,DirectorioRaiz, 'r', BufferFAT)
same function with 'r' means read,
it reads next 512 byte of the file and places it into BufferFAT.
( I used PROTEUS 8.1 )

I hope my example helps.


//---------------------------
Translated;
Hice algunos cambios en la biblioteca ,
pero yo creo que el problema es la imagen que usamos en el proteus ,
hice .ima archivo de imagen con el programa Winimage ,
y ha añadido un archivo txt en esta imagen ,
pero cuando miro a esa imagen con winhex ( HXD ) Pogram
i vi que .txt atrribute (byte 0x0B de su entrada no es 0x20
debe ser 0x20 , si no es así, nuestra biblioteca sd no lo reconoce como un archivo ,
Así que cambié el atributo del txt en el archivo de imagen con winhex ,
luego de lo que pasó , puedo abrir el txt con proteus ,
he añadido un archivo de imagen y mi ejemplo de trabajo que puedo probarlo .
nombre del txt es 06.txt ,
He utilizado el ( FAT_OpenFileAndRead ( NombreCorto , DirectorioRaiz , ' o', función BufferFAT ) ,
NombreCorto es el nombre corto del archivo,
( si el nombre es más pequeño que 8 charecters almohadillas BIBLIOTECA con cero como sea necesario )
DirectorioRaiz ( RootDirectory ) donde quieres comenzar la búsqueda de este archivo ,
' o' significa abrirlo ,
cuando esta función que se utiliza el nombre de archivo se abre extremo lectura a sus primeros 512 bytes de datos en la que BufferFAT ,
entonces que muestran ! s contenido con el uso de BufferFAT ,
después de eso , si queremos leer restos del archivo sólo tenemos que utilizar
( FAT_OpenFileAndRead ( NombreCorto , DirectorioRaiz , ' r ' , BufferFAT )
misma función con ' r ' significa leer ,
se lee junto 512 byte del archivo y lo coloca en BufferFAT .
(Yo usé PROTEUS 8.1 )

Espero que mi ejemplo ayuda .
//--------------------------


LINK of complete example (ccsc code,library,hex, proteus schematic, and image file)
***********************************************************
https://www.dropbox.com/s/qafj0r34x745ncf/8_SD_Suky_ver18.rar?dl=0
***********************************************************

¿Puede alguien añadido en la página del foro
i no pude encontrar cómo agregó
Can someone added it into the this page of forum
i couldn not find how to added.


« Última modificación: 04 de Octubre de 2014, 07:32:45 por UcanEl »

Desconectado luchi94

  • PIC10
  • *
  • Mensajes: 17
Re:ayuda leer SD en ccs
« Respuesta #9 en: 02 de Julio de 2018, 11:39:34 »
Buenas tardes, estoy usando el Code 1 para intentar crear un archivo .txt en una micro SD.
La cuestión es que no me estaría creando el archivo, cuales son los pines para conectar al pic MISO,MOSI SCK,CS.
Si pudieran darme una mano, muchísimas gracias.


 

anything