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

📄 at45db161d_driver.c

📁 52系列单片机对AT45DB161D的操作程序
💻 C
📖 第 1 页 / 共 2 页
字号:
  SPI_CS=1; 

} 

/*描述:                                               */ 
/*   与上一个函数的唯一区别是不带预擦除。                         */ 

void AT45DB161B_BufferToMainMemoryPageProgramWithoutBuilt_inErase(uchar buffer,uint PA,uint BFA,uchar *pHeader,uint len)
{ 
  uint i; 

  AT45DB161B_BufferWrite(buffer,BFA,pHeader,len); 

   while(!(AT45DB161B_StatusRegisterRead()&0x80));
  // while(i++<1000){if(AT45DB161B_StatusRegisterRead()&0x80){break;}} 
  
  SPI_CS=0; 
  SPI_HostWriteByte(0x87+buffer); 
  SPI_HostWriteByte((uchar)(PA>>6));               //15位无关位,9位页地址位
  SPI_HostWriteByte((uchar)(PA<<2)); 
  SPI_HostWriteByte(0x00); 
  
   for(i=0;i<len;i++){SPI_HostWriteByte(pHeader[i]);} //改
  SPI_CS=1; 

} 









/*对整片进行擦除*/

void AT45DB161B_ChipErase()       //我写
{ 
  
  while(!(AT45DB161B_StatusRegisterRead()&0x80));   
  
  SPI_CS=0;   

   SPI_HostWriteByte(0xc7); 
   SPI_HostWriteByte(0x94);
  
  SPI_HostWriteByte(0x80); 
  
  SPI_HostWriteByte(0x90); 
    
  
  SPI_CS=1; 

} 



void Erasing_Sector(uchar PA)      //通过扇区对FLASH进行擦除
{

while(!(AT45DB161B_StatusRegisterRead()&0x80)); 

  SPI_CS=0;   

   SPI_HostWriteByte(0x7c);
              
  SPI_HostWriteByte((uchar)(PA<<2)); 

SPI_HostWriteByte(0x00); 
SPI_HostWriteByte(0x00); 
 SPI_CS=1; 

}




void ErasingDataFlash(uint PA) //081 total 512 block 16sector per block通过页对FLASH进行擦除
{

while(!(AT45DB161B_StatusRegisterRead()&0x80)); 

  

SPI_CS=0;
SPI_HostWriteByte(0x50); //0x50 erase 512 pages
SPI_HostWriteByte((char)(PA>>4)); //r r r PA11 PA10 PA9 PA8 PA7 
SPI_HostWriteByte((char)(PA<<4)); //PA6 PA5 PA4 PA3 X X X 0
SPI_HostWriteByte(0x00); 
SPI_CS=1;


}





/**************************以下LCM****************************/

void send (uchar dat)               //写命令或数据                      
{
 while(busy==1);
  // while(P4==0x08);
  data_ora=dat;
   req=1;
  
  // while(P4==0x00);
  while(busy==0);
  req=0;
}


/*------------写命令或数据到LCD--------------*/
void wr_zb (uchar comm,uchar addr_x,uchar addr_y)
{
  send(comm);
  send(addr_x);     //列 
  send(addr_y);       //行 
}




/****************以下液晶显示子程序***************/
/****************LCM初始化(使能)****************/

void lcd_int(void)
{
  req=0;
 //P4=0x08;
 busy=1;
}


/*在任意位置显示字符,行j,列i,要显示的数组中的字符位置k,8*8*/
void disp_bd (uchar *time,i,j,k)
{
    
  
       wr_zb(0xf1,i+4,j*8);          //i=0时为第0列
     send(time[k]);                 //要显示的数组中的字符的位置
   
 }

/*在任意位置显示字符,行j,列i,要显示的数组中的字符位置k,8*16ASCLL*/
void disp_flow (uchar *time,i,j,k)
{
    
  
       wr_zb(0xf9,i+4,j*16);          //i=0时为第0列,J为0时为第0行	  
     send(time[k]);                 //要显示的数组中的字符的位置,k=0时为第0个	   
   
}

 /*在任意位置显示字符,行j,列i,8*16ASCLL*/
void disp_flow1 (uchar *time,i,j)
{
    
  
       wr_zb(0xf9,i+4,j*16);          //i=0时为第0列,J为0时为第0行	  
     send(time[0]);                 //要显示的数组中的字符的位置,k=0时为第0个	   
   
}
   
/*在任意位置显示字符,行j,列i,8*8*/
void disp_time (uchar *time,i,j)
{
    
  
       wr_zb(0xf1,i+4,j*8);          //i=0时为第0列
     send(time[0]);                 //要显示的数组中的字符的位置
   
}







void init_T2(void)
  {   
      EXIF=0x0c;         //使用外部晶振
	  PMR=0x41;           //机器周期为四个时钟周期
      CKCON=0x00;          //定时器设置为12分频 
//---about timer0,timer1, init...
      RCAP2H=0xff;         //9600  用于保存高8位自动重载值
	  RCAP2L=0xdc;          //9600  用于保存低8位自动重载值
       TH2=RCAP2H;            // T1 作为波特率时钟发生器   9600bps
       TL2=RCAP2L;              //高八位
       TR2=1;                 // 开定时器2  
      T2CON=0x34;           //T2为波特率发生器
       SCON=0xd8;             // 串口方式3 8bit,允许接收
     //  PS=1;                  // 串口设置为高优先级
      // ES=1;                  // 串口中断使能      
      // EA=1;                  // 总中断使能!!
    
	   }

 void delay1(uchar g)						 //延时毫秒 
 {
 uchar i,j;
 for(i=0;i<g;i++ )
 for( j=0;j<150;j++) ;

 }

void main(void)
{ 

uint PPA;
 uchar i; 
 uchar test[6];
uchar test1[6];
 
//    SPI_RESET = 0;
//    SPI_WP = 0;
//   delay(2000);


//    SPI_WP = 1;//取消写保护

delay1(60);

//i=AT45DB161B_StatusRegisterRead(); 
init_T2();
// memset(test,0x56,32); 
for(i = 0; i < 6; i++)
//{test[i] = i + 0x28;}        //改动
{test[i] = i + 0x22;}     

//AT45DB161B_BufferToMainMemoryPageProgramWithBuilt_inErase(1,3080,25,test,6); 

 
// lcd_int();
while(1)
{


AT45DB161B_ChipErase();


for(PPA=0;PPA<512;PPA++)
{

ErasingDataFlash(PPA);

}




// AT45DB161B_ContinuousArrayRead(4000,53,test1,6);

AT45DB161B_ContinuousArrayRead(33,0,test1,6);


/*for(i=0;i<32;i++)
{
SBUF=test[i];

 while(TI==0);              
 TI=0;
 }*/





lcd_int();

       buff1[0] = test1[0] % 0x10 + '0';
       disp_time(buff1,10,7);    //将buff1中第1个数据显示在3行10列 //秒个位
    
       temp =test1[0] & 0x7f;
       temp = temp/16;
       buff1[0] = temp%10 + '0';
       disp_time(buff1,9,7);       //秒十位
   
      // if(buffer[1]!=copymt){//每分刷新一次
       //  copymt = test[1];
         buff1[0] = test1[1] % 0x10 + '0';
        disp_time(buff1,7,7);         //分个位
                                  //空出6
     

         temp =test1[1] & 0x7f;
         temp = temp/16;
         buff1[0] = temp%10 + '0';
         disp_time(buff1,6,7);//分十位
        

         buff1[0] = test1[2] % 0x10 + '0';
        disp_time(buff1,4,7); //时个位
	

         temp =test1[2] & 0x7f;
         temp = temp/16;
         buff1[0] = temp%10 + '0';
          disp_time(buff1,3,7); //时十位
       
       
        // vWrite8x16String(XingQi[buffer[5]] ,3, 40,0);//显示星期
       
         buff1[0] = test1[3] % 0x10 + '0';
         disp_time(buff1,10,6);//日个位

         
         temp =test1[3] & 0x7f;
         temp = temp/16;
         buff1[0] = temp%10 + '0';
         disp_time(buff1,9,6);//日十位
        

         buff1[0] = test1[4] % 0x10 + '0';
         disp_time(buff1,7,6);//月个位

        
         temp =test1[4] & 0x7f;
         temp = temp/16;
         buff1[0] = temp%10 + '0';
         disp_time(buff1,6,6);//月十位
        

         buff1[0] = test1[5] % 0x10 + '0';
        disp_time(buff1,4,6);//年个位
        

         temp =test1[5] & 0x7f;
         temp = temp/16;
         buff1[0] = temp%10 + '0';
          disp_time(buff1,3,6); //年十位*/
  
 
}
}

⌨️ 快捷键说明

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