پاسخ : فرستادن یه کد مثل 03H به یه ای سی یا ...
باز هم فرار کردید :mrgreen:
این جدول زمان بندی چه طوریه ؟
باز هم فرار کردید :mrgreen:
این جدول زمان بندی چه طوریه ؟
/* * definitions.h * * Created: 11/5/2011 9:49:18 PM * Author: Mostafa */ #ifndef DEFINITIONS_H_ #define DEFINITIONS_H_ #define MSD_CMD_GET_IC_VER 0x01 //Obtain chip and firmware version number #define MSD_CMD_SET_BAUDRATE 0x02 //Set serial communication baud rate #define MSD_CMD_ENTER_SLEEP 0x03 //Go to low-power and suspending #define MSD_CMD_RESET_ALL 0x05 //Execute hardware reset #define MSD_CMD_CHECK_EXIST 0x06 //Test communication interface and working status #define MSD_CMD_SET_SD0_INT 0x0B //Set interrupt Mode of SD0 in SPI #define MSD_CMD_GET_FILE_SIZE 0x0C //Get the current file length #define MSD_CMD_SET_USB_MODE 0x15 //Configure the work mode of USB #define MSD_CMD_GET_STATUS 0x22 //Get interruption status and cancel requirement #define MSD_CMD_RD_USB_DATA0 0x27 //Read data from current interrupt port buffer of USB or receive buffer of host port #define MSD_CMD_WR_USB_DATA 0x2C //Write data to transfer buffer of USB host #define MSD_CMD_WR_REQ_DATA 0x2D //Write requested data block to internal appointed buffer #define MSD_CMD_WR_OFS_DATA 0x2E //Write data block to internal buffer with appointed excursion address #define MSD_CMD_SET_FILE_NAME 0x2F //Set the file name which will be operated #define MSD_CMD_DISK_CONNECT 0x30 //Check the disk connection status #define MSD_CMD_DISK_MOUNT 0x31 //Initialize disk and test disk ready #define MSD_CMD_FILE_OPEN 0x32 //Open file or catalog, enumerate file and catalog #define MSD_CMD_FILE_ENUM_GO 0x33 //Go on to enumerate file and catalog #define MSD_CMD_FILE_CREATE 0x34 //Create file #define MSD_CMD_FILE_ERASE 0x35 //Delete file #define MSD_CMD_FILE_CLOSE 0x36 //Close the open file or catalog #define MSD_CMD_DIR_INF0_READ 0x37 //Read the catalog information of file #define MSD_CMD_DIR_INF0_SAVE 0x38 //Save catalog information of file #define MSD_CMD_BYTE_LOCATE 0x39 //Move the file pointer take byte as unit #define MSD_CMD_BYTE_READ 0x3A //Read data block from current location take byte as unit #define MSD_CMD_BYTE_RD_GO 0x3B //Continue byte read #define MSD_CMD_BYTE_WRITE 0x3C //Write data block from current location take unit as unit #define MSD_CMD_BYTE_WR_GO 0x3D //Continue byte write #define MSD_CMD_DISK_CAPACITY 0x3E //Check disk physical capacity #define MSD_CMD_DISK_QUERY 0x3F //Check disk space #define MSD_CMD_DIR_CREATE 0x40 //Create catalog and open or open the existed catalog #define MSD_CMD_SEG_LOCATE 0x4A //Move file pointer from current location take fan as unit #define MSD_CMD_SEC_READ 0x4B //Read data block from current location take fan as unit #define MSD_CMD_SEC_WRITE 0x4C //Write data block from current location take fan as unit #define MSD_CMD_DISK_BOC_CMD 0x50 //Execute B0 transfer protocol command to USB Storage #define MSD_CMD_DISK_READ 0x54 //Read physical fan from USB storage device #define MSD_CMD_DISK_RD_GO 0x55 //Go on reading operation of USB storage device #define MSD_CMD_DISK_WRITE 0x56 //Write physical fan to USB storage device #define MSD_CMD_DISK_WR_GO 0x57 //Go on writing operation of USB storage device // --------------------------------------------------------------------------------------------------- #define MSD_RET_SUCCESS 0x51 //Operation successful #define MSD_RET_ABORT 0x5F //Operation failure #define MSD_USB_INT_SUCCESS 0x14 //Success of SD card or USB transaction or transfer operation #define MSD_USB_INT_CONNECT 0x15 //Detection of USB device attachment #define MSD_USB_INT_DISCONNECT 0x16 //Detection of USB device detachment #define MSD_USB_INT_BUF_OVER 0x17 //Data error or Buffer overflow #define MSD_USB_INT_USB_READY 0x18 //USB device has initialized (appointed USB address) #define MSD_USB_INT_DISK_READ 0x1D //Read operation of storage device #define MSD_USB_INT_DISK_WRITE 0x1E //Write operation of storage device #define MSD_USB_INT_DISK_ERR 0x1F //Failure of USB storage device #define MSD_ERR_OPEN_DIR 0x41 //Open directory address is appointed #define MSD_ERR_MISS_FILE 0x42 //File doesn’t be found which address is appointed, maybe the name is error #define MSD_ERR_FOUND_NAME 0x43 //Search suited file name, or open directory according the request, open file in actual #define MSD_ERR_DISK_DISCON 0x82 //Disk doesn’t connect, maybe the disk has cut down #define MSD_ERR_LARGE_SECTOR 0x84 //Fan is too big, only support 512 bytes #define MSD_ERR_TYPE_ERROR 0x92 //Disk partition doesn’t support, re-prartition by tool #define MSD_ERR_BPB_ERROR 0xA1 //Disk doesn’t format, or parameter is errot, re-formate by WINDOWS with default parameter #define MSD_ERR_DISK_FULL 0xB1 //File in disk is full, spare space is too small #define MSD_ERR_FDT_OVER 0xB2 //Many file in directory, no spare directory, clean up the disk, less than 512 in FAT12/FAT16 root directory #define MSD_ERR_FILE_CLOSE 0xB4 //File is closed, re-open file if need #endif /* DEFINITIONS_H_ */
/* * MSDlib.h * * Created: 11/5/2011 10:19:59 PM * Author: Mostafa */ #ifndef MSDLIB_H_ #define MSDLIB_H_ #include "definitions.h" void msd_init(); void msd_command(char cmd); char msd_isconnect(); char msd_mount(); void msd_dismount(); char msd_updateDiskCapacity(); volatile char msd_timeout; struct diskSpaces { unsigned long msd_diskSize; // in 512 sectors unsigned long msd_diskFree; // in 512 sectors }diskSpaces; #endif /* MSDLIB_H_ */
/* * MSDlib.c * * Created: 11/14/2011 1:05:36 PM * Author: Mostafa */ #include "MSDlib.h" #include "MSDmacro.h" #include "msd_uart.h" void msd_init() { MSD_UART_INIT(); } void msd_flushBuffer() { while(MSD_UART_RECIVED()) MSD_UARTGET(); } void msd_command(char cmd) { msd_flushBuffer(); MSD_UARTPUT(0x57); MSD_UARTPUT(0xAB); MSD_UARTPUT(cmd); } //1000ms resolation char msd_waitonebyte(char t) { unsigned int i; msd_timeout = 0; t = 26 - t; for(i = 0; i < 50000; i+=t) { if(MSD_UART_RECIVED()) return MSD_UARTGET(); MSD_Delay_us(50); } msd_timeout = 1; return 0xff; } char msd_getversion() { char t; msd_command(MSD_CMD_GET_IC_VER); t = msd_waitonebyte(3); if( t == 0xff ) return MSD_RET_ABORT; return t; } char mds_setmode(char mode) { char ret; msd_command(MSD_CMD_SET_USB_MODE); MSD_UARTPUT(mode); ret = msd_waitonebyte(5); msd_waitonebyte(1); return ret; } char msd_isconnect() { msd_command(MSD_CMD_DISK_CONNECT); return msd_waitonebyte(3); } char msd_mount() { char ret , trys; for(trys = 0; trys < 3 ; trys++) { // check version ret = msd_getversion(); if(ret == MSD_RET_ABORT) continue; // set mode of operation ret = mds_setmode(6); if(ret != MSD_RET_SUCCESS) continue; // mount mass storage msd_command(MSD_CMD_DISK_MOUNT); ret = msd_waitonebyte(20); if(ret == MSD_USB_INT_SUCCESS) return MSD_USB_INT_SUCCESS; } return ret; } char msd_updateDiskCapacity() { char ret , trys; unsigned char i; char *temp = &diskSpaces; for(trys = 0; trys < 3 ; trys++) { // mount mass storage msd_command(MSD_CMD_DISK_QUERY); ret = msd_waitonebyte(20); if(ret != MSD_USB_INT_SUCCESS) continue; //09 E8 3F 77 00 68 61 55 00 03 14 msd_command(MSD_CMD_RD_USB_DATA0); ret = msd_waitonebyte(3); if(ret != 0x09) continue; for(i = 0; i < 8; i++) { *temp = msd_waitonebyte(1); temp++; if(msd_timeout) continue; } diskSpaces.msd_diskSize /= 2; // convert to kilobyte diskSpaces.msd_diskFree /= 2; // convert to kilobyte return MSD_USB_INT_SUCCESS; } return MSD_RET_ABORT; }
/* * CH375_Test1.c * * Created: 11/5/2011 9:41:27 PM * Author: Mostafa */ #include <avr/io.h> #include "MSD Lib/MSDlib.h" #include "lcd_lib.h" #include <stdio.h> #include <avr/interrupt.h> int main(void) { LCDinit(); LCDGotoXY(0,0); sei(); msd_init(); if( msd_mount() == MSD_USB_INT_SUCCESS) { msd_updateDiskCapacity(); printf_P((char*)PSTR("T:%ld") ,diskSpaces.msd_diskSize); LCDGotoXY(0,1); printf_P((char*)PSTR("T:%ld") ,diskSpaces.msd_diskFree); } while(1) { //TODO:: Please write your application code } }
دیدگاه