Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
Main.c
Package: 51-SD.rar [view]
Upload User: jcsy2001
Upload Date: 2013-11-29
Package Size: 201k
Code Size: 3k
Category:
Embeded-SCM Develop
Development Platform:
C/C++
- #include "common.H"
- #include "DEVICE.H"
- #include "HAL.H"
- #include "HPI.H"
- #include "FAT.H"
- #include "FAT32.H"
- #include "HPI32.H"
- FLAGS bdata bFlags;
- extern unsigned char xdata DBUF[BUFFER_LENGTH];
- /////////////////////////////////////////////////
- extern unsigned long xdata DirStartCluster,DirStartCluster32;
- extern unsigned char xdata UARTBUF[UARTBUF_LENGTH];
- extern Command_Def xdata Command;
- extern SYS_INFO_BLOCK xdata DeviceInfo;
- extern FILE_INFO xdata ThisFile;
- //////////////////////////////////////////
- void Init_Port()
- {
- P0 = 0xFF;
- P1 = 0xFF;
- P2 = 0xFF;
- P3 = 0xFF;
- }
- /*Serial Port */
- /*Mode = 1 /8-bit UART
- Serial Port Interrupt = Disabled */
- /*Receive = Enabled */
- /*Auto Addressing = Disabled */
- void Init_COMM(void)
- {
- SCON = 0x53;
- PCON = 0x80 | PCON;
- T2CON=0x30;
- RCAP2H=0xFF; // 57600 @ 21.1184MHz: 24000000/(32*(65536-(RCAP2H,RCAP2L)))
- RCAP2L=0xF4;
- TI=0;
- RI=0;
- TR2=1;
- ES = 1;
- }
- void main(void)
- {
- unsigned char temp;
- unsigned long xdata time_count;
- Init_Port();
- Init_COMM();
- bFlags.bits.bUartInDone=0;
- DirStartCluster=0;
- DirStartCluster32=0;
- for(temp=0;temp<64;temp++)
- DBUF[temp]=0;
- ENABLE_INTERRUPTS;
- while(TRUE)
- {
- time_count++;
- if (time_count>1000) // 过一段时间查询一下SD/MMC卡是否在线 www.mcusky.com
- {
- DISABLE_INTERRUPTS;
- time_count = 0;
- ENABLE_INTERRUPTS;
- if(SdInit()) //初始化SD卡
- {
- if(bFlags.bits.SLAVE_ONLINE == FALSE)
- {bFlags.bits.SLAVE_FOUND=TRUE;
- bFlags.bits.SLAVE_ONLINE =TRUE;
- }
- }
- else
- {
- if(bFlags.bits.SLAVE_ONLINE ==TRUE)
- {bFlags.bits.SLAVE_REMOVED=TRUE;
- bFlags.bits.SLAVE_ONLINE =FALSE;
- }
- }
- }
- if(bFlags.bits.SLAVE_FOUND){
- DISABLE_INTERRUPTS;
- bFlags.bits.SLAVE_FOUND=FALSE;
- bFlags.bits.SLAVE_ENUMERATED = TRUE;
- DirStartCluster=0;
- DirStartCluster32=0;
- ThisFile.FatSectorPointer=0;
- DeviceInfo.LastFreeCluster=0;
- MCU_LED1=0;
- bFlags.bits.bMassDevice=TRUE;
- ENABLE_INTERRUPTS;
- }
- if(bFlags.bits.SLAVE_REMOVED)
- {
- DISABLE_INTERRUPTS;
- bFlags.bits.SLAVE_REMOVED=FALSE;
- bFlags.bits.SLAVE_ENUMERATED = FALSE;
- bFlags.bits.SLAVE_IS_ATTACHED = FALSE;
- MCU_LED1=1;MCU_LED2=1;
- ENABLE_INTERRUPTS;
- }
- if(bFlags.bits.bUartInDone){
- DISABLE_INTERRUPTS;
- bFlags.bits.bUartInDone=0;
- if(DeviceInfo.FAT) //FAT32
- UartHandler32();
- else
- UartHandler(); //FAT16
- ENABLE_INTERRUPTS;
- }
- if(bFlags.bits.bMassDevice)
- {
- DISABLE_INTERRUPTS;
- bFlags.bits.bMassDevice=FALSE;
- if(InitFileSystem())
- {
- bFlags.bits.SLAVE_IS_ATTACHED = TRUE;
- MCU_LED2=0;
- }
- else
- {
- bFlags.bits.SLAVE_IS_ATTACHED = FALSE;
- }
- ENABLE_INTERRUPTS;
- }
- }
- }