?? at45db161d_driver.c
字號:
SPI_CS=1;
}
/*描述: */
/* 與上一個函數(shù)的唯一區(qū)別是不帶預(yù)擦除。 */
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位無關(guān)位,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) //通過扇區(qū)對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) //寫命令或數(shù)據(jù)
{
while(busy==1);
// while(P4==0x08);
data_ora=dat;
req=1;
// while(P4==0x00);
while(busy==0);
req=0;
}
/*------------寫命令或數(shù)據(jù)到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,要顯示的數(shù)組中的字符位置k,8*8*/
void disp_bd (uchar *time,i,j,k)
{
wr_zb(0xf1,i+4,j*8); //i=0時為第0列
send(time[k]); //要顯示的數(shù)組中的字符的位置
}
/*在任意位置顯示字符,行j,列i,要顯示的數(shù)組中的字符位置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]); //要顯示的數(shù)組中的字符的位置,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]); //要顯示的數(shù)組中的字符的位置,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]); //要顯示的數(shù)組中的字符的位置
}
void init_T2(void)
{
EXIF=0x0c; //使用外部晶振
PMR=0x41; //機器周期為四個時鐘周期
CKCON=0x00; //定時器設(shè)置為12分頻
//---about timer0,timer1, init...
RCAP2H=0xff; //9600 用于保存高8位自動重載值
RCAP2L=0xdc; //9600 用于保存低8位自動重載值
TH2=RCAP2H; // T1 作為波特率時鐘發(fā)生器 9600bps
TL2=RCAP2L; //高八位
TR2=1; // 開定時器2
T2CON=0x34; //T2為波特率發(fā)生器
SCON=0xd8; // 串口方式3 8bit,允許接收
// PS=1; // 串口設(shè)置為高優(yōu)先級
// 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個數(shù)據(jù)顯示在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); //年十位*/
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -