基于stc單片機(jī)的AT89S52離線燒錄器程序
下面是部分源碼預(yù)覽,完整的代碼請(qǐng)到http://www.51hei.com/bbs/dpj-20605-1.html下載
#include "uart.h"
#include "s51pro.h"
#include "myfun.h"
#include "znfat/znFAT.h"
extern unsigned char OutBuf[4];
extern unsigned char InBuf[4];
unsigned char idata psignbuf[3];
unsigned char code_buf[32];
sfr P1M0 = 0x92;
sfr P1M1 = 0x91; //定義STC12單片機(jī)IO模式特殊功能寄存器
struct znFAT_Init_Args idata Init_Args; //初始化參數(shù)集合
struct FileInfo idata fileinfo; //文件信息集合
void main()
{
unsigned int idata addr=0,i=0;
unsigned int idata res=0,n_file=0,len=0;
P1M1=0x40;//P16高阻輸入
P1M0=0xa0; //如果使用51單片機(jī)來調(diào)試SD卡模塊,打開推挽,增強(qiáng)IO驅(qū)動(dòng)能力
UART_Init();
UART_Send_Str("串口設(shè)置完畢");
znFAT_Device_Init(); //存儲(chǔ)設(shè)備初始化
UART_Send_Str("SD卡初始化完畢");
znFAT_Select_Device(0,&Init_Args); //選擇設(shè)備
res=znFAT_Init(); //文件系統(tǒng)初始化
if(!res) //文件系統(tǒng)初始化成功
{
UART_Send_Str("Suc. to init FS");
UART_Put_Inf("BPB_Sector_No:",Init_Args.BPB_Sector_No);
UART_Put_Inf("Total_SizeKB:",Init_Args.Total_SizeKB);
UART_Put_Inf("BytesPerSector:",Init_Args.BytesPerSector);
UART_Put_Inf("FATsectors:",Init_Args.FATsectors);
UART_Put_Inf("SectorsPerClust:",Init_Args.SectorsPerClust);
UART_Put_Inf("FirstFATSector:",Init_Args.FirstFATSector);
UART_Put_Inf("FirstDirSector:",Init_Args.FirstDirSector);
UART_Put_Inf("FSsec:",Init_Args.FSINFO_Sec);
UART_Put_Inf("Next_Free_Cluster:",Init_Args.Next_Free_Cluster);
UART_Put_Inf("FreenCluster:",Init_Args.Free_nCluster);
}
else //文件系統(tǒng)初始化失敗
{
UART_Put_Inf("Fail to init FS , Err Code:",res);
}
//==================================================================
res=znFAT_Open_File(&fileinfo,"/*.bin",n_file,1); //打開文件
while(!res)
{
UART_Put_Inf("Suc. toopenfile ",n_file);
UART_Send_Str("================================");
UART_Send_Str("File_Name(Short 8.3):");
UART_Send_Str(fileinfo.File_Name);UART_Send_Enter();
if(fileinfo.have_lfn) //如果有長(zhǎng)名,則輸出長(zhǎng)名
{
UART_Send_Str("File_Name(Long Name):");
//中文輸出其UNICODE編碼碼值
i=0;
while(fileinfo.longname[i])
{
if(fileinfo.longname[i]<0x80)
UART_Send_Byte((unsigned char)fileinfo.longname[i++]);
else
{
UART_Put_Hex(fileinfo.longname[i++]);
UART_Send_Byte( );
}
}
UART_Send_Enter();
}
else
{
UART_Send_Str("This file have not Long Name.");;
}
UART_Put_Inf("File_Size:",fileinfo.File_Size);
評(píng)論