基于stc单片机的AT89S52离线烧录器程序
下面是部分源码预览,完整的代码请到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单片机IO模式特殊功能寄存器
struct znFAT_Init_Args idata Init_Args; //初始化参数集合
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单片机来调试SD卡模块,打开推挽,增强IO驱动能力
UART_Init();
UART_Send_Str("串口设置完毕");
znFAT_Device_Init(); //存储设备初始化
UART_Send_Str("SD卡初始化完毕");
znFAT_Select_Device(0,&Init_Args); //选择设备
res=znFAT_Init(); //文件系统初始化
if(!res) //文件系统初始化成功
{
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 //文件系统初始化失败
{
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) //如果有长名,则输出长名
{
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);
UART_Send_Str("File_CDate:");
UART_Put_Num(fileinfo.File_CDate.year); UART_Send_Str("年");
UART_Put_Num(fileinfo.File_CDate.month);UART_Send_Str("月");
UART_Put_Num(fileinfo.File_CDate.day); UART_Send_Str("日");
UART_Put_Num(fileinfo.File_CTime.hour); UART_Send_Str("时");
UART_Put_Num(fileinfo.File_CTime.min); UART_Send_Str("分");
UART_Put_Num(fileinfo.File_CTime.sec); UART_Send_Str("秒");
UART_Put_Inf("File_StartClust:",fileinfo.File_StartClust);
UART_Put_Inf("File_CurClust:",fileinfo.File_CurClust);
UART_Put_Inf("File_CurSec:",fileinfo.File_CurSec);
UART_Put_Inf("File_CurPos:",fileinfo.File_CurPos);
UART_Put_Inf("File_CurOffset:",fileinfo.File_CurOffset);
UART_Send_Str("================================");
Pro_Enable();
UART_Send_Str("Program enable....");
Pro_ReadSign(psignbuf);
UART_Send_Str("Sign[0]:");
binary(psignbuf[0]);UART_Send_Enter();
UART_Send_Str("Sign[1]:");
binary(psignbuf[1]);UART_Send_Enter();
UART_Send_Str("Sign[2]:");
binary(psignbuf[2]);UART_Send_Enter();
Pro_Erase();
UART_Send_Str("Program erase....");
UART_Send_Str("Startprogramming....");
addr=0;
while(len=znFAT_ReadData(&fileinfo,fileinfo.File_CurOffset,32,code_buf))
{
for(i=0;i
while(!Write(code_buf[i],addr));
addr++;
}
UART_Send_Byte(.);
}
UART_Send_Enter();
Pro_Over();
UART_Send_Str("Program over....");
UART_Send_Str("Start to Play this Code....");
RST=1;
delay(1000);
RST=0;
for(i=0;i<100;i++)
{
delay(60000);
}
RST=1;
UART_Send_Str("Complete playing this Code");
stc单片机AT89S52离线烧录 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)