⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flash.lst

📁 源码 : KIEL C 单片机 : C8051F320 功能 : U盘 (64M) 关键字 : C8051F320,U盘,NANDFLASH,FAT,SCH 描述 : 源码完全可运行
💻 LST
字号:
C51 COMPILER V6.12  FLASH                                                                  08/20/2006 19:41:24 PAGE 1   


C51 COMPILER V6.12, COMPILATION OF MODULE FLASH
OBJECT MODULE PLACED IN Flash.OBJ
COMPILER INVOKED BY: C:\keil\C51\BIN\c51.exe Flash.c DB OE

stmt level    source

*** WARNING C500 IN LINE 1 OF FLASH.C: MISSING DEVICE (SECURITY KEY NOT FOUND)
   1          //头文件
   2          /////////////////////////////
   3          #include "c8051F320.h"
   4          #include "stdio.h"
   5          ////////////////////////////////////////////////////////////////////////////////////////////////////
   6          //位定义
   7          sbit FLASH_WP	=P2^0;	//命令锁存
   8          sbit FLASH_WE	=P2^1;	//地址锁存
   9          sbit FLASH_ALE	=P2^2;	//写保护
  10          sbit FLASH_CLE  =P2^3;	//片选
  11          sbit FLASH_CE   =P2^4;	//写使能
  12          sbit FLASH_RE   =P2^5;	//读使能
  13          sbit FLASH_RB   =P2^6;	//忙指示
  14          sbit FLASH_SE   =P2^7;
  15          
  16          //P1口为数据口
  17          //注释掉的函数在需要时可以取掉注释即可
  18          ///////////////////////////////////////////////////////////////////////////////////////////////////
  19          //FLASH函数声明
  20          void 			Flash_Init(void);								//FLASH初始化
  21          //unsigned int 	Get_Flash_ID(void);								//读FLASH的ID号
  22          //unsigned char 	Get_Flash_Status(void);						//读FLASH的状态
  23          unsigned char 	Flash_Erase_Block(unsigned int BlockNum);		//擦除FLASH中的第BlockNum个BLOCK,擦除成功则返回1
  24          void 			Flash_Read_Page(unsigned int BLockNum,unsigned char BlockPageNum,unsigned char *P,unsigned int Dat
             -a_Length);
  25          				//读出第BlockNum个BLOCK中第BlockPageNum个PAGE中的内容,长度为Data_Length
  26          unsigned char 	Flash_Write_Page(unsigned int BLockNum,unsigned char BlockPageNum,unsigned char *P,unsigned
             - int Data_Length);
  27          				//意义同上
  28          void 			Flash_Write_Command(unsigned char command);		//写命令
  29          void 			Flash_Write_Address(unsigned char address);		//写地址
  30          void 			Flash_Write_Data(unsigned char num);			//写一字节数据
  31          unsigned char 	Flash_Read_Data(void);							//读一字节数据
  32          
  33          //void Test_Flash(void);			//FLASH测试函数,首先读取FLASH的ID号,然后写入512字节数据,再读出来,判断是否正
             -确
  34          
  35          extern	void	Time_Delay(unsigned int time);
  36          ////////////////////////////////////////////////////////////////////////////////////////////////////
  37          
  38          
  39          void Flash_Init()
  40          {
  41   1      	unsigned int i=0;
  42   1      	P1=0xff;
  43   1      	P2MDOUT=0xff;
  44   1      	FLASH_SE=0;FLASH_WP=1;FLASH_CE=0;FLASH_ALE=0;
  45   1      	FLASH_CLE=0;FLASH_WE=1;FLASH_RE=1;FLASH_RB=1;	//控制位的初始状态
  46   1      	Flash_Write_Command(0xff);						//复位命令
  47   1      	Time_Delay(50);									//延时50ms
  48   1      }
  49          /*
  50          unsigned int Get_Flash_ID(void)
  51          {
C51 COMPILER V6.12  FLASH                                                                  08/20/2006 19:41:24 PAGE 2   

  52          	unsigned int id=0;
  53          	Flash_Write_Command(0x90);		//读ID命令
  54          	Flash_Write_Address(0x00);		//地址
  55          	id=Flash_Read_Data();		    //读ID的高8位
  56          	id *=256;
  57          	id+=Flash_Read_Data();			//读ID的低8位
  58          	return(id);
  59          }
  60          */
  61          /*
  62          unsigned char Get_Flash_Status()
  63          {
  64          	unsigned char status=0;
  65          	Flash_Write_Command(0x70);
  66          	status=Flash_Read_Data();
  67          	return(status);
  68          }*/
  69          
  70          unsigned char Flash_Erase_Block(unsigned int BlockNum)
  71          {
  72   1      	unsigned char Address_M=0,Address_H=0,Address_HH=0;
  73   1      	unsigned long  PageNum=0;
  74   1      	unsigned char status=0;
  75   1      	PageNum=BlockNum*32;				//计算PAGE地址(这是该BLOCK中的第一个PAGE),每个BLOCK含32个PAGE
  76   1      	Address_M=PageNum & 0xff;
  77   1      	Address_H=(PageNum>>8) & 0xff;		//擦除BLOCK时,只需要输入地址的高两字节,此处为计算地址的高两字节
  78   1      	Address_HH=(PageNum>>8) & 0xff;
  79   1      		
  80   1      	Flash_Write_Command(0x60);			//发送擦除命令
  81   1      	Flash_Write_Address(Address_M);
  82   1      	Flash_Write_Address(Address_H);		//发送地址
  83   1      	Flash_Write_Address(Address_HH);
  84   1      	Flash_Write_Command(0xd0);			//启动擦除
  85   1      	P2MDOUT =0xbf;
  86   1      	FLASH_RB=1;							//FLASH_RB漏极开路输出
  87   1      	while(!FLASH_RB)					//判断是否擦除完毕
  88   1      	{}
  89   1      
  90   1      	Flash_Write_Command(0x70);			//发送读状态命令
  91   1      	status=Flash_Read_Data();			//读状态
  92   1      	if(status & 0x01)					//如果有错误,则返回false
  93   1      	{
  94   2      		return(0);
  95   2      	}
  96   1      	else								//否则返回true
  97   1      	{
  98   2      		return(1);
  99   2      	}
 100   1      }
 101          
 102          void Flash_Read_Page(unsigned int BLockNum,unsigned char BlockPageNum,unsigned char *P,unsigned int Data_L
             -ength)
 103          {
 104   1      	unsigned int  i=0;
 105   1      	unsigned long  PageNum=0;
 106   1      	unsigned char Address_L=0,Address_M=0,Address_H=0,Address_HH=0;
 107   1      	PageNum=BLockNum*32+BlockPageNum;		//计算该PAGE在整个FLASH中的PAGE地址
 108   1      	Address_L=0;
 109   1      	Address_M=PageNum & 0xff;
 110   1      	Address_H=(PageNum>>8) & 0xff;
 111   1      	Address_HH=(PageNum>>8) & 0xff;
 112   1      
C51 COMPILER V6.12  FLASH                                                                  08/20/2006 19:41:24 PAGE 3   

 113   1      	Flash_Write_Command(0x00);				//将内部指针指向A区
 114   1      	Flash_Write_Address(Address_L);		    //写地址
 115   1      	Flash_Write_Address(Address_M);
 116   1      	Flash_Write_Address(Address_H);
 117   1      	Flash_Write_Address(Address_HH);
 118   1      	for(i=0;i<Data_Length;i++)
 119   1      	{
 120   2      		*(P+i)=Flash_Read_Data();			//读数据
 121   2      	}
 122   1      
 123   1      }
 124          
 125          unsigned char Flash_Write_Page(unsigned int BLockNum,unsigned char BlockPageNum,unsigned char *P,unsigned 
             -int Data_Length)
 126          {
 127   1      	unsigned int  i=0;
 128   1      	unsigned long  PageNum=0;
 129   1      	unsigned char Address_L=0,Address_M=0,Address_H=0,Address_HH=0;
 130   1      	unsigned char status=0;
 131   1      	PageNum=BLockNum*32+BlockPageNum;		//计算该PAGE在整个FLASH中的PAGE地址
 132   1      	Address_L=0;
 133   1      	Address_M=PageNum & 0xff;
 134   1      	Address_H=(PageNum>>8) & 0xff;
 135   1      	Address_HH=(PageNum>>8) & 0xff;
 136   1      	
 137   1      	Flash_Write_Command(0x00);			//将内部指针指向A区
 138   1      	Flash_Write_Command(0x80);			//写FLASH命令
 139   1      	Flash_Write_Address(Address_L);		//写地址
 140   1      	Flash_Write_Address(Address_M);
 141   1      	Flash_Write_Address(Address_H);
 142   1      	Flash_Write_Address(Address_HH);
 143   1      	for(i=0;i<Data_Length;i++)
 144   1      	{
 145   2      		Flash_Write_Data(*(P+i));		//将数据写入缓冲区
 146   2      	}
 147   1      	Flash_Write_Command(0x10);		  	//启动写入,将数据从缓冲区写入到FLASH
 148   1      	P2MDOUT =0xbf;						//FLASH_RB漏极开路输出
 149   1      	FLASH_RB=1;
 150   1      	while(!FLASH_RB)					//判断是否操作完毕
 151   1      	{}
 152   1      
 153   1      	Flash_Write_Command(0x70);			//发送读状态命令
 154   1      	status=Flash_Read_Data();			//读状态
 155   1      	if(status & 0x01)					//如果有错误,则返回false
 156   1      	{
 157   2      		return(0);
 158   2      	}
 159   1      	else								//否则返回true
 160   1      	{
 161   2      		return(1);
 162   2      	}
 163   1      
 164   1      }
 165          
 166          void Flash_Write_Command(unsigned char command)
 167          {
 168   1      	FLASH_ALE=0;	//地址锁存禁止
 169   1      	FLASH_CLE=1;	//命令锁存使能
 170   1      	FLASH_WE =0;	//写使能信号,上升沿有效
 171   1      	P1MDOUT  =0xff;	//设置P1为推挽输出
 172   1      	P1=command;
 173   1      	FLASH_WE =1;	//命令在上升沿写入
C51 COMPILER V6.12  FLASH                                                                  08/20/2006 19:41:24 PAGE 4   

 174   1      	FLASH_CLE=0;	//命令锁存禁止
 175   1      	FLASH_ALE=1;
 176   1      }
 177          
 178          void Flash_Write_Address(unsigned char address)
 179          {
 180   1      	FLASH_WE=1;
 181   1      	FLASH_CLE=0;	//命令锁存禁止
 182   1      	FLASH_ALE=1;	//地址锁存使能
 183   1      	FLASH_WE =0;	//写使能信号,上升沿有效
 184   1      	P1MDOUT  =0xff;	//设置P1为推挽输出
 185   1      	P1=address;
 186   1      	FLASH_WE =1;	//上升沿写入
 187   1      	FLASH_ALE=0;	//地址锁存禁止
 188   1      }
 189          
 190          void Flash_Write_Data(unsigned char num)
 191          {
 192   1      	FLASH_WE=1;
 193   1      	FLASH_CLE=0;	//命令锁存禁止
 194   1      	FLASH_ALE=0;	//地址锁存禁止
 195   1      	FLASH_WE =0;	//写使能信号, 上升沿有效
 196   1      	P1MDOUT  =0xff;	//设置P1为推挽输出
 197   1      	P1=num;
 198   1      	FLASH_WE =1;	//命令在上升沿写入
 199   1      }
 200          
 201          unsigned char Flash_Read_Data(void)
 202          {
 203   1      	unsigned char num=0;
 204   1      	FLASH_CLE	=0;		//命令锁存禁止
 205   1      	FLASH_ALE	=0;		//地址锁存禁止
 206   1      	P1MDOUT    =0x00;	//设置P1为漏极开路输出
 207   1      	P1		 	=0xff;
 208   1      	FLASH_RE 	=0;		//读信号使能
 209   1      	P2MDOUT =0xbf;		//FLASH_RB漏极开路输出
 210   1      	FLASH_RB=1;
 211   1      	while(!FLASH_RB)	//判断是否操作完毕
 212   1      	{}
 213   1      	num=P1;
 214   1      	FLASH_RE=1;
 215   1      	return(num);
 216   1      }
 217          /*
 218          void Test_Flash()
 219          {
 220          	unsigned int Flash_ID;
 221          	xdata unsigned char Buffer[512];
 222          	unsigned int i=0,dat=0;
 223          	Flash_ID=Get_Flash_ID();
 224          	printf("Flash_ID is %u\n",Flash_ID);
 225          
 226          	for(i=0;i<512;i++)
 227          	{Buffer[i]=i;}
 228          	for(i=0;i<256;i++)
 229          	{Buffer[256+i]=i;}
 230          	Flash_Write_Page(1,1,Buffer,512);
 231          	for(i=0;i<512;i++)
 232          	{Buffer[i]=0;}
 233          	Flash_Read_Page(1,1,Buffer,512);
 234          	for(i=0;i<512;i++)
 235          	{
C51 COMPILER V6.12  FLASH                                                                  08/20/2006 19:41:24 PAGE 5   

 236          		dat=Buffer[i];
 237          		printf("the No.%u data is %u\n",i,dat);
 238          	}
 239          
 240          }*/


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    576    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      47
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  1 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -