Thông báo

Collapse
No announcement yet.

SDcard va MMCard voi 8051

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • SDcard va MMCard voi 8051

    : các bạn ơi giúp tôi với liên quan về SDcard với 89S52, tôi cần kết nối dữ liệu gửi từ máy tính tới 89S52 rồi vi điều khiển này ghi dữ liệu đó vào thẻ nhớ 1G . cứu tôi mau với , mất nhiều thời gian mà chưa xong, có gì gửi vào mail saobui@gmail.com

  • #2
    Click image for larger version

Name:	8051MMC.jpg
Views:	2
Size:	81.9 KB
ID:	1353676
    các bạn xem file ảnh này nhé. tôi đã làm mạch in rồi nhưng phần mềm nhúng có vấn đề, các bạn xem hộ luôn

    Comment


    • #3
      file Fat32.h
      //-----------------------------------------------------------------------
      // File: fat32.h
      // Description: MCS51 C module for FAT32 layer on Memory Card, v 1.0408
      // Author: PHAM ANH SAO <saobui@gmail.com>
      // Compiler: Keil uVision
      // Date: March 30, 2008
      //-----------------------------------------------------------------------

      #ifndef _FAT32_H_
      #define _FAT32_H_

      #define FAT32_OPTIMIZE_CODE
      #ifdef _WRITE_SUPPORT
      #define FAT32_WRITE_SUPPORT
      #endif

      // Errors
      #define FAT32_ERROR_INIT -1
      #define FAT32_NO_ERROR 0
      #define FAT32_ERROR_IO 1
      #define FAT32_ERROR_FORMAT 2

      // File Type Difinition
      typedef char fat32File;
      // Max number of concurrent files
      #define HANDLE_MAX 10

      // File Attributes
      #define FAT32_FILE_ATTR_READ_ONLY 0x01 // Read Only
      #define FAT32_FILE_ATTR_HIDDEN 0x02 // Hidden
      #define FAT32_FILE_ATTR_SYSTEM 0x04 // System
      #define FAT32_FILE_ATTR_VOLUME_ID 0x08 // Volume ID
      #define FAT32_FILE_ATTR_DIRECTORY 0x10 // Directory
      #define FAT32_FILE_ATTR_ARCHIVE 0x20 // Archive
      #define FAT32_FILE_ATTR_LONG_NAME 0x0F // Long Name

      // Function Prototypes
      extern char fat32Init(void);
      #ifdef FAT32_WRITE_SUPPORT
      extern fat32File fat32FileOpen(const char *Path, char Mode);
      extern int fat32FileWrite(fat32File Handle, char *BufferOut, unsigned int NoBytes);
      extern char fat32FileUnlink(const char *Path);
      #else
      extern fat32File fat32FileOpen(const char *Path);
      #endif // FAT32_WRITE_SUPPORT
      extern char fat32FileClose(fat32File Handle);
      extern long fat32FileLSeek(fat32File Handle, unsigned long Offset, char FromWhere);
      extern unsigned long fat32FileSize(fat32File Handle);
      extern int fat32FileRead(fat32File Handle, char *BufferIn, unsigned int NoBytes);
      extern char fat32FileEnd(fat32File Handle);
      #ifndef FAT32_OPTIMIZE_CODE
      extern char fat32FileSetPos(fat32File Handle, unsigned long Pos);
      #else
      #define fat32FileSetPos(Handle, Pos) fat32FileLSeek(Handle, Pos, SEEK_SET)
      #endif // FAT32_OPTIMIZE_CODE

      // Definitions and Macros to use functions as ANSI C
      // Modes used in Accessing files
      #define O_RONLY 0x01
      #define O_WONLY 0x02
      #define O_RDWR 0x03
      #define O_APPEND 0x04
      #define O_CREATE 0x08
      #define O_EXCL 0x10
      #define O_TRUNC 0x20
      #define O_TEXT 0x40
      #define O_BINARY 0x80

      // Attributes
      #define FA_RONLY FAT32_FILE_ATTR_READ_ONLY
      #define FA_HIDDEN FAT32_FILE_ATTR_HIDDEN
      #define FA_SYSTEM FAT32_FILE_ATTR_SYSTEM
      #define FA_LABEL FAT32_FILE_ATTR_VOLUME_ID
      #define FA_DIREC FAT32_FILE_ATTR_DIRECTORY
      #define FA_ARCH FAT32_FILE_ATTR_ARCHIVE
      #define FA_LNAME FAT32_FILE_ATTR_LONG_NAME

      // SEEKs
      #define SEEK_SET 0
      #define SEEK_CUR 1
      #define SEEK_END 2

      // Macros
      #ifdef FAT32_WRITE_SUPPORT
      #define open(path, mode) fat32FileOpen(path, mode)
      #define write(handle, buff, len) fat32FileWrite(handle, buff, len)
      #define unlink(path) fat32FileUnlink(path)
      #define setattr(path, attr) fat32FileSetAttribute(path, attr) // Not ANSI C
      #else
      #define open(path, mode) fat32FileOpen(path)
      #endif // FAT32_WRITE_SUPPORT
      #define close(handle) fat32FileClose(handle)
      #define read(handle, buff, len) fat32FileRead(handle, buff, len)
      #define lseek(handle, offset, fromwhere) fat32FileLSeek(handle, offset, fromwhere)
      #define eof(handle) fat32FileEnd(handle) // Not ANSI C
      #define sizef(handle) fat32FileSize(handle) // Not ANSI C


      #endif // _FAT32_H_

      Comment


      • #4
        File mc.h
        //-----------------------------------------------------------------------
        // File: mc.h
        // Description: C module for Memory Card (MMC/SD) physical operations
        // Author: PHAM ANH SAO <saobui@gmail.com>
        // Compiler: Keil uVision
        // Date: March 15, 2008
        //-----------------------------------------------------------------------

        #ifndef _MC_H_
        #define _MC_H_

        #define MC_OPTIMIZE_CODE
        #ifdef _WRITE_SUPPORT
        #define MC_WRITE_SUPPORT
        #endif

        // Errors
        #define MC_TRUE 1
        #define MC_FALSE 0
        #define MC_NO_ERROR 0x00
        #define MC_ERROR_IO 0x02
        #define MC_ERROR_TIME_OUT 0x54

        // MC Types
        #define MC_TYPE_MMC 1
        #define MC_TYPE_SD 0

        // Constants
        #define MC_BLOCK_LEN 512

        // Global Function Prototypes for Memory Card Layer
        // If Code is Prefered some functions may be macros, or not available
        extern char mcInitCard(void);
        extern char mcSetBlockSize(unsigned int NoBytes);
        extern char mcReadBlockPart(unsigned long Address, char *BufferIn,
        unsigned int Start, unsigned int Size);
        #ifdef MC_WRITE_SUPPORT
        extern char mcWriteBlockPart(unsigned long Address, char *BufferIn,
        unsigned int Start, unsigned int Size);
        #ifndef MC_OPTIMIZE_CODE
        extern char mcWriteBlock(unsigned long Address, const char *BufferOut);
        #else // MC_OPTIMIZE_CODE
        #define mcWriteBlock(Blk, Bufo) mcWriteBlockPart(Blk, Bufo, 0, MC_BLOCK_LEN)
        #endif // MC_OPTIMIZE_CODE
        #endif // MC_WRITE_SUPPORT

        #ifndef MC_OPTIMIZE_CODE
        extern char xdata mcCSD[18]; // Card Specific Data Register (16 bytes+ CRC16)
        extern char xdata mcOCR[4]; // Operating Control Register
        extern char xdata mcCID[18]; // Card Identification Register (16 bytes+ CRC16)

        extern char mcReadCSD(void);
        extern char mcWriteCSD(void);
        extern char mcReadCID(void);
        extern char mcReadOCR(void);
        extern char mcReadBlock(unsigned long Address, char *BufferIn);
        #else // MC_OPTIMIZE_CODE
        #define mcReadBlock(Blk, Bufi) mcReadBlockPart(Blk, Bufi, 0, MC_BLOCK_LEN)
        #endif // MC_OPTIMIZE_CODE



        #endif // _MC_H_


        File rs232.h
        //-----------------------------------------------------------------------
        // File: rs232.h
        // Description: C module for RS-232 communication on MCS-51
        // Author: PHAM ANH SAO <saobui@gmail.com>
        // Compiler: Keil uVision
        // Date: March 23, 2008
        //-----------------------------------------------------------------------

        #ifndef _RS232_H_
        #define _RS232_H_

        #include <reg52.h>

        extern void rs232Init(char asVoid); // Data: 1-8-1, No Parity, 9600 @ 24M
        extern void rs232SendByte(char Sent);
        extern char rs232ReceiveByte(unsigned char TimeOut);
        extern void rs232SendString(const char *String);
        extern void rs232SendBytes(unsigned int NoBytes, const char *Bytes);
        extern void rs232ReceiveLine(char *LineBuf);

        #ifndef __STDIO_H__
        #define puts(s) rs232SendString(s)
        #define gets(s) rs232ReceiveLine(s)
        #define getch() rs232ReceiveByte(0xFF)
        #define putch(c) rs232SendByte(c)
        #endif // __STDIO_H__

        #endif // _RS232_H_


        File mcTest.c
        //#define _WRITE_SUPPORT
        #include "rs232.h"
        #include "fat32.h"
        #include <reg52.h>

        sbit LED_MCIN= P1^7; // Memory Card Insert LED
        sbit MCOUT= P3^2; // Memory Card Out
        #define MCIN !MCOUT

        void Timer0(void);

        char xdata mcInserted;

        void main()
        {
        char xdata mcBuffer[2050];
        char xdata Path[256];
        unsigned int len;
        fat32File file;

        // Init Serial Port
        rs232Init(0);
        rs232SendString(" MEMORY CARD TEST by PHAM ANH SAO\n");

        // Init Timer 0
        TMOD|= 0x02; // Timer0, 8 bit auto load
        TH0= 0x00; // auto load value
        IE|= 0x82;
        TR0= 1; // Start Timer0

        // Init FAT32 for Memory Card
        while(fat32Init()!= 0)
        {
        rs232SendString("> FAT32 Initialization Error!\n");
        }

        // Open a sample file and display its contents
        while(1)
        {
        rs232SendString("> Type the File Path to Open...\n> ");
        rs232ReceiveLine(Path);

        // Open a file for Read and Write (O_RDWR)
        // and set file pointer to end of file (O_APPEND)
        // If file does not exist, we create it (O_CREATE)
        if((file= open(Path, O_CREATE| O_RDWR| O_APPEND))!= -1)
        {
        rs232SendString("> File Opened!\n");

        // Write a sample string to file
        #ifdef _WRITE_SUPPORT
        if(write(file, "<saobui@gmail.com>", 21)== -1)
        rs232SendString("\n> Write Fail!\n");
        else
        rs232SendString("\n> Data Successfully Written to File!\n");
        #endif

        // Rewind the file
        lseek(file, 0, SEEK_SET);

        // Display contents
        while(!eof(file))
        {
        len= read(file, mcBuffer, 2048);
        rs232SendBytes(len, mcBuffer);
        }

        // Close file
        if(close(file)== 0)
        rs232SendString("\n> File Now Closed!\n");
        }

        else
        {
        rs232SendString("> File Could Not be Opened!\n");
        }

        }
        }

        void Timer0() interrupt 1 using 1
        {
        TR0= 0;
        if(MCIN)
        {
        LED_MCIN= 1;

        if(!mcInserted)
        {
        rs232SendString("\n> Card Inserted!\n");
        }
        mcInserted= 1;
        }

        else
        {
        LED_MCIN= 0;
        if(mcInserted)
        {
        rs232SendString("\n> Card Removed! \n");
        }

        mcInserted= 0;
        }

        TR0= 1;

        }


        tôi gửi cả 4 fi le đó, các bạn xem. tôi đã chuyển File mcTest.c sang File.Hex mà cứ báo lỗi là sao nhỉ, có phai do tôi thiếu thư viện File hỗ trợ không, ai có hi cho tôi , hoặc chỉ ra thất bại của tôi ở đâu nhé

        Comment


        • #5
          Giao tiếp thẻ nhớ MMC & SD Card - Quang bao, led, ty gia vang
          tôi đã xem qua link này nhưng không biết ghép chô nào với nhau nữa, giúp tôi với cả DIỄN ĐÀN ơi

          Comment


          • #6
            Lại một đồng chí lấy thư viện FAT32 của mình và sửa tên tác giả thành của họ. Rất may mà mình chưa post source thư viện lên...

            Comment


            • #7
              cho mình hỏi chút , nuế giao tiếp MMCar thì 89xx sẽ lấy dử liệu trong car ak hay la sao , mà làm thế tì nap chip như thế nào
              Cha mẹ khó nhọc nuôi ta lớn !!!
              Bạn bè Chơi Chó khiến ta khôn !!!

              Comment


              • #8
                Nguyên văn bởi bvhoang Xem bài viết
                Lại một đồng chí lấy thư viện FAT32 của mình và sửa tên tác giả thành của họ. Rất may mà mình chưa post source thư viện lên...
                tốt nhất là mỗi khi post code không do mình viết ra thì cứ ghi là sưu tầm/tham khảo

                Comment

                Về tác giả

                Collapse

                saobuibkhn Tìm hiểu thêm về saobuibkhn

                Bài viết mới nhất

                Collapse

                Đang tải...
                X